Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.67.x] [incubator-kie-issues-1105] Polymorphic json typing causes long delays in first request #3056

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 8 additions & 8 deletions kie-server-parent/kie-server-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- core dependencies -->
<!-- core dependencies -->
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
Expand All @@ -56,7 +56,7 @@
<artifactId>kie-soup-xstream</artifactId>
</dependency>

<!-- we need to find a way to remove the following 2 dependencies from this jar -->
<!-- we need to find a way to remove the following 2 dependencies from this jar -->
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
Expand All @@ -74,13 +74,13 @@
<artifactId>optaplanner-persistence-jaxb</artifactId>
</dependency>

<!-- Needed only for the DMNResult, DMNContext, etc and FEELEvent so should be possible later to migrate to kie-dmn-API -->
<!-- Needed only for the DMNResult, DMNContext, etc and FEELEvent so should be possible later to migrate to kie-dmn-API -->
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-dmn-api</artifactId>
</dependency>

<!-- json -->
<!-- json -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
Expand All @@ -102,13 +102,13 @@
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>

<!-- xstream -->
<!-- xstream -->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
</dependency>

<!-- utils -->
<!-- utils -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down Expand Up @@ -142,7 +142,7 @@
<artifactId>jaxb-impl</artifactId>
<scope>test</scope>
</dependency>
<!-- TRUSTY -->
<!-- TRUSTY -->
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-pmml-dependencies</artifactId>
Expand All @@ -153,7 +153,7 @@
</exclusion>
</exclusions>
</dependency>
<!-- LEGACY -->
<!-- LEGACY -->
<dependency>
<groupId>org.drools</groupId>
<artifactId>kie-pmml</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,12 @@ public List<NamedType> findSubtypes(Annotated a) {
complete.addAll(base);
}
if (customClasses != null) {
complete.addAll(customClasses);
for (NamedType namedType : customClasses) {
Class<?> clazz = namedType.getType();
if (!a.getRawType().equals(clazz) && a.getRawType().isAssignableFrom(clazz)) {
complete.add(namedType);
}
}
}
return complete;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2024 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.kie.server.api.marshalling.json;

import java.io.IOException;
import java.io.InputStream;
import java.util.Set;
import java.util.stream.Collectors;

import org.drools.core.util.IoUtils;
import org.junit.Test;
import org.kie.server.api.marshalling.test.model.Fact;
import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.assertj.core.api.Assertions.assertThat;

public class JSONMarshallerLargeTest {

private Logger logger = LoggerFactory.getLogger(JSONMarshallerLargeTest.class);

@Test(timeout = 5000L)
public void testLargeNumberOfClasses() throws IOException {
try (InputStream is = JSONMarshallerLargeTest.class.getClassLoader().getResourceAsStream("complex_payload.json")) {
String content = new String(IoUtils.readBytesFromInputStream(is));

Reflections reflections = new Reflections("org.kie.server.api.marshalling.test.model", new SubTypesScanner(false));
Set<Class<?>> clazzes = reflections.getSubTypesOf(Object.class).stream().collect(Collectors.toSet());
clazzes.remove(Fact.class);

JSONMarshaller marshaller = new JSONMarshaller(clazzes, JSONMarshallerLargeTest.class.getClassLoader());
Fact object = marshaller.unmarshall(content, Fact.class);
assertThat(object).isNotNull();
logger.info("object captured {}", object);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2024 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kie.server.api.marshalling.test.model;

public class Fact implements java.io.Serializable {

private Object object;

public Object getObject() {
return object;
}

public void setObject(Object object) {
this.object = object;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2024 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kie.server.api.marshalling.test.model.dummy.package1;

import java.io.Serializable;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

@SuppressWarnings("java:S1068")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DummyData1")
public class DummyData1 implements Serializable {

private static final long serialVersionUID = 5174127032991892033L;

@XmlAttribute(name = "dummyString")
private String dummyString;
private int dummyInt;
@XmlElement(required = true)
private Object dummyObj;

public DummyData1() {
}

public DummyData1(int dummyInt, Object dummyObj) {
this.dummyInt = dummyInt;
this.dummyObj = dummyObj;
}

public DummyData1(int dummyInt, String dummyString, Object dummyObj) {
this.dummyInt = dummyInt;
this.dummyString = dummyString;
this.dummyObj = dummyObj;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2024 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kie.server.api.marshalling.test.model.dummy.package1;

import java.io.Serializable;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

@SuppressWarnings("java:S1068")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DummyData10")
public class DummyData10 implements Serializable {

private static final long serialVersionUID = 5174127032991892033L;

@XmlAttribute(name = "dummyString")
private String dummyString;
private int dummyInt;
@XmlElement(required = true)
private Object dummyObj;

public DummyData10() {
}

public DummyData10(int dummyInt, Object dummyObj) {
this.dummyInt = dummyInt;
this.dummyObj = dummyObj;
}

public DummyData10(int dummyInt, String dummyString, Object dummyObj) {
this.dummyInt = dummyInt;
this.dummyString = dummyString;
this.dummyObj = dummyObj;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2024 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kie.server.api.marshalling.test.model.dummy.package1;

import java.io.Serializable;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

@SuppressWarnings("java:S1068")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DummyData100")
public class DummyData100 implements Serializable {

private static final long serialVersionUID = 5174127032991892033L;

@XmlAttribute(name = "dummyString")
private String dummyString;
private int dummyInt;
@XmlElement(required = true)
private Object dummyObj;

public DummyData100() {
}

public DummyData100(int dummyInt, Object dummyObj) {
this.dummyInt = dummyInt;
this.dummyObj = dummyObj;
}

public DummyData100(int dummyInt, String dummyString, Object dummyObj) {
this.dummyInt = dummyInt;
this.dummyString = dummyString;
this.dummyObj = dummyObj;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2024 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kie.server.api.marshalling.test.model.dummy.package1;

import java.io.Serializable;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

@SuppressWarnings("java:S1068")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DummyData11")
public class DummyData11 implements Serializable {

private static final long serialVersionUID = 5174127032991892033L;

@XmlAttribute(name = "dummyString")
private String dummyString;
private int dummyInt;
@XmlElement(required = true)
private Object dummyObj;

public DummyData11() {
}

public DummyData11(int dummyInt, Object dummyObj) {
this.dummyInt = dummyInt;
this.dummyObj = dummyObj;
}

public DummyData11(int dummyInt, String dummyString, Object dummyObj) {
this.dummyInt = dummyInt;
this.dummyString = dummyString;
this.dummyObj = dummyObj;
}
}
Loading