if (m.find()) {
sessionId = m.group(1);
}
// find the session
CommandExecutor ks = null;
if( sessionId != null ) {
KieSessionModel ksm = kci.getKieContainer().getKieSessionModel(sessionId);
if( ksm != null ) {
switch (ksm.getType() ) {
case STATEFUL:
ks = kci.getKieContainer().getKieSession(sessionId);
break;
case STATELESS:
ks = kci.getKieContainer().getStatelessKieSession(sessionId);
break;
}
}
} else {
// if no session ID is defined, then the default is a stateful session
ks = kci.getKieContainer().getKieSession();
}
if (ks != null) {
ClassLoader moduleClassLoader = kci.getKieContainer().getClassLoader();
XStream xs = XStreamXml.newXStreamMarshaller(moduleClassLoader);
Command<?> cmd = (Command<?>) xs.fromXML(payload);
if (cmd == null) {
return new ServiceResponse<String>(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 GenericCommand<?>[]{(GenericCommand<?>) cmd}));
}
ExecutionResults results = ks.execute((BatchExecutionCommandImpl) cmd);
String result = xs.toXML(results);
return new ServiceResponse<String>(ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " successfully called.", result);
} else {
return new ServiceResponse<String>(ServiceResponse.ResponseType.FAILURE, "Session '" + sessionId + "' not found on container '" + containerId + "'.");
}