//saving the used message number
if (!dummyMessage)
setNextMsgNo(configContext,internalSequenceId,messageNumber);
//set this as the response highest message.
SequencePropertyBean responseHighestMsgBean = new SequencePropertyBean (
internalSequenceId,
Sandesha2Constants.SequenceProperties.HIGHEST_OUT_MSG_NUMBER,
new Long (messageNumber).toString()
);
seqPropMgr.insert(responseHighestMsgBean);
if (lastMessage) {
SequencePropertyBean responseHighestMsgKeyBean = new SequencePropertyBean (
internalSequenceId,
Sandesha2Constants.SequenceProperties.HIGHEST_OUT_MSG_KEY,
storageKey
);
SequencePropertyBean responseLastMsgKeyBean = new SequencePropertyBean (
internalSequenceId,
Sandesha2Constants.SequenceProperties.LAST_OUT_MESSAGE_NO,
new Long (messageNumber).toString()
);
seqPropMgr.insert(responseHighestMsgKeyBean);
seqPropMgr.insert(responseLastMsgKeyBean);
}
boolean sendCreateSequence = false;
SequencePropertyBean outSeqBean = seqPropMgr.retrieve(
internalSequenceId,
Sandesha2Constants.SequenceProperties.OUT_SEQUENCE_ID);
// setting async ack endpoint for the server side. (if present)
if (serverSide) {
String incomingSequenceID = SandeshaUtil
.getServerSideIncomingSeqIdFromInternalSeqId(internalSequenceId);
SequencePropertyBean incomingToBean = seqPropMgr.retrieve(
incomingSequenceID,
Sandesha2Constants.SequenceProperties.TO_EPR);
if (incomingToBean != null) {
String incomingTo = incomingToBean.getValue();
msgContext.setProperty(SandeshaClientConstants.AcksTo, incomingTo);
}
}
//FINDING THE SPEC VERSION
String specVersion = null;
if (msgContext.isServerSide()) {
//in the server side, get the RM version from the request sequence.
MessageContext requestMessageContext;
try {
requestMessageContext = msgContext.getOperationContext().getMessageContext(AxisOperationFactory.MESSAGE_LABEL_IN_VALUE);
} catch (AxisFault e) {
throw new SandeshaException (e);
}
if (requestMessageContext==null)
throw new SandeshaException ("Request message context is null, cant find out the request side sequenceID");
RMMsgContext requestRMMsgCtx = MsgInitializer.initializeMessage(requestMessageContext);
Sequence sequence = (Sequence) requestRMMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
String requestSequenceID = sequence.getIdentifier().getIdentifier();
SequencePropertyBean specVersionBean = seqPropMgr.retrieve(requestSequenceID,Sandesha2Constants.SequenceProperties.RM_SPEC_VERSION);
if (specVersionBean==null)
throw new SandeshaException ("SpecVersion sequence property bean is not available for the incoming sequence. Cant find the RM version for outgoing side");
specVersion = specVersionBean.getValue();
} else {
//in the client side, user will set the RM version.
specVersion = (String) msgContext.getProperty(SandeshaClientConstants.RM_SPEC_VERSION);
}
if (specVersion==null)
specVersion = SpecSpecificConstants.getDefaultSpecVersion(); //TODO change the default to v1_1.
if (messageNumber == 1) {
if (outSeqBean == null) { // out sequence will be set for the server side, in the case of an offer.
sendCreateSequence = true; // message number being one and not having an out sequence, implies that a create sequence has to be send.
}
// if fist message - setup the sending side sequence - both for the server and the client sides
SequenceManager.setupNewClientSequence(msgContext, internalSequenceId,specVersion);
}
ServiceContext serviceContext = msgContext.getServiceContext();
OperationContext operationContext = msgContext.getOperationContext();
//SENDING THE CREATE SEQUENCE.
if (sendCreateSequence) {
SequencePropertyBean responseCreateSeqAdded = seqPropMgr
.retrieve(internalSequenceId,Sandesha2Constants.SequenceProperties.OUT_CREATE_SEQUENCE_SENT);
String addressingNamespaceURI = SandeshaUtil.getSequenceProperty(internalSequenceId,Sandesha2Constants.SequenceProperties.ADDRESSING_NAMESPACE_VALUE,configContext);
String anonymousURI = SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespaceURI);
if (responseCreateSeqAdded == null) {
responseCreateSeqAdded = new SequencePropertyBean(
internalSequenceId,Sandesha2Constants.SequenceProperties.OUT_CREATE_SEQUENCE_SENT,"true");
seqPropMgr.insert(responseCreateSeqAdded);
String acksTo = null;
if (serviceContext != null)
acksTo = (String) msgContext.getProperty(SandeshaClientConstants.AcksTo);
if (msgContext.isServerSide()) {
// we do not set acksTo value to anonymous when the create
// sequence is send from the server.
MessageContext requestMessage;
try {
requestMessage = operationContext.getMessageContext(OperationContextFactory.MESSAGE_LABEL_IN_VALUE);
} catch (AxisFault e) {
throw new SandeshaException (e);
}
if (requestMessage == null) {
String message = "Request message is not present";
log.debug(message);
throw new SandeshaException(message);
}
acksTo = requestMessage.getTo().getAddress();
} else {
if (acksTo == null)
acksTo = anonymousURI;
}
if (!anonymousURI.equals(acksTo) && !serverSide) {
String transportIn = (String) configContext //TODO verify
.getProperty(MessageContext.TRANSPORT_IN);
if (transportIn == null)
transportIn = org.apache.axis2.Constants.TRANSPORT_HTTP;
} else if (acksTo == null && serverSide) {
String incomingSequencId = SandeshaUtil.getServerSideIncomingSeqIdFromInternalSeqId(internalSequenceId);
SequencePropertyBean bean = seqPropMgr.retrieve(
incomingSequencId,Sandesha2Constants.SequenceProperties.REPLY_TO_EPR);
if (bean != null) {
EndpointReference acksToEPR = new EndpointReference(bean.getValue());
if (acksToEPR != null)
acksTo = (String) acksToEPR.getAddress();
}
} else if (anonymousURI.equals(acksTo)) {
// set transport in.