return executionEnvironment.getScheduler().execTransaction(new Callable<Object>(){
public Object call() throws Exception {
//We need to get a new mex from persistence layer.
PartnerRoleMessageExchange mex = (PartnerRoleMessageExchange) engine.getBpelServer().getEngine().getMessageExchange(mexId);
try
{
// Create SOAPMessage
SOAPMessage soapRequestMessage = MessageFactory.newInstance().createMessage();
if(log.isDebugEnabled())
log.debug( "ODE outbound message: \n" +DOMWriter.printNode(mex.getRequest().getMessage(), true) );
String soapAction=messageAdapter.createSoapRequest(soapRequestMessage,
new ODEMessageAdapter(mex.getRequest()), mex.getOperation());
if (log.isDebugEnabled()) {
log.debug("Riftsaw soap request message: \n" + JavaUtils.getSoapMessageASString(soapRequestMessage));
}
org.apache.ode.bpel.iapi.EndpointReference odeepr=mex.getEndpointReference();
javax.xml.ws.EndpointReference epr=null;
if (odeepr != null) {
if (odeepr instanceof org.apache.ode.bpel.epr.URLEndpoint) {
org.apache.ode.bpel.epr.URLEndpoint url=(org.apache.ode.bpel.epr.URLEndpoint)odeepr;
javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder builder=
new javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder();
epr = builder.address(url.getUrl())
.serviceName(serviceName)
.endpointName(port)
.build();
if (log.isDebugEnabled()) {
log.debug("EPR = " + epr);
}
}
} else if (log.isDebugEnabled()) {
log.debug("ODE has no EPR for this message exchange");
}
// The actual WS invocation
Dispatch<SOAPMessage> proxy = getDispatcher(epr, port);
setEndpointFromUDDI(proxy);
try {
// Set SOAPAction
if (soapAction != null) {
// Setting soap action using both approaches, as CXF needs one and JBossWS-Native the other
proxy.getRequestContext().put(Dispatch.SOAPACTION_URI_PROPERTY, soapAction);
MimeHeaders hd = soapRequestMessage.getMimeHeaders();
hd.addHeader("SOAPAction", soapAction);
} else if (log.isDebugEnabled()) {
log.debug("SOAPAction not set");
}
// Set client side timeout for the invocation
proxy.getRequestContext().put("javax.xml.ws.client.receiveTimeout", Long.toString(timeout));
SOAPMessage soapResponseMessage = proxy.invoke(soapRequestMessage);
if (log.isDebugEnabled()) {
log.debug("Riftsaw soap response message: \n" + JavaUtils.getSoapMessageASString(soapResponseMessage));
}
// Create ODE response
Message odeResponse = mex.createMessage(mex.getOperation().getOutput().getMessage().getQName());
if(soapResponseMessage.getSOAPBody().hasFault())
{
// fault handling
Document odeMsg = DOMUtils.newDocument();
Element odeMsgEl = odeMsg.createElementNS(null, "message");
odeMsg.appendChild(odeMsgEl);
Fault fault = messageAdapter.parseSoapFault(odeMsgEl, soapResponseMessage, mex.getOperation());
handleFault(mex, fault, soapResponseMessage.getSOAPBody().getFault(), odeMsgEl);
}
else
{
messageAdapter.parseSoapResponse(new ODEMessageAdapter(odeResponse),
soapResponseMessage,mex.getOperation());
mex.reply(odeResponse);
}
if(log.isDebugEnabled())
log.debug( "ODE inbound message: \n" +DOMWriter.printNode(odeResponse.getMessage(), true) );
} catch(javax.xml.ws.soap.SOAPFaultException fe) {
// fault handling
Document odeMsg = DOMUtils.newDocument();
Element odeMsgEl = odeMsg.createElementNS(null, "message");
odeMsg.appendChild(odeMsgEl);
if (log.isDebugEnabled()) {
log.debug("Riftsaw soap fault: \n" + DOMWriter.printNode(fe.getFault(), true));
}
Fault fault=messageAdapter.parseSoapFault(odeMsgEl, fe.getFault(),
mex.getOperation());
handleFault(mex, fault, fe.getFault(), odeMsgEl);
}
}
catch (Throwable e)
{
log.error("WS invocation failed", e);
mex.replyWithFailure(MessageExchange.FailureType.COMMUNICATION_ERROR, e.getMessage(), null);
}
return null;
}
});