public Object doTheWork(Object[] args) throws InvocationTargetException {
Element response = null;
if(! (operation.getInterface() instanceof WSDLInterface)) {
throw new InvocationTargetException(null,"Unsupported service contract");
}
org.apache.ode.bpel.iapi.MyRoleMessageExchange mex = null;
Future onhold = null;
//Process the BPEL process invocation
try {
txMgr.begin();
mex = odeServer.getBpelServer().getEngine().createMessageExchange(new GUID().toString(),
bpelServiceName,
bpelOperationName);
onhold = mex.invoke(createInvocationMessage(mex, args));
txMgr.commit();
} catch (Exception e) {
try {
txMgr.rollback();
} catch (SystemException se) {
}
throw new InvocationTargetException(e, "Error invoking BPEL process : " + e.getMessage());
}
// Waiting until the reply is ready in case the engine needs to continue in a different thread
if (onhold != null) {
try {
onhold.get();
} catch (Exception e) {
throw new InvocationTargetException(e,"Error invoking BPEL process : " + e.getMessage());
}
}
//Process the BPEL invocation response
try {
txMgr.begin();
// Reloading the mex in the current transaction, otherwise we can't
// be sure we have the "freshest" one.
mex = (MyRoleMessageExchange)odeServer.getBpelServer().getEngine().getMessageExchange(mex.getMessageExchangeId());
Status status = mex.getStatus();
System.out.println("Status: " + status.name());
Element invocationResponse = mex.getResponse().getMessage();
System.out.println("Response: " + DOMUtils.domToString(invocationResponse));
//process the method invocation result
response = processResponse(invocationResponse);
txMgr.commit();
// end of transaction two
} catch (Exception e) {
try {
txMgr.rollback();
} catch (SystemException se) {
}
throw new InvocationTargetException(e, "Error retrieving BPEL process invocation status : " + e
.getMessage());
}
return response;