use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.
the class MarshallingRoundTripCustomClassListTest method testJSON.
@Test
public void testJSON() {
Marshaller marshaller = MarshallerFactory.getMarshaller(getCustomClasses(), MarshallingFormat.JSON, getClass().getClassLoader());
verifyMarshallingRoundTrip(marshaller, createTestObject());
}
use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.
the class MarshallingRoundTripNestedClassesTest method testXStream.
@Test
public void testXStream() {
Marshaller marshaller = MarshallerFactory.getMarshaller(getCustomClasses(), MarshallingFormat.XSTREAM, getClass().getClassLoader());
verifyMarshallingRoundTrip(marshaller, createTestObject());
}
use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.
the class MarshallingRoundTripNestedClassesTest method testJSON.
@Test
public void testJSON() {
Marshaller marshaller = MarshallerFactory.getMarshaller(getCustomClasses(), MarshallingFormat.JSON, getClass().getClassLoader());
verifyMarshallingRoundTrip(marshaller, createTestObject());
}
use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.
the class KieContainerInstanceImplTest method testUpdatingOfReleaseId.
@Test
public void testUpdatingOfReleaseId() {
createEmptyKjar(GROUP_ID, ARTIFACT_ID, VERSION_100);
createEmptyKjar(GROUP_ID, ARTIFACT_ID, VERSION_101);
KieServices ks = KieServices.Factory.get();
InternalKieContainer kieContainer = (InternalKieContainer) ks.newKieContainer(CONTAINER_ID, RELEASE_ID_100);
KieContainerInstanceImpl containerInstance = new KieContainerInstanceImpl(CONTAINER_ID, KieContainerStatus.STARTED, kieContainer);
Marshaller marshaller = containerInstance.getMarshaller(MarshallingFormat.JAXB);
// Call getResource() and verify release id
KieContainerResource containerResource = containerInstance.getResource();
Assertions.assertThat(containerResource).isNotNull();
verifyReleaseId(containerResource.getReleaseId(), RELEASE_ID_100);
verifyReleaseId(containerResource.getResolvedReleaseId(), RELEASE_ID_100);
// Marshaller is same - no change in release id
Marshaller updatedMarshaller = containerInstance.getMarshaller(MarshallingFormat.JAXB);
Assertions.assertThat(updatedMarshaller).isEqualTo(marshaller);
// Setting kie container with version change
containerInstance.getKieContainer().updateToVersion(RELEASE_ID_101);
// Call getResource() and verify release id
containerResource = containerInstance.getResource();
Assertions.assertThat(containerResource).isNotNull();
verifyReleaseId(containerResource.getReleaseId(), RELEASE_ID_101);
verifyReleaseId(containerResource.getResolvedReleaseId(), RELEASE_ID_101);
// Marshaller is different - release id was updated
updatedMarshaller = containerInstance.getMarshaller(MarshallingFormat.JAXB);
Assertions.assertThat(updatedMarshaller).isNotEqualTo(marshaller);
}
use of org.kie.server.api.marshalling.Marshaller in project droolsjbpm-integration by kiegroup.
the class KieContainerCommandServiceImpl method callContainer.
protected ServiceResponse<ExecutionResults> callContainer(String containerId, String payload, MarshallingFormat marshallingFormat, String classType, boolean marshallResponse) {
if (payload == null) {
return new ServiceResponse<ExecutionResults>(ServiceResponse.ResponseType.FAILURE, "Error calling container " + containerId + ". Empty payload. ");
}
try {
KieContainerInstanceImpl kci = (KieContainerInstanceImpl) context.getContainer(containerId, ContainerLocatorProvider.get().getLocator());
// call do dispose() is executed.
if (kci != null && kci.getKieContainer() != null) {
String sessionId = null;
// this is a weak way of finding the lookup, but it is the same used in kie-camel. Will keep it for now.
Matcher m = LOOKUP.matcher(payload);
if (m.find()) {
sessionId = m.group(1);
}
// find the session
CommandExecutor ks = null;
if (sessionId != null) {
ks = context.getKieSessionLookupManager().lookup(sessionId, kci, context);
} else {
// if no session ID is defined, then use default stateful/stateless ksession.
ks = KieServerUtils.getDefaultKieSession(kci);
}
context.getKieSessionLookupManager().postLookup(sessionId, kci, ks, context);
if (ks != null) {
Class<? extends Command> type = BatchExecutionCommandImpl.class;
if (classType != null && !classType.isEmpty()) {
type = (Class<? extends Command>) kci.getKieContainer().getClassLoader().loadClass(classType);
}
Command<?> cmd = kci.getMarshaller(marshallingFormat).unmarshall(payload, type);
if (cmd == null) {
return new ServiceResponse<ExecutionResults>(ServiceResponse.ResponseType.FAILURE, "Body of in message not of the expected type '" + Command.class.getName() + "'");
}
if (!(cmd instanceof BatchExecutionCommandImpl)) {
cmd = new BatchExecutionCommandImpl(Arrays.asList(new ExecutableCommand<?>[] { (ExecutableCommand<?>) cmd }));
}
ExecutionResults results = ks.execute((BatchExecutionCommandImpl) cmd);
if (marshallResponse) {
Marshaller marshaller = kci.getMarshaller(marshallingFormat);
String result = marshaller.marshall(results);
return new ServiceResponse(ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " successfully called.", result);
} else {
return new ServiceResponse<ExecutionResults>(ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " successfully called.", results);
}
} else {
return new ServiceResponse<ExecutionResults>(ServiceResponse.ResponseType.FAILURE, "Session '" + sessionId + "' not found on container '" + containerId + "'.");
}
} else {
return new ServiceResponse<ExecutionResults>(ServiceResponse.ResponseType.FAILURE, "Container " + containerId + " is not instantiated.");
}
} catch (Exception e) {
logger.error("Error calling container '" + containerId + "'", e);
return new ServiceResponse<ExecutionResults>(ServiceResponse.ResponseType.FAILURE, "Error calling container " + containerId + ": " + e.getClass().getName() + ": " + e.getMessage());
}
}
Aggregations