createSeqResponse.setFlow(MessageContext.OUT_FLOW);
// for making sure that this won't be processed again
createSeqResponse.setProperty(Sandesha2Constants.APPLICATION_PROCESSING_DONE, "true");
CreateSequenceResponse createSeqResPart = createSeqResponse.getCreateSequenceResponse();
// 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(),
null);
// 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();
//Need to see if this is a duplicate offer.
//If it is we can't accept the offer as we can't be sure it has come from the same client.
RMSBean finderBean = new RMSBean ();
finderBean.setSequenceID(offeredSequenceID);
RMSBean rMSBean = storageManager.getRMSBeanMgr().findUnique(finderBean);
boolean offerAccepted = false;
String outgoingSideInternalSequenceId = SandeshaUtil
.getOutgoingSideInternalSequenceID(rmdBean.getSequenceID());
if(rMSBean != null){
if (log.isDebugEnabled())
log.debug("Duplicate offer so we can't accept as we can't be sure it's from the same client: " + offeredSequenceID);
offerAccepted = false;
} else {
boolean isValidseqID = isValidseqID(offeredSequenceID, context, createSeqRMMsg, storageManager);
offerAccepted = true;
//Before processing this offer any further we need to perform some extra checks
//on the offered EP if WS-RM Spec 1.1 is being used
if(isValidseqID && Sandesha2Constants.SPEC_VERSIONS.v1_1.equals(rmdBean.getRMVersion())){
Endpoint endpoint = offer.getEndpoint();
if (endpoint!=null) {
//Check to see if the offer endpoint has a value of WSA Anonymous
String addressingNamespace = (String) createSeqRMMsg.getProperty(AddressingConstants.WS_ADDRESSING_VERSION);
String endpointAddress = endpoint.getEPR().getAddress();
if(SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespace).equals(endpointAddress)){
//We will still accept this offer but we should warn the user that this MEP is not always reliable or efficient
if (log.isDebugEnabled())
log.debug("CSeq msg contains offer with an anonymous EPR");
log.warn(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.sequenceMEPWarning, createSeqRMMsg.getMessageContext().getMessageID(),
offeredSequenceID));
}
rMSBean = new RMSBean();
//Set the offered EP
rMSBean.setOfferedEndPointEPR(endpoint.getEPR());
} else {
//Don't accept the offer
if (log.isDebugEnabled())
log.debug("Offer Refused as it included a null endpoint");
offerAccepted = false;
}
} else if (isValidseqID && Sandesha2Constants.SPEC_VERSIONS.v1_0.equals(rmdBean.getRMVersion())){
rMSBean = new RMSBean();
}
if(isValidseqID){
// Setting the CreateSequence table entry for the outgoing
// side.
rMSBean.setSequenceID(offeredSequenceID);
rMSBean.setInternalSequenceID(outgoingSideInternalSequenceId);
// this is a dummy value
rMSBean.setCreateSeqMsgID(SandeshaUtil.getUUID());
//Try inserting the new RMSBean
if(!storageManager.getRMSBeanMgr().insert(rMSBean)){
offerAccepted = false;
}
}
}
if (offerAccepted) {
if(rmdBean.getToEndpointReference() != null){
rMSBean.setToEndpointReference(rmdBean.getToEndpointReference());
} else {
//It's Sync2Way so set to address to anonymous when spec 1.0 is used
String specVersion = rmdBean.getRMVersion();
if (Sandesha2Constants.SPEC_VERSIONS.v1_0.equals(specVersion)) {
rMSBean.setToEndpointReference(new EndpointReference(AddressingConstants.Submission.WSA_ANONYMOUS_URL));
}
}
rMSBean.setAcksToEndpointReference(rmdBean.getReplyToEndpointReference()); // The acks need to flow back into this endpoint
rMSBean.setReplyToEndpointReference(rmdBean.getReplyToEndpointReference());
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.
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.
EndpointReference reference = rMSBean.getAcksToEndpointReference();
if ((reference == 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().update(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.