use of org.kie.server.api.model.ServiceResponsesList in project droolsjbpm-integration by kiegroup.
the class KieServerResource method executeCommands.
@ApiOperation(value = "Executes one or more KIE Server commands for server-related or container-related operations")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, response = ServiceResponsesList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = EXECUTE_CMD_RESPONSE_JSON) })) })
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response executeCommands(@Context HttpHeaders headers, @ApiParam(value = "command script payload", required = true, examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = EXECUTE_CMD_JSON) })) String commandScriptPayload) {
String contentType = getContentType(headers);
CommandScript command = marshallerHelper.unmarshal(commandScriptPayload, contentType, CommandScript.class);
ServiceResponsesList result = delegate.executeScript(command, MarshallerHelper.getFormat(contentType), null);
return createCorrectVariant(result, headers);
}
use of org.kie.server.api.model.ServiceResponsesList in project droolsjbpm-integration by kiegroup.
the class WebSocketKieServerClient method activateContainer.
@Override
public ServiceResponse<KieContainerResource> activateContainer(String id) {
CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new ActivateContainerCommand(id)));
ServiceResponse<KieContainerResource> response = (ServiceResponse<KieContainerResource>) sendCommandToAllSessions(script, new WebSocketServiceResponse(true, (message) -> {
ServiceResponsesList list = WebSocketUtils.unmarshal(message, ServiceResponsesList.class);
return list.getResponses().get(0);
})).getResponses().get(0);
return response;
}
use of org.kie.server.api.model.ServiceResponsesList in project droolsjbpm-integration by kiegroup.
the class WebSocketKieServerClient method createContainer.
@Override
public ServiceResponse<KieContainerResource> createContainer(String id, KieContainerResource resource) {
CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new CreateContainerCommand(resource)));
ServiceResponse<KieContainerResource> response = (ServiceResponse<KieContainerResource>) sendCommandToAllSessions(script, new WebSocketServiceResponse(true, (message) -> {
ServiceResponsesList list = WebSocketUtils.unmarshal(message, ServiceResponsesList.class);
return list.getResponses().get(0);
})).getResponses().get(0);
return response;
}
use of org.kie.server.api.model.ServiceResponsesList in project droolsjbpm-integration by kiegroup.
the class WebSocketKieServerClient method getScannerInfo.
@Override
public ServiceResponse<KieScannerResource> getScannerInfo(String id) {
CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new GetScannerInfoCommand(id)));
ServiceResponse<KieScannerResource> response = (ServiceResponse<KieScannerResource>) sendCommand(script, new WebSocketServiceResponse(true, (message) -> {
ServiceResponsesList list = WebSocketUtils.unmarshal(message, ServiceResponsesList.class);
return list.getResponses().get(0);
})).getResponses().get(0);
return response;
}
use of org.kie.server.api.model.ServiceResponsesList in project droolsjbpm-integration by kiegroup.
the class CaseKieContainerCommandServiceImpl method executeScript.
@Override
public ServiceResponsesList executeScript(CommandScript commands, MarshallingFormat marshallingFormat, String classType) {
List<ServiceResponse<? extends Object>> responses = new ArrayList<ServiceResponse<? extends Object>>();
for (KieServerCommand command : commands.getCommands()) {
if (!(command instanceof DescriptorCommand)) {
logger.warn("Unsupported command '{}' given, will not process it", command.getClass().getName());
continue;
}
try {
Object result = null;
Object handler = null;
DescriptorCommand descriptorCommand = (DescriptorCommand) command;
// find out the handler to call to process given command
if ("CaseService".equals(descriptorCommand.getService())) {
handler = caseManagementServiceBase;
} else if ("CaseQueryService".equals(descriptorCommand.getService())) {
handler = caseManagementRuntimeDataService;
} else if ("CaseAdminService".equals(descriptorCommand.getService())) {
handler = caseAdminServiceBase;
} else {
throw new IllegalStateException("Unable to find handler for " + descriptorCommand.getService() + " service");
}
List<Object> arguments = new ArrayList();
// process and unwrap arguments
for (Object arg : descriptorCommand.getArguments()) {
logger.debug("Before :: Argument with type {} and value {}", arg.getClass(), arg);
if (arg instanceof Wrapped) {
arg = ((Wrapped) arg).unwrap();
}
logger.debug("After :: Argument with type {} and value {}", arg.getClass(), arg);
arguments.add(arg);
}
if (descriptorCommand.getPayload() != null && !descriptorCommand.getPayload().isEmpty()) {
arguments.add(descriptorCommand.getPayload());
}
if (descriptorCommand.getMarshallerFormat() != null && !descriptorCommand.getMarshallerFormat().isEmpty()) {
arguments.add(descriptorCommand.getMarshallerFormat());
}
logger.debug("About to execute {} operation on {} with args {}", descriptorCommand.getMethod(), handler, arguments);
// process command via reflection and handler
result = MethodUtils.invokeMethod(handler, descriptorCommand.getMethod(), arguments.toArray());
logger.debug("Handler {} returned response {}", handler, result);
// return successful result
responses.add(new ServiceResponse(ServiceResponse.ResponseType.SUCCESS, "", result));
} catch (InvocationTargetException e) {
responses.add(new ServiceResponse(ServiceResponse.ResponseType.FAILURE, e.getTargetException().getMessage()));
} catch (Throwable e) {
logger.error("Error while processing {} command", command, e);
// return failure result
responses.add(new ServiceResponse(ServiceResponse.ResponseType.FAILURE, e.getMessage()));
}
}
logger.debug("About to return responses '{}'", responses);
return new ServiceResponsesList(responses);
}
Aggregations