_log.debug("SOAPAction: " + soapAction);
// We need both convertors in each case (since we need to convert
// replies as well
WorkflowProcessesMessageConvertor wf2up = new WorkflowProcessesMessageConvertor();
UserProcessMessageConvertor up2wf = new UserProcessMessageConvertor();
SAXReader reader = new SAXReader();
MessageSender messageSender = getMessageSender();
FormDispatcherConfiguration config = FormDispatcherConfiguration.getInstance();
// the XML document to return as the HTTP response payload
Document responseDocument = null;
try {
if (fdsUri.equals(_IB4P_URI)) {
// it is a request from the Workflow Processes
_log.info("Workflow Processes -> User Process");
_log.debug("Parsing the request from the Workflow Processes.");
Document workflowProcessesRequest = reader.read(request.getInputStream());
if (_log.isDebugEnabled()) {
_log.debug("Workflow process request:\n" + workflowProcessesRequest.asXML() + "\n");
_log.debug("Converting the request to the user process format.");
}
// null means that the convertor will figure out the user
// process namespace itself
wf2up.convertMessage(workflowProcessesRequest, null);
if (_log.isDebugEnabled()) {
_log.debug("Workflow process request (after conversion):\n" + workflowProcessesRequest.asXML() + "\n");
}
if (wf2up.getSoapAction() != null) {
soapAction = wf2up.getSoapAction();
_log.debug("Completion SOAP Action: '" + soapAction + "'");
}
// SOAP Action should always be quoted (WS-Interop)
if (soapAction == null || soapAction.length() == 0) {
soapAction = "\"\"";
} else if (soapAction.charAt(0) != '\"') {
soapAction = "\"" + soapAction + "\"";
}
String userProcessEndpoint = wf2up.getUserProcessEndpoint();
_log.debug("Sending the request to the user process and getting the response");
Document userProcessResponse = messageSender.requestAndGetReply(workflowProcessesRequest, userProcessEndpoint, soapAction);
if (_log.isDebugEnabled()) {
_log.debug("User process response:\n" + userProcessResponse.asXML() + "\n");
_log.debug("Converting the response to the Workflow Processes format.");
}
up2wf.convertMessage(userProcessResponse);
if (_log.isDebugEnabled()) {
_log.debug("Sending the converted response back to the Workflow Processes.");
_log.debug("User process response (after conversion)\n" + userProcessResponse.asXML() + "\n");
}
responseDocument = userProcessResponse;
} else {
// it is a request from a user process
_log.debug("User Process -> Workflow Processes");
// get the full URL of the workflow process endpoint
String workflowProcessesEndpoint = config.getPxeBaseUrl() + config.getWorkflowProcessesRelativeUrl();
_log.debug("Parsing the request from the user process.");
Document userProcessRequest = reader.read(request.getInputStream());
if (_log.isDebugEnabled()) {
_log.debug("User process request:\n" + userProcessRequest.asXML() + "\n");
}
Document pureRequest = SoapTools.unwrapMessage(userProcessRequest);
Element rootElement = pureRequest.getRootElement();
String rootElementName = rootElement.getName();
IDispatcher dispatcher = null;
try {
dispatcher = Dispatchers.createDispatcher(rootElementName);
} catch (NoDispatcherException e) {
_log.debug("No custom dispatcher, using the default processing");
}
if (dispatcher != null) {
// TODO: convert the default processing to an IDispatcher
try {
Document processedRequest = dispatcher.dispatchRequest(pureRequest);
Document wrappedRequest = SoapTools.wrapMessage(processedRequest);
String endpoint = dispatcher.getTargetEndpoint();
String dispatcherSoapAction = dispatcher.getTargetSoapAction();
Document rawResponse = messageSender.requestAndGetReply(wrappedRequest, endpoint, dispatcherSoapAction);
Document unwrappedResponse = SoapTools.unwrapMessage(rawResponse);
Document processedResponse = dispatcher.dispatchResponse(unwrappedResponse);
responseDocument = SoapTools.wrapMessage(processedResponse);
} catch (InvalidInputFormatException e) {
_log.error("Error converting user process request", e);
// TODO: return a SOAP fault
throw new RuntimeException(e);
}
} else {
_log.debug("Converting the request to the Workflow Processes format.");
up2wf.convertMessage(userProcessRequest);
if (_log.isDebugEnabled()) {
_log.debug("\n" + userProcessRequest.asXML() + "\n");
}
String userProcessNamespaceUri = up2wf.getUserProcessNamespaceUri();
_log.debug("Sending the converted request to the Workflow Processes and getting the response.");
if (up2wf.getSoapAction() != null){
soapAction = up2wf.getSoapAction();
}
_log.debug("SOAP Action:" + soapAction);
Document workflowProcessesResponse = messageSender.requestAndGetReply(userProcessRequest, workflowProcessesEndpoint, soapAction);
if (_log.isDebugEnabled()) {