Options options = msgContext.getOptions();
StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configurationContext,
configurationContext.getAxisConfiguration());
SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropertyBeanMgr();
String toAddress = rmMsgCtx.getTo().getAddress();
String sequenceKey = (String) options.getProperty(SandeshaClientConstants.SEQUENCE_KEY);
String internalSeqenceID = SandeshaUtil.getInternalSequenceID(toAddress, sequenceKey);
String outSequenceID = SandeshaUtil.getSequenceProperty(internalSeqenceID,
Sandesha2Constants.SequenceProperties.OUT_SEQUENCE_ID, storageManager);
if (outSequenceID == null)
throw new SandeshaException(SandeshaMessageHelper.getMessage(
SandeshaMessageKeys.couldNotSendTerminateSeqNotFound, internalSeqenceID));
// / Transaction addTerminateSeqTransaction =
// storageManager.getTransaction();
String terminated = SandeshaUtil.getSequenceProperty(outSequenceID,
Sandesha2Constants.SequenceProperties.TERMINATE_ADDED, storageManager);
// registring an InOutOperationContext for this.
// since the serviceContext.fireAndForget only sets a inOnly One
// this does not work when there is a terminateSequnceResponse
// TODO do processing of terminateMessagesCorrectly., create a new
// message instead of sendign the one given by the serviceClient
// TODO important
AxisOperation outInAxisOp = new OutInAxisOperation(new QName("temp"));
AxisOperation referenceInOutOperation = msgContext.getAxisService()
.getOperation(
new QName(Sandesha2Constants.RM_IN_OUT_OPERATION_NAME));
if (referenceInOutOperation == null) {
String messge = "Cant find the recerence RM InOut operation";
throw new SandeshaException(messge);
}
outInAxisOp.setParent(msgContext.getAxisService());
// setting flows
// outInAxisOp.setRemainingPhasesInFlow(referenceInOutOperation.getRemainingPhasesInFlow());
outInAxisOp.setRemainingPhasesInFlow(referenceInOutOperation
.getRemainingPhasesInFlow());
outInAxisOp.setMessageReceiver(new RMMessageReceiver ());
OperationContext opcontext = OperationContextFactory
.createOperationContext(
WSDL20_2004Constants.MEP_CONSTANT_OUT_IN, outInAxisOp);
opcontext.setParent(msgContext.getServiceContext());
configurationContext.registerOperationContext(rmMsgCtx.getMessageId(),
opcontext);
msgContext.setOperationContext(opcontext);
msgContext.setAxisOperation(outInAxisOp);
if (terminated != null && "true".equals(terminated)) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.terminateAddedPreviously);
log.debug(message);
return false;
}
TerminateSequence terminateSequencePart = (TerminateSequence) rmMsgCtx
.getMessagePart(Sandesha2Constants.MessageParts.TERMINATE_SEQ);
terminateSequencePart.getIdentifier().setIndentifer(outSequenceID);
rmMsgCtx.setFlow(MessageContext.OUT_FLOW);
msgContext.setProperty(Sandesha2Constants.APPLICATION_PROCESSING_DONE, "true");
rmMsgCtx.setTo(new EndpointReference(toAddress));
String rmVersion = SandeshaUtil.getRMVersion(internalSeqenceID, storageManager);
if (rmVersion == null)
throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotDecideRMVersion));
rmMsgCtx.setWSAAction(SpecSpecificConstants.getTerminateSequenceAction(rmVersion));
rmMsgCtx.setSOAPAction(SpecSpecificConstants.getTerminateSequenceSOAPAction(rmVersion));
String transportTo = SandeshaUtil.getSequenceProperty(internalSeqenceID,
Sandesha2Constants.SequenceProperties.TRANSPORT_TO, storageManager);
if (transportTo != null) {
rmMsgCtx.setProperty(MessageContextConstants.TRANSPORT_URL, transportTo);
}
//setting msg context properties
rmMsgCtx.setProperty(Sandesha2Constants.MessageContextProperties.SEQUENCE_ID, outSequenceID);
rmMsgCtx.setProperty(Sandesha2Constants.MessageContextProperties.INTERNAL_SEQUENCE_ID, internalSeqenceID);
rmMsgCtx.setProperty(Sandesha2Constants.MessageContextProperties.SEQUENCE_PROPERTY_KEY , sequenceKey);
try {
rmMsgCtx.addSOAPEnvelope();
} catch (AxisFault e) {
throw new SandeshaException(e.getMessage(),e);
}
String key = SandeshaUtil.getUUID();
SenderBean terminateBean = new SenderBean();
terminateBean.setMessageContextRefKey(key);
storageManager.storeMessageContext(key, msgContext);
// Set a retransmitter lastSentTime so that terminate will be send with
// some delay.
// Otherwise this get send before return of the current request (ack).
// TODO: refine the terminate delay.
terminateBean.setTimeToSend(System.currentTimeMillis() + Sandesha2Constants.TERMINATE_DELAY);
terminateBean.setMessageID(msgContext.getMessageID());
EndpointReference to = msgContext.getTo();
if (to!=null)
terminateBean.setToAddress(to.getAddress());
// this will be set to true at the sender.
terminateBean.setSend(true);
msgContext.setProperty(Sandesha2Constants.QUALIFIED_FOR_SENDING, Sandesha2Constants.VALUE_FALSE);
terminateBean.setReSend(false);
SenderBeanMgr senderBeanMgr = storageManager.getSenderBeanMgr();
senderBeanMgr.insert(terminateBean);
SequencePropertyBean terminateAdded = new SequencePropertyBean();
terminateAdded.setName(Sandesha2Constants.SequenceProperties.TERMINATE_ADDED);
terminateAdded.setSequencePropertyKey(outSequenceID);
terminateAdded.setValue("true");
seqPropMgr.insert(terminateAdded);
rmMsgCtx.setProperty(Sandesha2Constants.SET_SEND_TO_TRUE, Sandesha2Constants.VALUE_TRUE);
SandeshaUtil.executeAndStore(rmMsgCtx, key);