in modules/core/src/main/java/org/apache/sandesha2/util/RMMsgCreator.java [90:261]
public static RMMsgContext createCreateSeqMsg(RMSBean rmsBean, RMMsgContext applicationRMMsg) throws AxisFault {
if(log.isDebugEnabled()) log.debug("Entry: RMMsgCreator::createCreateSeqMsg " + applicationRMMsg);
MessageContext applicationMsgContext = applicationRMMsg.getMessageContext();
if (applicationMsgContext == null)
throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.appMsgIsNull));
ConfigurationContext context = applicationMsgContext.getConfigurationContext();
if (context == null)
throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.configContextNotSet));
// creating by copying common contents. (this will not set contexts
// except for configCtx).
AxisOperation createSequenceOperation = SpecSpecificConstants.getWSRMOperation(
Sandesha2Constants.MessageTypes.CREATE_SEQ,
rmsBean.getRMVersion(),
applicationMsgContext.getAxisService());
MessageContext createSeqmsgContext = SandeshaUtil
.createNewRelatedMessageContext(applicationRMMsg, createSequenceOperation);
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(log.isDebugEnabled()) log.debug("RMMsgCreator:: addressing name space is " + addressingNamespace);
// If acksTo has not been set, then default to anonymous, using the correct spec level
EndpointReference acksToEPR = rmsBean.getAcksToEndpointReference();
if(acksToEPR == null){
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) {
// if the user has specified this sequence as a one way sequence it should not
// append the sequence offer.
if (!JavaUtils.isTrue(applicationMsgContext.getOptions().getProperty(
SandeshaClientConstants.ONE_WAY_SEQUENCE))) {
Parameter p = service.getParameter(Sandesha2Constants.SERVICE_CONTAINS_OUT_IN_MEPS);
if (p != null && p.getValue() != null) {
twoWayService = ((Boolean) p.getValue()).booleanValue();
if (log.isDebugEnabled()) log.debug("RMMsgCreator:: twoWayService " + twoWayService);
}
}
}
// Adding sequence offer - if present. We send an offer if the client has assigned an
// id, or if the service contains out-in MEPs
boolean autoOffer = twoWayService;
//There may not have been a way to confirm if an OUT_IN MEP is being used.
//Therefore doing an extra check to see what Axis is using. If it's OUT_IN then we must offer.
if(applicationMsgContext.getOperationContext() != null && applicationMsgContext.getOperationContext().getAxisOperation() != null){
if(applicationMsgContext.getOperationContext().getAxisOperation().getAxisSpecificMEPConstant() == org.apache.axis2.wsdl.WSDLConstants.MEP_CONSTANT_OUT_IN
|| applicationMsgContext.getOperationContext().getAxisOperation().getAxisSpecificMEPConstant() == org.apache.axis2.wsdl.WSDLConstants.MEP_CONSTANT_OUT_OPTIONAL_IN){
autoOffer = true;
}
}
// 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.
if(Sandesha2Constants.SPEC_2007_02.NS_URI.equals(rmNamespaceValue)) {
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);
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 the offeredEndpoint hasn't been set then use the acksTo of the RMSBean
if (offeredEndpoint==null) {
offeredEndpoint = rmsBean.getAcksToEndpointReference();
}
Endpoint endpoint = new Endpoint (offeredEndpoint, rmNamespaceValue, addressingNamespace);
offerPart.setEndpoint(endpoint);
}
createSequencePart.setSequenceOffer(offerPart);
}
EndpointReference toEPR = rmsBean.getToEndpointReference();
if (toEPR == null || toEPR.getAddress()==null) {
String message = SandeshaMessageHelper
.getMessage(SandeshaMessageKeys.toBeanNotSet);
throw new SandeshaException(message);
}
createSeqRMMsg.setTo(toEPR);
if(log.isDebugEnabled()) log.debug("RMMsgCreator:: toEPR=" + toEPR);
EndpointReference replyToEPR = rmsBean.getReplyToEndpointReference();
if(replyToEPR != null) {
replyToEPR = SandeshaUtil.getEPRDecorator(createSeqRMMsg.getConfigurationContext()).decorateEndpointReference(replyToEPR);
createSeqRMMsg.setReplyTo(replyToEPR);
if(log.isDebugEnabled()) log.debug("RMMsgCreator:: replyToEPR=" + replyToEPR);
}
AcksTo acksTo = new AcksTo(acksToEPR, rmNamespaceValue, addressingNamespace);
createSequencePart.setAcksTo(acksTo);
if(log.isDebugEnabled()) log.debug("RMMsgCreator:: acksTo=" + acksTo);
createSeqRMMsg.setCreateSequence(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 usesSeqStr = new UsesSequenceSTR();
usesSeqStr.toHeader(createSeqmsgContext.getEnvelope().getHeader());
}
// 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();
if(log.isDebugEnabled()) log.debug("Entry: RMMsgCreator::createCreateSeqMsg " + createSeqRMMsg);
return createSeqRMMsg;
}