use of org.kie.server.api.marshalling.MarshallingFormat in project droolsjbpm-integration by kiegroup.
the class MarshallerHelper method marshal.
public String marshal(String containerId, String marshallingFormat, Object entity, ContainerLocator locator) {
MarshallingFormat format = getFormat(marshallingFormat);
if (format == null) {
throw new IllegalArgumentException("Unknown marshalling format " + marshallingFormat);
}
KieContainerInstance containerInstance = registry.getContainer(containerId, locator);
if (containerInstance == null) {
throw new IllegalArgumentException("No container found for id " + containerId + " .");
}
Marshaller marshaller = containerInstance.getMarshaller(format);
if (marshaller == null) {
throw new IllegalArgumentException("No marshaller found for format " + format);
}
return marshaller.marshall(entity, MarshallingFormat.buildParameters(marshallingFormat));
}
use of org.kie.server.api.marshalling.MarshallingFormat in project droolsjbpm-integration by kiegroup.
the class ControllerUtils method unmarshal.
public static <T> T unmarshal(String data, String marshallingFormat, Class<T> unmarshalType) {
if (data == null || data.isEmpty()) {
return null;
}
MarshallingFormat format = getFormat(marshallingFormat);
Marshaller marshaller = null;
switch(format) {
case JAXB:
{
marshaller = jaxbMarshaller;
break;
}
case JSON:
{
marshaller = jsonMarshaller;
break;
}
default:
{
marshaller = jsonMarshaller;
break;
}
}
Object instance = marshaller.unmarshall(data, unmarshalType);
if (instance instanceof Wrapped) {
return (T) ((Wrapped) instance).unwrap();
}
return (T) instance;
}
use of org.kie.server.api.marshalling.MarshallingFormat in project droolsjbpm-integration by kiegroup.
the class CloudEventReader method readEvent.
@Override
public <T> T readEvent(byte[] value, Class<T> valueType) throws IOException {
JsonNode node = mapper.readTree(value);
MarshallingFormat contentType = MarshallingFormat.JSON;
if (node.has("datacontenttype")) {
contentType = MarshallingFormat.fromType(node.get("datacontenttype").asText());
}
if (node.has("data")) {
Marshaller marshaller = marshallers.computeIfAbsent(contentType, c -> MarshallerFactory.getMarshaller(c, cl));
return marshaller.unmarshall(node.get("data").toString(), valueType);
}
throw new IOException("Missing data field in cloud event " + new String(value));
}
use of org.kie.server.api.marshalling.MarshallingFormat in project businessautomation-cop by redhat-cop.
the class ReopenProcessResource method queryCases.
@POST
@Path("/reopen/{instanceId}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response queryCases(@Context HttpHeaders headers, @PathParam("instanceId") Long instanceId, List<String> nodes) {
logger.info("Reopening process instance with id {} and nodes {}", instanceId, nodes);
Variant v = getVariant(headers);
String contentType = getContentType(headers);
MarshallingFormat format = MarshallingFormat.fromType(contentType);
if (format == null) {
format = MarshallingFormat.valueOf(contentType);
}
try {
Long newPid = reopenService.reopenProcess(instanceId, nodes);
return createResponse(newPid, v, Response.Status.OK);
} catch (Exception e) {
// in case marshalling failed return the call container response to
// keep backward compatibility
e.printStackTrace();
String response = "Execution failed with error : " + e.getMessage();
logger.error("Returning Failure response with content '{}'", response);
return createResponse(response, v, Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of org.kie.server.api.marshalling.MarshallingFormat in project businessautomation-cop by redhat-cop.
the class AbortAllResource method abortAllContainerInstances.
@DELETE
@Path("/abortAll")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response abortAllContainerInstances(@Context HttpHeaders headers, @PathParam("id") String containerId) {
Variant v = getVariant(headers);
String contentType = getContentType(headers);
MarshallingFormat format = MarshallingFormat.fromType(contentType);
if (format == null) {
format = MarshallingFormat.valueOf(contentType);
}
MarshallerHelper marshallerHelper = new MarshallerHelper(registry);
try {
// get active instances
Collection<ProcessInstanceDesc> activeInstances = runtimeDataService.getProcessInstancesByDeploymentId(containerId, Arrays.asList(1), /* active */
null);
// extract their pids
List<Long> pids = activeInstances.stream().map(activeInstance -> activeInstance.getId()).collect(Collectors.toList());
// abort them all
processService.abortProcessInstances(containerId, pids);
String result = marshallerHelper.marshal(format.toString(), pids);
logger.debug("Aborted following instances:" + result + ", in a following container:" + containerId);
return 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 createResponse(response, v, Response.Status.INTERNAL_SERVER_ERROR);
}
}
Aggregations