OperationContext createSeqOpCtx = createSeqmsgContext.getOperationContext();
String createSeqMsgId = SandeshaUtil.getUUID();
createSeqmsgContext.setMessageID(createSeqMsgId);
context.registerOperationContext(createSeqMsgId, createSeqOpCtx);
RMMsgContext createSeqRMMsg = new RMMsgContext(createSeqmsgContext);
String rmNamespaceValue = SpecSpecificConstants.getRMNamespaceValue(rmsBean.getRMVersion());
// Decide which addressing version to use. We copy the version that the application
// is already using (if set), and fall back to the level in the spec if that isn't
// found.
String addressingNamespace = (String) applicationMsgContext.getProperty(AddressingConstants.WS_ADDRESSING_VERSION);
Boolean disableAddressing = (Boolean) applicationMsgContext.getProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES);
if(addressingNamespace == null) {
// Addressing may still be enabled, as it defaults to the final spec. The only time
// we follow the RM spec is when addressing has been explicitly disabled.
if(disableAddressing != null && disableAddressing.booleanValue())
addressingNamespace = SpecSpecificConstants.getAddressingNamespace(rmNamespaceValue);
else
addressingNamespace = AddressingConstants.Final.WSA_NAMESPACE;
}
// If acksTo has not been set, then default to anonymous, using the correct spec level
EndpointReference acksToEPR = null;
String acksToAddress = rmsBean.getAcksToEPR();
if(acksToAddress != null) {
acksToEPR = new EndpointReference(acksToAddress);
} else {
acksToEPR = new EndpointReference(SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespace));
}
CreateSequence createSequencePart = new CreateSequence(rmNamespaceValue);
// Check if this service includes 2-way operations
boolean twoWayService = false;
AxisService service = applicationMsgContext.getAxisService();
if(service != null) {
Parameter p = service.getParameter(Sandesha2Constants.SERVICE_CONTAINS_OUT_IN_MEPS);
if(p != null && p.getValue() != null) {
twoWayService = ((Boolean) p.getValue()).booleanValue();
}
}
// Adding sequence offer - if present. We send an offer if the client has assigned an
// id, or if we are using WS-RM 1.0 and the service contains out-in MEPs
boolean autoOffer = false;
if(Sandesha2Constants.SPEC_2005_02.NS_URI.equals(rmNamespaceValue)) {
autoOffer = twoWayService;
} else {
// We also do some checking at this point to see if MakeConection is required to
// enable WS-RM 1.1, and write a warning to the log if it has been disabled.
SandeshaPolicyBean policy = SandeshaUtil.getPropertyBean(context.getAxisConfiguration());
if(twoWayService && !policy.isEnableMakeConnection()) {
String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.makeConnectionWarning);
log.warn(message);
}
}
String offeredSequenceId = (String) applicationMsgContext.getProperty(SandeshaClientConstants.OFFERED_SEQUENCE_ID);
if(autoOffer ||
(offeredSequenceId != null && offeredSequenceId.length() > 0)) {
if (offeredSequenceId == null || offeredSequenceId.length() == 0) {
offeredSequenceId = SandeshaUtil.getUUID();
}
SequenceOffer offerPart = new SequenceOffer(rmNamespaceValue);
Identifier identifier = new Identifier(rmNamespaceValue);
identifier.setIndentifer(offeredSequenceId);
offerPart.setIdentifier(identifier);
createSequencePart.setSequenceOffer(offerPart);
if (Sandesha2Constants.SPEC_2007_02.NS_URI.equals(rmNamespaceValue)) {
// We are going to send an offer, so decide which endpoint to include
EndpointReference offeredEndpoint = (EndpointReference) applicationMsgContext.getProperty(SandeshaClientConstants.OFFERED_ENDPOINT);
if (offeredEndpoint==null) {
EndpointReference replyTo = applicationMsgContext.getReplyTo(); //using replyTo as the Endpoint if it is not specified
if (replyTo!=null) {
offeredEndpoint = SandeshaUtil.cloneEPR(replyTo);
}
}
// Finally fall back to using an anonymous endpoint
if (offeredEndpoint==null) {
offeredEndpoint = new EndpointReference(SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespace));
}
Endpoint endpoint = new Endpoint (offeredEndpoint, rmNamespaceValue, addressingNamespace);
offerPart.setEndpoint(endpoint);
}
}
String to = rmsBean.getToEPR();
String replyTo = rmsBean.getReplyToEPR();
if (to == null) {
String message = SandeshaMessageHelper
.getMessage(SandeshaMessageKeys.toBeanNotSet);
throw new SandeshaException(message);
}
// TODO store and retrieve a full EPR instead of just the address.
EndpointReference toEPR = new EndpointReference(to);
createSeqRMMsg.setTo(toEPR);
if(replyTo != null) {
EndpointReference replyToEPR = new EndpointReference(replyTo);
createSeqRMMsg.setReplyTo(replyToEPR);
}
AcksTo acksTo = new AcksTo(acksToEPR, rmNamespaceValue, addressingNamespace);
createSequencePart.setAcksTo(acksTo);
createSeqRMMsg.setMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ, createSequencePart);
// Find the token that should be used to secure this new sequence. If there is a token, then we
// save it in the properties so that the caller can store the token within the create sequence
// bean.
SecurityManager secMgr = SandeshaUtil.getSecurityManager(context);
SecurityToken token = secMgr.getSecurityToken(applicationMsgContext);
if(token != null) {
OMElement str = secMgr.createSecurityTokenReference(token, createSeqmsgContext);
createSequencePart.setSecurityTokenReference(str);
createSeqRMMsg.setProperty(Sandesha2Constants.MessageContextProperties.SECURITY_TOKEN, token);
// If we are using token based security, and the 1.1 spec level, then we
// should introduce a UsesSequenceSTR header into the message.
if(createSequencePart.getNamespaceValue().equals(Sandesha2Constants.SPEC_2007_02.NS_URI)) {
UsesSequenceSTR header = new UsesSequenceSTR(null, Sandesha2Constants.SPEC_2007_02.NS_URI);
header.toSOAPEnvelope(createSeqmsgContext.getEnvelope());
}
// Ensure that the correct token will be used to secure the outbound create sequence message.
// We cannot use the normal helper method as we have not stored the token into the sequence bean yet.
secMgr.applySecurityToken(token, createSeqRMMsg.getMessageContext());
}
createSeqRMMsg.setAction(SpecSpecificConstants.getCreateSequenceAction(rmsBean.getRMVersion()));
createSeqRMMsg.setSOAPAction(SpecSpecificConstants.getCreateSequenceSOAPAction(rmsBean.getRMVersion()));
createSeqRMMsg.addSOAPEnvelope();
return createSeqRMMsg;
}