use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.
the class ContainerJmsResponseHandlerIntegrationTest method setupClients.
@Before
public void setupClients() throws Exception {
asyncClient = createDefaultClient();
Marshaller marshaller = MarshallerFactory.getMarshaller(new HashSet<Class<?>>(extraClasses.values()), configuration.getMarshallingFormat(), asyncClient.getClassLoader());
responseCallback = new BlockingResponseCallback(marshaller);
asyncClient.setResponseHandler(new AsyncResponseHandler(responseCallback));
fireAndForgetClient = createDefaultClient();
fireAndForgetClient.setResponseHandler(new FireAndForgetResponseHandler());
}
use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.
the class CustomResource method insertFireReturn.
@POST
@Path("/{ksessionId}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response insertFireReturn(@Context HttpHeaders headers, @PathParam("id") String id, @PathParam("ksessionId") String ksessionId, String cmdPayload) {
Variant v = RestUtils.getVariant(headers);
String contentType = RestUtils.getContentType(headers);
MarshallingFormat format = MarshallingFormat.fromType(contentType);
try {
KieContainerInstance kci = registry.getContainer(id, ContainerLocatorProvider.get().getLocator());
Marshaller marshaller = kci.getMarshaller(format);
List<?> listOfFacts = marshaller.unmarshall(cmdPayload, List.class);
List<Command<?>> commands = new ArrayList<Command<?>>();
BatchExecutionCommand executionCommand = commandsFactory.newBatchExecution(commands, ksessionId);
for (Object fact : listOfFacts) {
commands.add(commandsFactory.newInsert(fact, fact.toString()));
}
commands.add(commandsFactory.newFireAllRules());
commands.add(commandsFactory.newGetObjects());
ExecutionResults results = rulesExecutionService.call(kci, executionCommand);
String result = marshaller.marshall(results);
logger.debug("Returning OK response with content '{}'", result);
return RestUtils.createResponse(result, v, Response.Status.OK);
} catch (Exception e) {
// in case marshalling failed return the call container response to keep backward compatibility
String response = "Execution failed with error : " + e.getMessage();
logger.debug("Returning Failure response with content '{}'", response);
return RestUtils.createResponse(response, v, Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.
the class JSONMarshallerExtensionTest method testObjectInsideCommand.
@Test
public void testObjectInsideCommand() {
Set<Class<?>> extraClasses = new HashSet<Class<?>>();
extraClasses.add(CustomPerson.class);
Marshaller marshaller = MarshallerFactory.getMarshaller(extraClasses, MarshallingFormat.JSON, this.getClass().getClassLoader());
CustomPerson john = new CustomPerson("John", 20);
InsertObjectCommand command = new InsertObjectCommand(john);
String marshall = marshaller.marshall(command);
// verify if it's processed by JSONMarshallerExtensionCustomPerson serializer
Assertions.assertThat(marshall).contains("John is CustomPerson");
InsertObjectCommand unmarshall = marshaller.unmarshall(marshall, InsertObjectCommand.class);
CustomPerson result = (CustomPerson) unmarshall.getObject();
// verify if it's processed by JSONMarshallerExtensionCustomPerson deserializer
assertEquals(50, result.getAge());
}
use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.
the class JSONMarshallerTypeFactoryTest method testTypeFactoryCacheSize.
@Test
public void testTypeFactoryCacheSize() {
Set<Class<?>> extraClasses = new HashSet<>();
extraClasses.add(CustomPerson.class);
Marshaller marshaller1 = MarshallerFactory.getMarshaller(extraClasses, MarshallingFormat.JSON, this.getClass().getClassLoader());
CustomPerson john = new CustomPerson("John", 20);
InsertObjectCommand command1 = new InsertObjectCommand(john);
marshaller1.marshall(command1);
Marshaller marshaller2 = MarshallerFactory.getMarshaller(extraClasses, MarshallingFormat.JSON, this.getClass().getClassLoader());
CustomPerson paul = new CustomPerson("Paul", 17);
InsertObjectCommand command2 = new InsertObjectCommand(paul);
marshaller2.marshall(command2);
TypeFactory typeFactory1 = ((JSONMarshaller) marshaller1).getTypeFactory();
TypeFactory typeFactory2 = ((JSONMarshaller) marshaller2).getTypeFactory();
try {
Field field = TypeFactory.class.getDeclaredField("_typeCache");
field.setAccessible(true);
LookupCache<Object, JavaType> _typeCache1 = (LookupCache<Object, JavaType>) field.get(typeFactory1);
LookupCache<Object, JavaType> _typeCache2 = (LookupCache<Object, JavaType>) field.get(typeFactory2);
assertThat(_typeCache1.size()).isPositive();
assertThat(_typeCache2.size()).isPositive();
marshaller1.dispose();
assertThat(_typeCache1.size()).isZero();
// marshaller2 is not affected
assertThat(_typeCache2.size()).isPositive();
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
fail("failed with reflection", e);
}
}
use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.
the class FormServiceRestOnlyIntegrationTest method testGetTaskFormTest.
@Test
public void testGetTaskFormTest() throws Exception {
Map<String, Object> valuesMap = new HashMap<String, Object>();
valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
valuesMap.put(RestURI.PROCESS_ID, HIRING_PROCESS_ID);
Marshaller marshaller = MarshallerFactory.getMarshaller(marshallingFormat, ClassLoader.getSystemClassLoader());
Map<String, Object> params = new HashMap<String, Object>();
params.put("name", "john");
// start process instance
WebTarget clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + START_PROCESS_POST_URI, valuesMap));
logger.info("[POST] " + clientRequest.getUri());
response = clientRequest.request(getMediaType()).post(createEntity(marshaller.marshall(params)));
Assert.assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
Long result = response.readEntity(JaxbLong.class).unwrap();
assertNotNull(result);
// find tasks by process instance id
valuesMap.put(RestURI.PROCESS_INST_ID, result);
clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), QUERY_URI + "/" + TASK_BY_PROCESS_INST_ID_GET_URI, valuesMap));
logger.info("[GET] " + clientRequest.getUri());
response = clientRequest.request(getMediaType()).get();
Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
TaskSummaryList taskSummaryList = marshaller.unmarshall(response.readEntity(String.class), TaskSummaryList.class);
logger.debug("Form content is '{}'", taskSummaryList);
assertNotNull(taskSummaryList);
TaskSummary[] task = taskSummaryList.getTasks();
assertEquals(1, task.length);
Long taskId = task[0].getId();
valuesMap.put(RestURI.TASK_INSTANCE_ID, taskId);
changeUser(USER_JOHN, DEFAULT_PASSWORD);
clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), FORM_URI + "/" + TASK_FORM_GET_URI, valuesMap));
logger.info("[GET] " + clientRequest.getUri());
response = clientRequest.request(getMediaType()).get();
Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
String formdata = response.readEntity(String.class);
logger.debug("Form content is '{}'", formdata);
assertNotNull(formdata);
assertFalse(formdata.isEmpty());
clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + ABORT_PROCESS_INST_DEL_URI, valuesMap));
logger.info("[DELETE] " + clientRequest.getUri());
response = clientRequest.request().delete();
int noContentStatusCode = Response.Status.NO_CONTENT.getStatusCode();
int okStatusCode = Response.Status.OK.getStatusCode();
assertTrue("Wrong status code returned: " + response.getStatus(), response.getStatus() == noContentStatusCode || response.getStatus() == okStatusCode);
}
Aggregations