throw new SandeshaException ("Invalid create sequence message. RelatesTo part is not available");
}
String createSeqMsgId = relatesTo.getValue();
SenderBeanMgr retransmitterMgr = storageManager
.getRetransmitterBeanMgr();
CreateSeqBeanMgr createSeqMgr = storageManager.getCreateSeqBeanMgr();
CreateSeqBean createSeqBean = createSeqMgr.retrieve(createSeqMsgId);
if (createSeqBean == null) {
String message = "Create Sequence entry is not found";
log.debug(message);
throw new SandeshaException(message);
}
String internalSequenceId = createSeqBean.getInternalSequenceID();
if (internalSequenceId == null || "".equals(internalSequenceId)) {
String message = "TempSequenceId has is not set";
log.debug(message);
throw new SandeshaException(message);
}
createSeqBean.setSequenceID(newOutSequenceId);
createSeqMgr.update(createSeqBean);
//deleting the create sequence entry.
retransmitterMgr.delete(createSeqMsgId);
//storing new out sequence id
SequencePropertyBeanMgr sequencePropMgr = storageManager
.getSequencePropretyBeanMgr();
SequencePropertyBean outSequenceBean = new SequencePropertyBean(
internalSequenceId, Sandesha2Constants.SequenceProperties.OUT_SEQUENCE_ID,
newOutSequenceId);
SequencePropertyBean internalSequenceBean = new SequencePropertyBean(
newOutSequenceId,
Sandesha2Constants.SequenceProperties.INTERNAL_SEQUENCE_ID, internalSequenceId);
sequencePropMgr.insert(outSequenceBean);
sequencePropMgr.insert(internalSequenceBean);
createSeqResponseTransaction.commit();
Transaction offerProcessTransaction = storageManager.getTransaction();
//processing for accept (offer has been sent)
Accept accept = createSeqResponsePart.getAccept();
if (accept != null) {
//Find offered sequence from internal sequence id.
SequencePropertyBean offeredSequenceBean = sequencePropMgr
.retrieve(internalSequenceId,
Sandesha2Constants.SequenceProperties.OFFERED_SEQUENCE);
//TODO this should be detected in the Fault manager.
if (offeredSequenceBean == null) {
String message = "No offered sequence entry. But an accept was received";
log.debug(message);
throw new SandeshaException(message);
}
String offeredSequenceId = (String) offeredSequenceBean.getValue();
EndpointReference acksToEPR = accept.getAcksTo().getAddress()
.getEpr();
SequencePropertyBean acksToBean = new SequencePropertyBean();
acksToBean.setName(Sandesha2Constants.SequenceProperties.ACKS_TO_EPR);
acksToBean.setSequenceID(offeredSequenceId);
acksToBean.setValue(acksToEPR.getAddress());
sequencePropMgr.insert(acksToBean);
NextMsgBean nextMsgBean = new NextMsgBean();
nextMsgBean.setSequenceID(offeredSequenceId);
nextMsgBean.setNextMsgNoToProcess(1);
NextMsgBeanMgr nextMsgMgr = storageManager.getNextMsgBeanMgr();
nextMsgMgr.insert(nextMsgBean);
String rmSpecVersion = createSeqResponseRMMsgCtx.getRMSpecVersion();
SequencePropertyBean specVersionBean = new SequencePropertyBean (
offeredSequenceId,Sandesha2Constants.SequenceProperties.RM_SPEC_VERSION,rmSpecVersion);
sequencePropMgr.insert(specVersionBean);
SequencePropertyBean receivedMsgBean = new SequencePropertyBean(
offeredSequenceId, Sandesha2Constants.SequenceProperties.SERVER_COMPLETED_MESSAGES, "");
sequencePropMgr.insert(receivedMsgBean);
SequencePropertyBean msgsBean = new SequencePropertyBean();
msgsBean.setSequenceID(offeredSequenceId);
msgsBean.setName(Sandesha2Constants.SequenceProperties.CLIENT_COMPLETED_MESSAGES);
msgsBean.setValue("");
sequencePropMgr.insert(msgsBean);
//setting the addressing version.
String addressingNamespace = createSeqResponseRMMsgCtx.getAddressingNamespaceValue();
SequencePropertyBean addressingVersionBean = new SequencePropertyBean (
offeredSequenceId,Sandesha2Constants.SequenceProperties.ADDRESSING_NAMESPACE_VALUE,addressingNamespace);
sequencePropMgr.insert(addressingVersionBean);
}
offerProcessTransaction.commit();
Transaction updateAppMessagesTransaction = storageManager.getTransaction();
SenderBean target = new SenderBean();
target.setInternalSequenceID(internalSequenceId);
target.setSend(false);
target.setReSend(true);
Iterator iterator = retransmitterMgr.find(target).iterator();
while (iterator.hasNext()) {
SenderBean tempBean = (SenderBean) iterator.next();
//updating the application message
String key = tempBean.getMessageContextRefKey();
MessageContext applicationMsg = storageManager.retrieveMessageContext(key,configCtx);
//TODO make following exception message more understandable to the user (probably some others exceptions messages as well)
if (applicationMsg==null)
throw new SandeshaException ("Unavailable application message");
String rmVersion = SandeshaUtil.getRMVersion(internalSequenceId,configCtx);
if (rmVersion==null)
throw new SandeshaException ("Cant find the rmVersion of the given message");
String assumedRMNamespace = SpecSpecificConstants.getRMNamespaceValue(rmVersion);
RMMsgContext applicaionRMMsg = MsgInitializer
.initializeMessage(applicationMsg);
Sequence sequencePart = (Sequence) applicaionRMMsg
.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
if (sequencePart == null) {
String message = "Sequence part is null";
log.debug(message);
throw new SandeshaException(message);
}
Identifier identifier = new Identifier(factory,assumedRMNamespace);
identifier.setIndentifer(newOutSequenceId);
sequencePart.setIdentifier(identifier);
AckRequested ackRequestedPart = (AckRequested) applicaionRMMsg
.getMessagePart(Sandesha2Constants.MessageParts.ACK_REQUEST);
if (ackRequestedPart != null) {
Identifier id1 = new Identifier(factory,assumedRMNamespace);
id1.setIndentifer(newOutSequenceId);
ackRequestedPart.setIdentifier(id1);
}
try {
applicaionRMMsg.addSOAPEnvelope();
} catch (AxisFault e) {
throw new SandeshaException(e.getMessage());
}
//asking to send the application msssage
tempBean.setSend(true);
retransmitterMgr.update(tempBean);
//updating the message. this will correct the SOAP envelope string.
storageManager.updateMessageContext(key,applicationMsg);
}