public static void addTerminateSequenceMessage(RMMsgContext referenceMessage, String internalSequenceID, String outSequenceId, StorageManager storageManager) throws AxisFault {
if(log.isDebugEnabled())
log.debug("Enter: TerminateManager::addTerminateSequenceMessage " + outSequenceId + ", " + internalSequenceID);
RMSBean rmsBean = SandeshaUtil.getRMSBeanFromInternalSequenceId(storageManager, internalSequenceID);
if (rmsBean.isTerminateAdded()) {
if(log.isDebugEnabled())
log.debug("Exit: TerminateManager::addTerminateSequenceMessage - terminate was added previously.");
return;
}
RMMsgContext terminateRMMessage = RMMsgCreator.createTerminateSequenceMessage(referenceMessage, rmsBean, storageManager);
terminateRMMessage.setFlow(MessageContext.OUT_FLOW);
terminateRMMessage.setProperty(Sandesha2Constants.APPLICATION_PROCESSING_DONE, "true");
//setting the To EPR.
//First try to get it from an Endpoint property.
//If not get it from the To property.
EndpointReference toEPR = null;
if (rmsBean.getOfferedEndPoint() != null)
toEPR = new EndpointReference (rmsBean.getOfferedEndPoint());
if (toEPR==null) {
if (rmsBean.getToEPR()!=null) {
toEPR = new EndpointReference(rmsBean.getToEPR());
if (toEPR == null) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.toEPRNotValid, null);
throw new SandeshaException(message);
}
}
}
if (toEPR!=null)
terminateRMMessage.setTo(toEPR);
if (rmsBean.getReplyToEPR()!=null) {
terminateRMMessage.setReplyTo(new EndpointReference (rmsBean.getReplyToEPR()));
}
String rmVersion = rmsBean.getRMVersion();
terminateRMMessage.setWSAAction(SpecSpecificConstants.getTerminateSequenceAction(rmVersion));
terminateRMMessage.setSOAPAction(SpecSpecificConstants.getTerminateSequenceSOAPAction(rmVersion));
if (rmsBean.getTransportTo() != null) {
terminateRMMessage.setProperty(Constants.Configuration.TRANSPORT_URL, rmsBean.getTransportTo());
}
terminateRMMessage.addSOAPEnvelope();
String key = SandeshaUtil.getUUID();
SenderBean terminateBean = new SenderBean();
terminateBean.setInternalSequenceID(internalSequenceID);
terminateBean.setSequenceID(outSequenceId);
terminateBean.setMessageContextRefKey(key);
terminateBean.setMessageType(Sandesha2Constants.MessageTypes.TERMINATE_SEQ);
// 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(terminateRMMessage.getMessageId());
// this will be set to true at the sender.
terminateBean.setSend(true);
terminateRMMessage.getMessageContext().setProperty(Sandesha2Constants.QUALIFIED_FOR_SENDING,
Sandesha2Constants.VALUE_FALSE);
terminateBean.setReSend(false);
terminateBean.setSequenceID(outSequenceId);
terminateBean.setMessageType(Sandesha2Constants.MessageTypes.TERMINATE_SEQ);
terminateBean.setInternalSequenceID(internalSequenceID);
EndpointReference to = terminateRMMessage.getTo();
if (to!=null)
terminateBean.setToAddress(to.getAddress());
// If this message is targetted at an anonymous address then we must not have a transport
// ready for it, as the terminate sequence is not a reply.
if(to == null || to.hasAnonymousAddress())
terminateBean.setTransportAvailable(false);
rmsBean.setTerminateAdded(true);
storageManager.getRMSBeanMgr().update(rmsBean);
terminateRMMessage.setProperty(Sandesha2Constants.SET_SEND_TO_TRUE, Sandesha2Constants.VALUE_TRUE);