}
MessageContext createSeqMsg = createSeqRMMsg.getMessageContext();
ConfigurationContext context = createSeqMsg.getConfigurationContext();
StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(context, context.getAxisConfiguration());
// If the inbound CreateSequence includes a SecurityTokenReference then
// ask the security manager to resolve that to a token for us. We also
// check that the Create was secured using the token.
SecurityManager secManager = SandeshaUtil.getSecurityManager(context);
OMElement theSTR = createSeqPart.getSecurityTokenReference();
SecurityToken token = null;
if(theSTR != null) {
MessageContext msgcontext = createSeqRMMsg.getMessageContext();
token = secManager.getSecurityToken(theSTR, msgcontext);
// The create must be the body part of this message, so we check the
// security of that element.
OMElement body = msgcontext.getEnvelope().getBody();
secManager.checkProofOfPossession(token, body, msgcontext);
}
//if toAddress is RMAnon we may need to terminate the request side sequence here.
EndpointReference toEPR = createSeqMsg.getTo();
if (toEPR.hasAnonymousAddress()) {
RMSBean findBean = new RMSBean ();
findBean.setReplyToEPR(toEPR.getAddress());
findBean.setTerminationPauserForCS(true);
//TODO recheck
RMSBean rmsBean = storageManager.getRMSBeanMgr().findUnique(findBean);
if (rmsBean!=null) {
//AckManager hs not done the termination. Do the termination here.
MessageContext requestSideRefMessage = storageManager.retrieveMessageContext(rmsBean.getReferenceMessageStoreKey(),context);
if (requestSideRefMessage==null) {
FaultManager.makeCreateSequenceRefusedFault(createSeqRMMsg,
SandeshaMessageHelper.getMessage(SandeshaMessageKeys.referencedMessageNotFound, rmsBean.getInternalSequenceID()),
new Exception());
// Return false if an Exception hasn't been thrown.
if (log.isDebugEnabled())
log.debug("Exit: CreateSeqMsgProcessor::processInMessage " + Boolean.FALSE);
return false;
}
RMMsgContext requestSideRefRMMessage = MsgInitializer.initializeMessage(requestSideRefMessage);
TerminateManager.addTerminateSequenceMessage(requestSideRefRMMessage, rmsBean.getInternalSequenceID(), rmsBean.getSequenceID(), storageManager);
}
}
MessageContext outMessage = null;
// Create the new sequence id, as well as establishing the beans that handle the
// sequence state.
RMDBean rmdBean = SequenceManager.setupNewSequence(createSeqRMMsg, storageManager, secManager, token);
RMMsgContext createSeqResponse = RMMsgCreator.createCreateSeqResponseMsg(createSeqRMMsg, rmdBean);
outMessage = createSeqResponse.getMessageContext();
// Set a message ID for this Create Sequence Response message
outMessage.setMessageID(SandeshaUtil.getUUID());
createSeqResponse.setFlow(MessageContext.OUT_FLOW);
// for making sure that this won't be processed again
createSeqResponse.setProperty(Sandesha2Constants.APPLICATION_PROCESSING_DONE, "true");
CreateSequenceResponse createSeqResPart = (CreateSequenceResponse) createSeqResponse
.getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ_RESPONSE);
// OFFER PROCESSING
SequenceOffer offer = createSeqPart.getSequenceOffer();
if (offer != null) {
Accept accept = createSeqResPart.getAccept();
if (accept == null) {
if (log.isDebugEnabled())
log.debug(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noAcceptPart));
FaultManager.makeCreateSequenceRefusedFault(createSeqRMMsg,
SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noAcceptPart),
new Exception());
// Return false if an Exception hasn't been thrown.
if (log.isDebugEnabled())
log.debug("Exit: CreateSeqMsgProcessor::processInMessage " + Boolean.FALSE);
return false;
}
// offered seq id
String offeredSequenceID = offer.getIdentifer().getIdentifier();
boolean offerEcepted = offerAccepted(offeredSequenceID, context, createSeqRMMsg, storageManager);
if (offerEcepted) {
// Setting the CreateSequence table entry for the outgoing
// side.
RMSBean rMSBean = new RMSBean();
rMSBean.setSequenceID(offeredSequenceID);
String outgoingSideInternalSequenceId = SandeshaUtil
.getOutgoingSideInternalSequenceID(rmdBean.getSequenceID());
rMSBean.setInternalSequenceID(outgoingSideInternalSequenceId);
// this is a dummy value
rMSBean.setCreateSeqMsgID(SandeshaUtil.getUUID());
rMSBean.setToEPR(rmdBean.getToEPR());
rMSBean.setAcksToEPR(rmdBean.getToEPR()); // The acks need to flow back into this endpoint
rMSBean.setReplyToEPR(rmdBean.getReplyToEPR());
rMSBean.setLastActivatedTime(System.currentTimeMillis());
rMSBean.setRMVersion(rmdBean.getRMVersion());
rMSBean.setClientCompletedMessages(new RangeString());
// Setting sequence properties for the outgoing sequence.
// Only will be used by the server side response path. Will
// be wasted properties for the client side.
Endpoint endpoint = offer.getEndpoint();
if (endpoint!=null) {
// setting the OfferedEndpoint
rMSBean.setOfferedEndPoint(endpoint.getEPR().getAddress());
}
rmdBean.setOutboundInternalSequence(outgoingSideInternalSequenceId);
RMDBeanMgr rmdBeanMgr = storageManager.getRMDBeanMgr();
rmdBeanMgr.update(rmdBean);
// Store the inbound token (if any) with the new sequence
rMSBean.setSecurityTokenData(rmdBean.getSecurityTokenData());
// If this new sequence has anonymous acksTo, then we must poll for the acks
// If the inbound sequence is targetted at the WSRM anonymous URI, we need to start
// polling for this sequence.
String acksTo = rMSBean.getAcksToEPR();
EndpointReference reference = new EndpointReference(acksTo);
if ((acksTo == null || reference.hasAnonymousAddress()) &&
Sandesha2Constants.SPEC_VERSIONS.v1_1.equals(createSeqRMMsg.getRMSpecVersion())) {
rMSBean.setPollingMode(true);
}
// Set the SOAP Version for this sequence.
rMSBean.setSoapVersion(SandeshaUtil.getSOAPVersion(createSeqRMMsg.getSOAPEnvelope()));
storageManager.getRMSBeanMgr().insert(rMSBean);
SandeshaUtil.startWorkersForSequence(context, rMSBean);
} else {
// removing the accept part.
createSeqResPart.setAccept(null);
createSeqResponse.addSOAPEnvelope();
}
}
//TODO add createSequenceResponse message as the referenceMessage to the RMDBean.
outMessage.setResponseWritten(true);
rmdBean.setLastActivatedTime(System.currentTimeMillis());
// If the inbound sequence is targetted at the anonymous URI, we need to start
// polling for this sequence.
if (toEPR.hasAnonymousAddress()) {
if (Sandesha2Constants.SPEC_VERSIONS.v1_1.equals(createSeqRMMsg.getRMSpecVersion())) {
rmdBean.setPollingMode(true);
}
}
storageManager.getRMDBeanMgr().update(rmdBean);
SandeshaUtil.startWorkersForSequence(context, rmdBean);
//
// We have done all of our updates, so commit the transaction