ProcessMessageExchangeEvent evt = new ProcessMessageExchangeEvent();
evt.setMexId(mexId);
evt.setOperation(opName);
evt.setPortType(plinkInstnace.partnerLink.myRolePortType.getQName());
MessageExchangeDAO mex = _dao.getConnection().getMessageExchange(mexRef);
MessageDAO message = mex.createMessage(plinkInstnace.partnerLink.getMyRoleOperation(opName).getOutput()
.getMessage().getQName());
buildOutgoingMessage(message, msg);
MyRoleMessageExchangeImpl m = new MyRoleMessageExchangeImpl(_bpelProcess._engine, mex);
_bpelProcess.initMyRoleMex(m);
m.setResponse(new MessageImpl(message));
if (fault != null) {
mex.setStatus(MessageExchange.Status.FAULT.toString());
mex.setFault(fault);
evt.setAspect(ProcessMessageExchangeEvent.PROCESS_FAULT);
} else {
mex.setStatus(MessageExchange.Status.RESPONSE.toString());
evt.setAspect(ProcessMessageExchangeEvent.PROCESS_OUTPUT);
}
if (mex.getPipedMessageExchangeId() != null) {
PartnerRoleMessageExchange pmex = (PartnerRoleMessageExchange) _bpelProcess
.getEngine().getMessageExchange(mex.getPipedMessageExchangeId());
if (BpelProcess.__log.isDebugEnabled()) {
__log.debug("Replying to a p2p mex, myrole " + m + " - partnerole " + pmex);
}
try {
switch (m.getStatus()) {
case FAILURE:
// We can't seem to get the failure out of the myrole mex?
pmex.replyWithFailure(MessageExchange.FailureType.OTHER, "operation failed", null);
break;
case FAULT:
Message faultRes = pmex.createMessage(pmex.getOperation().getFault(m.getFault().getLocalPart())
.getMessage().getQName());
faultRes.setMessage(m.getResponse().getMessage());
pmex.replyWithFault(m.getFault(), faultRes);
break;
case RESPONSE:
Message response = pmex.createMessage(pmex.getOperation().getOutput().getMessage().getQName());
response.setMessage(m.getResponse().getMessage());
pmex.reply(response);
break;
default:
__log.warn("Unexpected state: " + m.getStatus());
break;
}
} finally {
mex.release();
}
} else _bpelProcess._engine._contexts.mexContext.onAsyncReply(m);
// send event
sendEvent(evt);