StorageManager storageManager = SandeshaUtil
.getSandeshaStorageManager(msg.getConfigurationContext());
SequencePropertyBeanMgr sequencePropertyMgr = storageManager
.getSequencePropretyBeanMgr();
SenderBeanMgr retransmitterMgr = storageManager
.getRetransmitterBeanMgr();
SequencePropertyBean toBean = sequencePropertyMgr.retrieve(
internalSequenceId, Sandesha2Constants.SequenceProperties.TO_EPR);
SequencePropertyBean replyToBean = sequencePropertyMgr.retrieve(
internalSequenceId, Sandesha2Constants.SequenceProperties.REPLY_TO_EPR);
//again - looks weird in the client side - but consistent
SequencePropertyBean outSequenceBean = sequencePropertyMgr.retrieve(
internalSequenceId,
Sandesha2Constants.SequenceProperties.OUT_SEQUENCE_ID);
if (toBean == null)
throw new SandeshaException("To is null");
EndpointReference toEPR = (EndpointReference) toBean.getValue();
EndpointReference replyToEPR = null;
if (replyToBean != null) {
replyToEPR = (EndpointReference) replyToBean.getValue();
}
if (toEPR == null || toEPR.getAddress() == null
|| toEPR.getAddress() == "")
throw new SandeshaException("To Property has an invalid value");
String newToStr = null;
if (msg.isServerSide()) {
try {
MessageContext requestMsg = msg.getOperationContext()
.getMessageContext(
OperationContextFactory.MESSAGE_LABEL_IN_VALUE);
if (requestMsg != null) {
newToStr = requestMsg.getReplyTo().getAddress();
}
} catch (AxisFault e) {
throw new SandeshaException(e.getMessage());
}
}
if (newToStr != null)
rmMsg.setTo(new EndpointReference(newToStr));
else
rmMsg.setTo(toEPR);
if (replyToEPR != null)
rmMsg.setReplyTo(replyToEPR);
Sequence sequence = new Sequence(factory);
MessageNumber msgNumber = new MessageNumber(factory);
msgNumber.setMessageNumber(messageNumber);
sequence.setMessageNumber(msgNumber);
boolean lastMessage = false;
//setting last message
if (msg.isServerSide()) {
//server side
String incomingSeqId = internalSequenceId;
MessageContext requestMsg = null;
try {
requestMsg = msg.getOperationContext().getMessageContext(
WSDLConstants.MESSAGE_LABEL_IN_VALUE);
} catch (AxisFault e) {
throw new SandeshaException(e.getMessage());
}
RMMsgContext reqRMMsgCtx = MsgInitializer
.initializeMessage(requestMsg);
Sequence requestSequence = (Sequence) reqRMMsgCtx
.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
if (requestSequence == null)
throw new SandeshaException("Request Sequence is null");
if (requestSequence.getLastMessage() != null) {
lastMessage = true;
sequence.setLastMessage(new LastMessage(factory));
//saving the last message no.
SequencePropertyBean lastOutMsgBean = new SequencePropertyBean(
internalSequenceId,
Sandesha2Constants.SequenceProperties.LAST_OUT_MESSAGE,
new Long(messageNumber));
sequencePropertyMgr.insert(lastOutMsgBean);
}
} else {
//client side
OperationContext operationContext = msg.getOperationContext();
if (operationContext != null) {
Object obj = msg.getProperty(Sandesha2ClientAPI.LAST_MESSAGE);
if (obj != null && "true".equals(obj)) {
lastMessage = true;
sequence.setLastMessage(new LastMessage(factory));
//saving the last message no.
SequencePropertyBean lastOutMsgBean = new SequencePropertyBean(
internalSequenceId,
Sandesha2Constants.SequenceProperties.LAST_OUT_MESSAGE,
new Long(messageNumber));
sequencePropertyMgr.insert(lastOutMsgBean);
}
}
}
AckRequested ackRequested = null;
boolean addAckRequested = false;
if (!lastMessage)
addAckRequested = true;
//setting the Sequnece id.
//Set send = true/false depending on the availability of the out
// sequence id.
String identifierStr = null;
if (outSequenceBean == null || outSequenceBean.getValue() == null) {
identifierStr = Sandesha2Constants.TEMP_SEQUENCE_ID;
} else {
identifierStr = (String) outSequenceBean.getValue();
}
Identifier id1 = new Identifier(factory);
id1.setIndentifer(identifierStr);
sequence.setIdentifier(id1);
rmMsg.setMessagePart(Sandesha2Constants.MessageParts.SEQUENCE, sequence);
if (addAckRequested) {
ackRequested = new AckRequested(factory);
Identifier id2 = new Identifier(factory);
id2.setIndentifer(identifierStr);
ackRequested.setIdentifier(id2);
rmMsg.setMessagePart(Sandesha2Constants.MessageParts.ACK_REQUEST,
ackRequested);
}
try {
rmMsg.addSOAPEnvelope();
} catch (AxisFault e1) {
throw new SandeshaException(e1.getMessage());
}
//Retransmitter bean entry for the application message
SenderBean appMsgEntry = new SenderBean();
String key = SandeshaUtil
.storeMessageContext(rmMsg.getMessageContext());
appMsgEntry.setKey(key);
appMsgEntry.setTimeToSend(System.currentTimeMillis());
appMsgEntry.setMessageId(rmMsg.getMessageId());
appMsgEntry.setMessageNumber(messageNumber);
if (outSequenceBean == null || outSequenceBean.getValue() == null) {
appMsgEntry.setSend(false);
} else {
appMsgEntry.setSend(true);
}
appMsgEntry.setInternalSequenceId(internalSequenceId);
retransmitterMgr.insert(appMsgEntry);
}