public String scheduleRequest(String containerId, String payload, String marshallingType) {
ClassLoader classLoader = this.getClass().getClassLoader();
JobRequestInstance jobRequest = null;
if (containerId != null && !containerId.isEmpty()) {
logger.debug("About to unmarshal job request from payload: '{}' using container {} marshaller", payload, containerId);
jobRequest = marshallerHelper.unmarshal(containerId, payload, marshallingType, JobRequestInstance.class);
jobRequest.getData().put("deploymentId", containerId);
classLoader = context.getContainer(containerId).getKieContainer().getClassLoader();
} else {
logger.debug("About to unmarshal job request from payload: '{}' using server marshaller", payload);
jobRequest = marshallerHelper.unmarshal(payload, marshallingType, JobRequestInstance.class);
}
Long requestId = null;
if(!validateCommand(jobRequest.getCommand(), classLoader)){
throw new IllegalArgumentException("Invalid command type "+jobRequest.getCommand());
}
if (jobRequest.getScheduledDate() != null) {
logger.debug("Scheduling job at future date '{}' for request {}", jobRequest.getScheduledDate(), jobRequest);
requestId = executorService.scheduleRequest(jobRequest.getCommand(), jobRequest.getScheduledDate(), new CommandContext(jobRequest.getData()));
} else {
logger.debug("Scheduling job at current date '{}' for request {}", new Date(), jobRequest);
requestId = executorService.scheduleRequest(jobRequest.getCommand(), new CommandContext(jobRequest.getData()));
}
String response = marshallerHelper.marshal(marshallingType, requestId);
return response;
}