Skip to content

Commit

Permalink
[RHPAM-4876] exclusion on kie server affect custom endpoints
Browse files Browse the repository at this point in the history
- Add resteasy-jackson2-provider in kie-server.war
  • Loading branch information
tkobayas committed Jan 18, 2024
1 parent 1f901ca commit 4e62f2d
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public Collection<Object> getAppComponents(String extension, SupportedTransports
List<Object> components = new ArrayList<Object>();
if (SupportedTransports.REST.equals(type)) {
components.add(new CustomResource(rulesExecutionService, context));
components.add(new CustomJsonResource());
}

return components;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Object> inputMap) {
inputMap.put("key3", "value3");
return Response.ok(inputMap).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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<String, Object> 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<String, Object> responseMap = (Map<String, Object>) entity;
assertThat(responseMap).containsEntry("key1", "value1")
.containsEntry("key2", 123)
.containsEntry("key3", "value3");

httpClient.close();
}
}
12 changes: 12 additions & 0 deletions kie-server-parent/kie-server-wars/kie-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId>
</exclusion>
<!-- avoid ban-duplicated-classes with resteasy-jackson2-provider -->
<exclusion>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
Expand Down Expand Up @@ -356,6 +361,13 @@
<groupId>org.kie.server</groupId>
<artifactId>kie-server-services-kafka</artifactId>
</dependency>

<!-- RHPAM-4876 -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,13 @@

<include>org.glassfish.jaxb:jaxb-runtime</include>
<include>org.glassfish.jaxb:jaxb-xjc</include>

<include>org.jboss.resteasy:resteasy-jackson2-provider</include>
</includes>
<excludes>
<exclude>org.jboss.resteasy:*</exclude>
<exclude>org.jboss.resteasy:resteasy-jaxrs</exclude>
<exclude>org.jboss.resteasy:resteasy-jackson-provider</exclude>
<exclude>org.jboss.resteasy:resteasy-jaxb-provider</exclude>
<exclude>jakarta.annotation:*</exclude>
<exclude>jakarta.ejb:*</exclude>
<exclude>jakarta.interceptor:*</exclude>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
<module name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider" />
<module name="com.fasterxml.jackson.dataformat.jackson-dataformat-yaml" />
<module name="org.jboss.resteasy.resteasy-jackson2-provider" />
<module name="org.jboss.resteasy.resteasy-jackson-provider" />
</exclusions>
<dependencies>
<!-- IMPORTANT: when adding dependency (module) here, make sure it is a public one.
Expand Down

0 comments on commit 4e62f2d

Please sign in to comment.