From 4e62f2d3d7e9cd1cbaf73a8234d301e02811b573 Mon Sep 17 00:00:00 2001 From: Toshiya Kobayashi Date: Wed, 17 Jan 2024 18:00:43 +0900 Subject: [PATCH] [RHPAM-4876] exclusion on kie server affect custom endpoints - Add resteasy-jackson2-provider in kie-server.war --- ...KieServerApplicationComponentsService.java | 1 + .../extension/custom/CustomJsonResource.java | 44 +++++++++++++++ .../CustomExtensionIntegrationTest.java | 54 +++++++++++++++++-- .../kie-server-wars/kie-server/pom.xml | 12 +++++ .../main/assembly/assembly-ee8-container.xml | 6 ++- .../WEB-INF/jboss-deployment-structure.xml | 1 - 6 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 kie-server-parent/kie-server-tests/kie-server-integ-tests-custom-extension/kie-server-integ-tests-custom-extension-rest/src/main/java/org/kie/server/extension/custom/CustomJsonResource.java diff --git a/kie-server-parent/kie-server-tests/kie-server-integ-tests-custom-extension/kie-server-integ-tests-custom-extension-rest/src/main/java/org/kie/server/extension/custom/CustomDroolsKieServerApplicationComponentsService.java b/kie-server-parent/kie-server-tests/kie-server-integ-tests-custom-extension/kie-server-integ-tests-custom-extension-rest/src/main/java/org/kie/server/extension/custom/CustomDroolsKieServerApplicationComponentsService.java index 0228264684..60e77aa0cb 100644 --- a/kie-server-parent/kie-server-tests/kie-server-integ-tests-custom-extension/kie-server-integ-tests-custom-extension-rest/src/main/java/org/kie/server/extension/custom/CustomDroolsKieServerApplicationComponentsService.java +++ b/kie-server-parent/kie-server-tests/kie-server-integ-tests-custom-extension/kie-server-integ-tests-custom-extension-rest/src/main/java/org/kie/server/extension/custom/CustomDroolsKieServerApplicationComponentsService.java @@ -52,6 +52,7 @@ public Collection getAppComponents(String extension, SupportedTransports List components = new ArrayList(); if (SupportedTransports.REST.equals(type)) { components.add(new CustomResource(rulesExecutionService, context)); + components.add(new CustomJsonResource()); } return components; diff --git a/kie-server-parent/kie-server-tests/kie-server-integ-tests-custom-extension/kie-server-integ-tests-custom-extension-rest/src/main/java/org/kie/server/extension/custom/CustomJsonResource.java b/kie-server-parent/kie-server-tests/kie-server-integ-tests-custom-extension/kie-server-integ-tests-custom-extension-rest/src/main/java/org/kie/server/extension/custom/CustomJsonResource.java new file mode 100644 index 0000000000..3dabc22a9f --- /dev/null +++ b/kie-server-parent/kie-server-tests/kie-server-integ-tests-custom-extension/kie-server-integ-tests-custom-extension-rest/src/main/java/org/kie/server/extension/custom/CustomJsonResource.java @@ -0,0 +1,44 @@ +/* + * 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. + * + * 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.extension.custom; + +import java.util.Map; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +/** + * This class is just to verify that Json conversion works (resteasy-jackson2-provider). There is nothing to do with drools nor jbpm. + */ +@Path("server/containers/custom-json") +public class CustomJsonResource { + + @POST + @Path("/{myId}") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + public Response insertFireReturn(@Context HttpHeaders headers, @PathParam("myId") String myId, Map inputMap) { + inputMap.put("key3", "value3"); + return Response.ok(inputMap).build(); + } +} diff --git a/kie-server-parent/kie-server-tests/kie-server-integ-tests-custom-extension/kie-server-integ-tests-custom-extension-test/src/test/java/org/kie/server/integrationtests/extension/custom/CustomExtensionIntegrationTest.java b/kie-server-parent/kie-server-tests/kie-server-integ-tests-custom-extension/kie-server-integ-tests-custom-extension-test/src/test/java/org/kie/server/integrationtests/extension/custom/CustomExtensionIntegrationTest.java index fb682c4939..612322767d 100644 --- a/kie-server-parent/kie-server-tests/kie-server-integ-tests-custom-extension/kie-server-integ-tests-custom-extension-test/src/test/java/org/kie/server/integrationtests/extension/custom/CustomExtensionIntegrationTest.java +++ b/kie-server-parent/kie-server-tests/kie-server-integ-tests-custom-extension/kie-server-integ-tests-custom-extension-test/src/test/java/org/kie/server/integrationtests/extension/custom/CustomExtensionIntegrationTest.java @@ -17,24 +17,36 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; -import org.assertj.core.api.Assertions; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; +import org.jboss.resteasy.plugins.providers.jackson.ResteasyJacksonProvider; import org.junit.After; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.kie.api.KieServices; import org.kie.api.runtime.ExecutionResults; +import org.kie.server.api.marshalling.MarshallingFormat; import org.kie.server.api.model.ReleaseId; import org.kie.server.client.CustomExtensionClient; import org.kie.server.client.KieServicesClient; +import org.kie.server.common.rest.Authenticator; import org.kie.server.integrationtests.shared.KieServerDeployer; import org.kie.server.integrationtests.shared.KieServerReflections; import org.kie.server.integrationtests.shared.basetests.KieServerBaseIntegrationTest; import org.kie.server.integrationtests.shared.basetests.RestJmsSharedBaseIntegrationTest; +import static org.assertj.core.api.Assertions.assertThat; + public class CustomExtensionIntegrationTest extends RestJmsSharedBaseIntegrationTest { private static ReleaseId releaseId = new ReleaseId("org.kie.server.testing", "stateless-session-kjar", "1.0.0"); @@ -94,12 +106,48 @@ public void testStatelessCall() throws Exception { ExecutionResults result = customClient.insertFireReturn(CONTAINER_ID, KIE_SESSION, persons); Object john2 = result.getValue(JOHN_OUT_IDENTIFIER); - Assertions.assertThat(KieServerReflections.valueOf(john2, PERSON_SURNAME_FIELD)).isEqualTo(JOHN_EXPECTED_SURNAME); + assertThat(KieServerReflections.valueOf(john2, PERSON_SURNAME_FIELD)).isEqualTo(JOHN_EXPECTED_SURNAME); Object mary2 = result.getValue(MARY_OUT_IDENTIFIER); - Assertions.assertThat(KieServerReflections.valueOf(mary2, PERSON_SURNAME_FIELD)).isEqualTo(MARY_SURNAME); + assertThat(KieServerReflections.valueOf(mary2, PERSON_SURNAME_FIELD)).isEqualTo(MARY_SURNAME); } private Object createPersonInstance(String firstname, String surname, ClassLoader loader) { return KieServerReflections.createInstance(PERSON_CLASS_NAME, loader, firstname, surname); } + + @Test + public void testCustomJsonResourceEndpoint() { + // RHPAM-4876 + if (configuration.getMarshallingFormat() != MarshallingFormat.JSON) { + return; + } + + Client httpClient = new ResteasyClientBuilder() + .establishConnectionTimeout(configuration.getTimeout(), TimeUnit.MILLISECONDS) + .socketTimeout(configuration.getTimeout(), TimeUnit.MILLISECONDS) + .register(new Authenticator(configuration.getUserName(), configuration.getPassword())) + .register(new ResteasyJacksonProvider()) + .build(); + + Map testPayload = new HashMap<>(); + testPayload.put("key1", "value1"); + testPayload.put("key2", 123); + + String endpoint = configuration.getServerUrl() + "/containers/custom-json/1"; + + Response response = httpClient.target(endpoint) + .request() + .post(Entity.entity(testPayload, MediaType.APPLICATION_JSON)); + + assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode()); + Object entity = response.readEntity(Map.class); + assertThat(entity).isNotNull() + .isInstanceOf(Map.class); + Map responseMap = (Map) entity; + assertThat(responseMap).containsEntry("key1", "value1") + .containsEntry("key2", 123) + .containsEntry("key3", "value3"); + + httpClient.close(); + } } diff --git a/kie-server-parent/kie-server-wars/kie-server/pom.xml b/kie-server-parent/kie-server-wars/kie-server/pom.xml index b96b3ea337..02fa377e1f 100644 --- a/kie-server-parent/kie-server-wars/kie-server/pom.xml +++ b/kie-server-parent/kie-server-wars/kie-server/pom.xml @@ -52,6 +52,11 @@ jakarta.el jakarta.el-api + + + org.jboss.resteasy + resteasy-jackson-provider + @@ -356,6 +361,13 @@ org.kie.server kie-server-services-kafka + + + + org.jboss.resteasy + resteasy-jackson2-provider + + diff --git a/kie-server-parent/kie-server-wars/kie-server/src/main/assembly/assembly-ee8-container.xml b/kie-server-parent/kie-server-wars/kie-server/src/main/assembly/assembly-ee8-container.xml index 45701c4e0e..c35df9addf 100644 --- a/kie-server-parent/kie-server-wars/kie-server/src/main/assembly/assembly-ee8-container.xml +++ b/kie-server-parent/kie-server-wars/kie-server/src/main/assembly/assembly-ee8-container.xml @@ -91,9 +91,13 @@ org.glassfish.jaxb:jaxb-runtime org.glassfish.jaxb:jaxb-xjc + + org.jboss.resteasy:resteasy-jackson2-provider - org.jboss.resteasy:* + org.jboss.resteasy:resteasy-jaxrs + org.jboss.resteasy:resteasy-jackson-provider + org.jboss.resteasy:resteasy-jaxb-provider jakarta.annotation:* jakarta.ejb:* jakarta.interceptor:* diff --git a/kie-server-parent/kie-server-wars/kie-server/src/main/ee-resources/WEB-INF/jboss-deployment-structure.xml b/kie-server-parent/kie-server-wars/kie-server/src/main/ee-resources/WEB-INF/jboss-deployment-structure.xml index e209106126..a5f50e11bd 100644 --- a/kie-server-parent/kie-server-wars/kie-server/src/main/ee-resources/WEB-INF/jboss-deployment-structure.xml +++ b/kie-server-parent/kie-server-wars/kie-server/src/main/ee-resources/WEB-INF/jboss-deployment-structure.xml @@ -28,7 +28,6 @@ -