use of org.kie.server.api.marshalling.MarshallingFormat in project rhpam-7-openshift-image by jboss-container-images.
the class HelloRulesClient method runRemote.
private void runRemote(HelloRulesCallback callback, KieServicesConfiguration config) {
MarshallingFormat marshallingFormat = getMarshallingFormat();
config.setMarshallingFormat(marshallingFormat);
if (MarshallingFormat.JAXB.equals(marshallingFormat)) {
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(Greeting.class);
classes.add(Person.class);
config.addExtraClasses(classes);
}
RuleServicesClient client = KieServicesFactory.newKieServicesClient(config).getServicesClient(RuleServicesClient.class);
BatchExecutionCommand batch = createBatch();
ServiceResponse<ExecutionResults> response = client.executeCommandsWithResults("rhpam-kieserver-decisions", batch);
ExecutionResults execResults = response.getResult();
handleResults(callback, execResults);
}
use of org.kie.server.api.marshalling.MarshallingFormat in project rhpam-7-openshift-image by jboss-container-images.
the class LibraryClient method runRemote.
private void runRemote(PrintWriter out, KieServicesConfiguration kiecfg) throws Exception {
appcfg.setKieSession(null);
MarshallingFormat marshallingFormat = appcfg.getMarshallingFormat();
out.println(String.format("Using %s MarshallingFormat.%s", marshallingFormat.getType(), marshallingFormat.name()));
kiecfg.setMarshallingFormat(marshallingFormat);
if (MarshallingFormat.JAXB.equals(marshallingFormat)) {
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(Book.class);
classes.add(Loan.class);
classes.add(LoanRequest.class);
classes.add(LoanResponse.class);
classes.add(ReturnRequest.class);
classes.add(ReturnResponse.class);
classes.add(Suggestion.class);
classes.add(SuggestionRequest.class);
classes.add(SuggestionResponse.class);
kiecfg.addExtraClasses(classes);
}
KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(kiecfg);
RuleServicesClient ruleServicesClient = kieServicesClient.getServicesClient(RuleServicesClient.class);
ProcessServicesClient processServicesClient = kieServicesClient.getServicesClient(ProcessServicesClient.class);
appcfg.setRuleServicesClient(ruleServicesClient);
appcfg.setProcessServicesClient(processServicesClient);
runApp(out);
}
use of org.kie.server.api.marshalling.MarshallingFormat in project droolsjbpm-integration by kiegroup.
the class CommandResource method manageContainer.
@ApiOperation(value = "Executes one or more runtime commands")
@ApiResponses({ @ApiResponse(code = 200, message = "Successful execution", response = ServiceResponse.class), @ApiResponse(code = 500, message = "Unexpected error", response = ServiceResponse.class), @ApiResponse(code = 204, message = "Command execute successfully, but without response", response = ServiceResponse.class) })
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response manageContainer(@Context HttpHeaders headers, @ApiParam(value = "Container id where rules should be evaluated on", required = true) @PathParam(RestURI.CONTAINER_ID) String id, @ApiParam(value = "Commands to be executed on rule engine given as BatchExecutionCommand type", required = true) String cmdPayload) {
Variant v = getVariant(headers);
String contentType = getContentType(headers);
String classType = getClassType(headers);
MarshallingFormat format = MarshallingFormat.fromType(contentType);
if (format == null) {
format = MarshallingFormat.valueOf(contentType);
}
logger.debug("Received request with content '{}'", cmdPayload);
Header conversationIdHeader = buildConversationIdHeader(id, registry, headers);
@SuppressWarnings("squid:S3740") ServiceResponse<?> result = delegate.callContainer(id, cmdPayload, format, classType);
Status status = result.getType() == FAILURE ? INTERNAL_SERVER_ERROR : OK;
try {
String response = marshallerHelper.marshal(id, format.getType(), result, ContainerLocatorProvider.get().getLocator());
logger.debug("Returning {} response with content '{}'", status, response);
return createResponse(response, v, status, conversationIdHeader);
} catch (IllegalArgumentException e) {
// in case marshalling failed return the call container response to keep backward compatibility
String response = marshallerHelper.marshal(format.getType(), result);
logger.debug("Returning {} response with content '{}'", status, response);
return createResponse(response, v, status, conversationIdHeader);
}
}
use of org.kie.server.api.marshalling.MarshallingFormat in project droolsjbpm-integration by kiegroup.
the class MarshallerHelper method marshal.
public String marshal(String marshallingFormat, Object entity) {
MarshallingFormat format = getFormat(marshallingFormat);
if (format == null) {
throw new IllegalArgumentException("Unknown marshalling format " + marshallingFormat);
}
Marshaller marshaller = serverMarshallers.get(format);
if (marshaller == null) {
marshaller = MarshallerFactory.getMarshaller(getExtraClasses(registry), format, this.getClass().getClassLoader());
serverMarshallers.put(format, marshaller);
}
return marshaller.marshall(entity, MarshallingFormat.buildParameters(marshallingFormat));
}
use of org.kie.server.api.marshalling.MarshallingFormat in project droolsjbpm-integration by kiegroup.
the class MarshallerHelper method unmarshal.
public <T> T unmarshal(String containerId, String data, String marshallingFormat, Class<T> unmarshalType, ContainerLocator locator) {
if (data == null || data.isEmpty()) {
return null;
}
MarshallingFormat format = getFormat(marshallingFormat);
KieContainerInstance containerInstance = registry.getContainer(containerId, locator);
if (containerInstance == null || format == null) {
throw new IllegalArgumentException("No container found for id " + containerId + " or unknown marshalling format " + marshallingFormat);
}
Marshaller marshaller = containerInstance.getMarshaller(format);
if (marshaller == null) {
throw new IllegalArgumentException("No marshaller found for format " + format);
}
Object instance = marshaller.unmarshall(data, unmarshalType, MarshallingFormat.buildParameters(marshallingFormat));
if (instance instanceof Wrapped) {
return (T) ((Wrapped) instance).unwrap();
}
return (T) instance;
}
Aggregations