public boolean processInMessage(RMMsgContext createSeqRMMsg) throws AxisFault {
if (log.isDebugEnabled())
log.debug("Enter: CreateSeqMsgProcessor::processInMessage");
MessageContext createSeqMsg = createSeqRMMsg.getMessageContext();
CreateSequence createSeqPart = (CreateSequence) createSeqRMMsg
.getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ);
if (createSeqPart == null) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noCreateSeqParts);
log.debug(message);
throw new SandeshaException(message);
}
ConfigurationContext context = createSeqMsg.getConfigurationContext();
StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(context, context.getAxisConfiguration());
FaultManager faultManager = new FaultManager();
SandeshaException fault = faultManager.checkForCreateSequenceRefused(createSeqMsg, storageManager);
if (fault != null) {
throw fault;
}
// 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.
OMElement theSTR = createSeqPart.getSecurityTokenReference();
SecurityToken token = null;
if(theSTR != null) {
SecurityManager secManager = SandeshaUtil.getSecurityManager(context);
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);
}
MessageContext outMessage = null;
try {
outMessage = Utils.createOutMessageContext(createSeqMsg); // createing
// a new
// response
// message.
} catch (AxisFault e1) {
throw new SandeshaException(e1);
}
SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropertyBeanMgr();
try {
String newSequenceId = SequenceManager.setupNewSequence(createSeqRMMsg, storageManager); // newly
// created
// sequnceID.
RMMsgContext createSeqResponse = RMMsgCreator.createCreateSeqResponseMsg(createSeqRMMsg, outMessage,
newSequenceId, storageManager); // converting the blank out
// message in to a create
// sequence response.
createSeqResponse.setFlow(MessageContext.OUT_FLOW);
createSeqResponse.setProperty(Sandesha2Constants.APPLICATION_PROCESSING_DONE, "true"); // for
// making
// sure
// that
// this
// wont
// be
// processed
// again.
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) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noAcceptPart);
log.debug(message);
throw new SandeshaException(message);
}
String offeredSequenceID = offer.getIdentifer().getIdentifier(); // offered
// seq.
// id.
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(newSequenceId);
rmsBean.setInternalSequenceID(outgoingSideInternalSequenceId);
rmsBean.setCreateSeqMsgID(SandeshaUtil.getUUID()); // this
// is a
// dummy
// value.
String outgoingSideSequencePropertyKey = outgoingSideInternalSequenceId;
RMSBeanMgr rmsBeanMgr = storageManager.getRMSBeanMgr();
rmsBeanMgr.insert(rmsBean);
// 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.
// setting the out_sequence_id
SequencePropertyBean outSequenceBean = new SequencePropertyBean();
outSequenceBean.setName(Sandesha2Constants.SequenceProperties.OUT_SEQUENCE_ID);
outSequenceBean.setValue(offeredSequenceID);
outSequenceBean.setSequencePropertyKey(outgoingSideSequencePropertyKey);
seqPropMgr.insert(outSequenceBean);
// setting the internal_sequence_id
SequencePropertyBean internalSequenceBean = new SequencePropertyBean();
internalSequenceBean.setName(Sandesha2Constants.SequenceProperties.INTERNAL_SEQUENCE_ID);
internalSequenceBean.setSequencePropertyKey(offeredSequenceID);
internalSequenceBean.setValue(outgoingSideInternalSequenceId);
seqPropMgr.insert(internalSequenceBean);
Endpoint endpoint = offer.getEndpoint();
if (endpoint!=null) {
// setting the OfferedEndpoint
SequencePropertyBean offeredEndpointBean = new SequencePropertyBean();
offeredEndpointBean.setName(Sandesha2Constants.SequenceProperties.OFFERED_ENDPOINT);
//currently we can only serialize the Address part of the Endpoint.
//TODO correct this to serialize the whole EPR.
offeredEndpointBean.setValue(endpoint.getEPR().getAddress());
offeredEndpointBean.setSequencePropertyKey(outgoingSideSequencePropertyKey);
seqPropMgr.insert(offeredEndpointBean);
}
} else {
// removing the accept part.
createSeqResPart.setAccept(null);
createSeqResponse.addSOAPEnvelope();
}
}
EndpointReference acksTo = createSeqPart.getAcksTo().getEPR();
if (acksTo == null || acksTo.getAddress() == null || "".equals(acksTo.getAddress())) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noAcksToPartInCreateSequence);
log.debug(message);
throw new AxisFault(message);
}