ProcessMessageExchangeEvent evt = new ProcessMessageExchangeEvent();
evt.setOperation(operation.getName());
evt.setPortType(partnerLink.partnerLink.partnerRolePortType.getQName());
evt.setAspect(ProcessMessageExchangeEvent.PARTNER_INPUT);
MessageExchangeDAO mexDao = _dao.getConnection().createMessageExchange(
MessageExchangeDAO.DIR_BPEL_INVOKES_PARTNERROLE);
mexDao.setStatus(MessageExchange.Status.NEW.toString());
mexDao.setOperation(operation.getName());
mexDao.setPortType(partnerLink.partnerLink.partnerRolePortType.getQName());
mexDao.setPartnerLinkModelId(partnerLink.partnerLink.getId());
mexDao.setPartnerLink(plinkDAO);
mexDao.setProcess(_dao.getProcess());
mexDao.setInstance(_dao);
mexDao.setPattern((operation.getOutput() != null ? MessageExchangePattern.REQUEST_RESPONSE
: MessageExchangePattern.REQUEST_ONLY).toString());
mexDao.setChannel(channel == null ? null : channel.export());
// Properties used by stateful-exchange protocol.
String mySessionId = plinkDAO.getMySessionId();
String partnerSessionId = plinkDAO.getPartnerSessionId();
if ( mySessionId != null )
mexDao.setProperty(MessageExchange.PROPERTY_SEP_MYROLE_SESSIONID, mySessionId);
if ( partnerSessionId != null )
mexDao.setProperty(MessageExchange.PROPERTY_SEP_PARTNERROLE_SESSIONID, partnerSessionId);
if (__log.isDebugEnabled())
__log.debug("INVOKE PARTNER (SEP): sessionId=" + mySessionId + " partnerSessionId=" + partnerSessionId);
MessageDAO message = mexDao.createMessage(operation.getInput().getMessage().getQName());
mexDao.setRequest(message);
message.setData(outgoingMessage);
message.setType(operation.getInput().getMessage().getQName());
// Get he my-role EPR (if myrole exists) for optional use by partner
// (for callback mechanism).
EndpointReference myRoleEndpoint = partnerLink.partnerLink.hasMyRole() ? _bpelProcess
.getInitialMyRoleEPR(partnerLink.partnerLink) : null;
PartnerRoleMessageExchangeImpl mex = new PartnerRoleMessageExchangeImpl(_bpelProcess._engine, mexDao,
partnerLink.partnerLink.partnerRolePortType, operation, partnerEpr, myRoleEndpoint, _bpelProcess
.getPartnerRoleChannel(partnerLink.partnerLink));
BpelProcess p2pProcess = null;
Endpoint partnerEndpoint = _bpelProcess.getInitialPartnerRoleEndpoint(partnerLink.partnerLink);
if (partnerEndpoint != null)
p2pProcess = _bpelProcess.getEngine().route(partnerEndpoint.serviceName, mex.getRequest());
if (p2pProcess != null) {
// Creating a my mex using the same message id as partner mex to "pipe" them
MyRoleMessageExchange myRoleMex = _bpelProcess.getEngine().createMessageExchange(
mex.getMessageExchangeId(), partnerEndpoint.serviceName,
operation.getName(), mex.getMessageExchangeId());
if (BpelProcess.__log.isDebugEnabled()) {
__log.debug("Invoking in a p2p interaction, partnerrole " + mex + " - myrole " + myRoleMex);
}
Message odeRequest = myRoleMex.createMessage(operation.getInput().getMessage().getQName());
odeRequest.setMessage(outgoingMessage);
if (BpelProcess.__log.isDebugEnabled()) {
__log.debug("Setting myRoleMex session ids for p2p interaction, mySession "
+ partnerSessionId + " - partnerSess " + mySessionId);
}
if ( partnerSessionId != null )
myRoleMex.setProperty(MessageExchange.PROPERTY_SEP_MYROLE_SESSIONID, partnerSessionId);
if ( mySessionId != null )
myRoleMex.setProperty(MessageExchange.PROPERTY_SEP_PARTNERROLE_SESSIONID, mySessionId);
mex.setStatus(MessageExchange.Status.REQUEST);
myRoleMex.invoke(odeRequest);
// Can't expect any sync response
mex.replyAsync();
} else {
// If we couldn't find the endpoint, then there is no sense
// in asking the IL to invoke.
if (partnerEpr != null) {
mexDao.setEPR(partnerEpr.toXML().getDocumentElement());
mex.setStatus(MessageExchange.Status.REQUEST);
_bpelProcess._engine._contexts.mexContext.invokePartner(mex);
} else {
__log.error("Couldn't find endpoint for partner EPR " + DOMUtils.domToString(partnerEPR));
mex.setFailure(FailureType.UNKNOWN_ENDPOINT, "UnknownEndpoint", partnerEPR);
}
}
evt.setMexId(mexDao.getMessageExchangeId());
sendEvent(evt);
// MEX pattern is request only, at this point the status can only be a one way
if (mexDao.getPattern().equals(MessageExchangePattern.REQUEST_ONLY.toString())) {
mexDao.setStatus(MessageExchange.Status.ASYNC.toString());
// This mex can now be released
mexDao.release();
}
// Check if there is a synchronous response, if so, we need to inject the
// message on the response channel.
switch (mex.getStatus()) {
case NEW:
throw new AssertionError("Impossible!");
case ASYNC:
break;
case RESPONSE:
case FAULT:
case FAILURE:
invocationResponse(mex);
break;
default:
__log.error("Partner did not acknowledge message exchange: " + mex);
mex.setFailure(FailureType.NO_RESPONSE, "Partner did not acknowledge.", null);
invocationResponse(mex);
}
return mexDao.getMessageExchangeId();
}