You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by da...@apache.org on 2007/02/23 15:25:43 UTC
svn commit: r510952 -
/webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java
Author: davidillsley
Date: Fri Feb 23 06:25:42 2007
New Revision: 510952
URL: http://svn.apache.org/viewvc?view=rev&rev=510952
Log:
Refactor of AddressingOutHandler to allow cleaner, simpler
code and access to relevant variables.
Modified:
webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java
Modified: webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java?view=diff&rev=510952&r1=510951&r2=510952
==============================================================================
--- webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java (original)
+++ webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java Fri Feb 23 06:25:42 2007
@@ -74,21 +74,19 @@
public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
// it should be able to disable addressing by some one.
- Object property = msgContext.getProperty(DISABLE_ADDRESSING_FOR_OUT_MESSAGES);
- if (JavaUtils.isTrueExplicitly(property)) {
- log.debug(msgContext.getLogIDString()+" Addressing is disabled .....");
+ if (Utils.isExplicitlyTrue(msgContext, DISABLE_ADDRESSING_FOR_OUT_MESSAGES)) {
+ if(log.isTraceEnabled()){
+ log.trace(msgContext.getLogIDString()+" Addressing is disabled. Not adding WS-Addressing headers.");
+ }
return InvocationResponse.CONTINUE;
}
-
+
// Determine the addressin namespace in effect.
Object addressingVersionFromCurrentMsgCtxt = msgContext.getProperty(WS_ADDRESSING_VERSION);
- boolean isFinalAddressingNamespace = true;
- String namespace = Final.WSA_NAMESPACE;
-
- if (Submission.WSA_NAMESPACE.equals(addressingVersionFromCurrentMsgCtxt)) {
- isFinalAddressingNamespace = false;
- namespace = Submission.WSA_NAMESPACE;
- }
+ if(log.isTraceEnabled()){
+ log.trace("Addressing version string from messageContext="+addressingVersionFromCurrentMsgCtxt);
+ }
+ boolean isFinalAddressingNamespace = Final.WSA_NAMESPACE.equals(addressingVersionFromCurrentMsgCtxt);
// Determine whether to include optional addressing headers in the output.
boolean includeOptionalHeaders = this.includeOptionalHeaders;
@@ -99,397 +97,423 @@
// Determine if a MustUnderstand attribute will be added to all headers in the
// addressing namespace.
- Object mustUnderstandProperty = msgContext.getProperty(AddressingConstants.ADD_MUST_UNDERSTAND_TO_ADDRESSING_HEADERS);
- boolean addMustUnderstandAttribute = JavaUtils.isTrueExplicitly(mustUnderstandProperty);
+ boolean addMustUnderstandAttribute = Utils.isExplicitlyTrue(msgContext, ADD_MUST_UNDERSTAND_TO_ADDRESSING_HEADERS);
// what if there are addressing headers already in the message. Do you replace that or not?
// Lets have a parameter to control that. The default behavior is you won't replace addressing
// headers if there are any (this was the case so far).
- Object replaceHeadersProperty = msgContext.getProperty(REPLACE_ADDRESSING_HEADERS);
- boolean replaceHeaders = JavaUtils.isTrueExplicitly(replaceHeadersProperty);
-
- SOAPFactory factory = (SOAPFactory) msgContext.getEnvelope().getOMFactory();
- OMNamespace addressingNamespaceObject = factory.createOMNamespace(namespace, WSA_DEFAULT_PREFIX);
-
- Options messageContextOptions = msgContext.getOptions();
- SOAPEnvelope envelope = msgContext.getEnvelope();
- SOAPHeader soapHeader = envelope.getHeader();
-
- // if there is no soap header in the envelope being processed, add one.
- if (soapHeader == null) {
- soapHeader = factory.createSOAPHeader(envelope);
- }
+ boolean replaceHeaders = Utils.isExplicitlyTrue(msgContext, REPLACE_ADDRESSING_HEADERS);
- // by this time, we definitely have some addressing information to be sent. This is because,
- // we have tested at the start of this whether messageInformationHeaders are null or not.
- // So rather than declaring addressing namespace in each and every addressing header, lets
- // define that in the Header itself.
- envelope.declareNamespace(addressingNamespaceObject);
+ WSAHeaderWriter writer = new WSAHeaderWriter(msgContext, isFinalAddressingNamespace, addMustUnderstandAttribute, replaceHeaders, includeOptionalHeaders);
+ writer.writeHeaders();
+
+ return InvocationResponse.CONTINUE;
+ }
- // processing WSA To
- processToEPR(messageContextOptions, envelope, addressingNamespaceObject, replaceHeaders, isFinalAddressingNamespace, includeOptionalHeaders);
+ private class WSAHeaderWriter{
+
+ private final Log log = LogFactory.getLog(AddressingOutHandler.class);
+
+ private MessageContext messageContext;
+ private SOAPEnvelope envelope;
+ private SOAPHeader header;
+ private SOAPFactory factory;
+ private Options messageContextOptions;
+ private OMNamespace addressingNamespaceObject;
+ private String addressingNamespace;
+
+ private boolean isFinalAddressingNamespace;
+ private boolean addMustUnderstandAttribute;
+ private boolean replaceHeaders; // determines whether we replace the existing headers or not, if they present
+ private boolean includeOptionalHeaders;
+
+ public WSAHeaderWriter(MessageContext mc, boolean isFinal, boolean addMU, boolean replace, boolean includeOptional) {
+ if(log.isDebugEnabled()){
+ log.debug("WSAHeaderWriter: isFinal="+isFinal+" addMU="+addMU+" replace="+replace+" includeOptional="+includeOptional);
+ }
+
+ messageContext = mc;
+ envelope = mc.getEnvelope();
+ factory = (SOAPFactory)envelope.getOMFactory();
+
+ header = envelope.getHeader();
+
+ // if there is no soap header in the envelope being processed, add one.
+ if (header == null) {
+ header = factory.createSOAPHeader(envelope);
+ }
+
+ messageContextOptions = messageContext.getOptions();
+
+ addressingNamespace = (isFinal?Final.WSA_NAMESPACE:Submission.WSA_NAMESPACE);
+ addressingNamespaceObject = factory.createOMNamespace(addressingNamespace, WSA_DEFAULT_PREFIX);
- // processing WSA replyTo
- processReplyTo(envelope, messageContextOptions, msgContext, addressingNamespaceObject, replaceHeaders, isFinalAddressingNamespace, includeOptionalHeaders);
-
- // processing WSA From
- processFromEPR(messageContextOptions, envelope, addressingNamespaceObject, replaceHeaders, isFinalAddressingNamespace, includeOptionalHeaders);
+ isFinalAddressingNamespace = isFinal;
+ addMustUnderstandAttribute = addMU;
+ replaceHeaders = replace;
+ includeOptionalHeaders = includeOptional;
+ }
+
+ public void writeHeaders() throws AxisFault{
+
+ // by this time, we definitely have some addressing information to be sent. This is because,
+ // we have tested at the start of this whether messageInformationHeaders are null or not.
+ // So rather than declaring addressing namespace in each and every addressing header, lets
+ // define that in the Header itself.
+ envelope.declareNamespace(addressingNamespaceObject);
- // processing WSA FaultTo
- processFaultToEPR(messageContextOptions, envelope, addressingNamespaceObject, replaceHeaders, isFinalAddressingNamespace, includeOptionalHeaders);
+ // processing WSA To
+ processToEPR();
- // processing WSA MessageID
- processMessageID(messageContextOptions, envelope, msgContext, addressingNamespaceObject, replaceHeaders, isFinalAddressingNamespace);
+ // processing WSA replyTo
+ processReplyTo();
+
+ // processing WSA From
+ processFromEPR();
- // processing WSA Action
- processWSAAction(messageContextOptions, envelope, msgContext, addressingNamespaceObject, replaceHeaders, isFinalAddressingNamespace);
+ // processing WSA FaultTo
+ processFaultToEPR();
- // processing WSA RelatesTo
- processRelatesTo(envelope, messageContextOptions, addressingNamespaceObject, replaceHeaders, isFinalAddressingNamespace, includeOptionalHeaders);
+ // processing WSA MessageID
+ processMessageID();
- // process fault headers, if present
- processFaultsInfoIfPresent(envelope, msgContext, addressingNamespaceObject, replaceHeaders, isFinalAddressingNamespace);
-
- // process mustUnderstand attribute, if required.
- processMustUnderstandProperty(envelope, msgContext, addressingNamespaceObject, addMustUnderstandAttribute);
-
- return InvocationResponse.CONTINUE;
- }
+ // processing WSA Action
+ processWSAAction();
- private void processMessageID(Options messageContextOptions, SOAPEnvelope envelope, MessageContext msgContext, OMNamespace addressingNamespaceObject, boolean replaceHeaders, boolean isFinalAddressingNamespace) {
- String messageID = messageContextOptions.getMessageId();
- if (messageID != null && !isAddressingHeaderAlreadyAvailable(WSA_MESSAGE_ID, envelope,
- addressingNamespaceObject, replaceHeaders, false)) {//optional
- OMElement oe = processStringInfo(messageID, WSA_MESSAGE_ID, envelope, addressingNamespaceObject);
- ArrayList attributes = (ArrayList)messageContextOptions.getProperty(AddressingConstants.MESSAGEID_ATTRIBUTES);
- if(attributes!= null && !attributes.isEmpty()){
- Iterator attrIterator = attributes.iterator();
- while(attrIterator.hasNext()){
- AttributeHelper.importOMAttribute((OMAttribute)attrIterator.next(), oe);
- }
- }
- }
- }
+ // processing WSA RelatesTo
+ processRelatesTo();
- private void processWSAAction(Options messageContextOptions, SOAPEnvelope envelope,
- MessageContext msgCtxt, OMNamespace addressingNamespaceObject, boolean replaceHeaders, boolean isFinalAddressingNamespace) throws AxisFault {
- String action = messageContextOptions.getAction();
-
- if(log.isTraceEnabled()){
- log.trace(msgCtxt.getLogIDString()+" processWSAAction: action from messageContext: "+action);
- }
- if(action == null || "".equals(action)){
- if(msgCtxt.getAxisOperation()!=null){
- action = msgCtxt.getAxisOperation().getOutputAction();
- if(log.isTraceEnabled()){
- log.trace(msgCtxt.getLogIDString()+" processWSAAction: action from AxisOperation: "+action);
+ // process fault headers, if present
+ processFaultsInfoIfPresent();
+
+ // process mustUnderstand attribute, if required.
+ processMustUnderstandProperty();
+ }
+
+
+ private void processMessageID() {
+ String messageID = messageContextOptions.getMessageId();
+ if (messageID != null && !isAddressingHeaderAlreadyAvailable(WSA_MESSAGE_ID, false)) {//optional
+ OMElement oe = processStringInfo(messageID, WSA_MESSAGE_ID);
+ ArrayList attributes = (ArrayList)messageContextOptions.getProperty(AddressingConstants.MESSAGEID_ATTRIBUTES);
+ if(attributes!= null && !attributes.isEmpty()){
+ Iterator attrIterator = attributes.iterator();
+ while(attrIterator.hasNext()){
+ AttributeHelper.importOMAttribute((OMAttribute)attrIterator.next(), oe);
+ }
}
}
}
-
- // Use the correct fault action for the selected namespace
- if (Final.WSA_FAULT_ACTION.equals(action) || Submission.WSA_FAULT_ACTION.equals(action)) {
- action = isFinalAddressingNamespace ? Final.WSA_FAULT_ACTION : Submission.WSA_FAULT_ACTION;
- messageContextOptions.setAction(action);
- }
- else if (!isFinalAddressingNamespace && Final.WSA_SOAP_FAULT_ACTION.equals(action)) {
- action = Submission.WSA_FAULT_ACTION;
- messageContextOptions.setAction(action);
- }
- // If we need to add a wsa:Action header
- if(!isAddressingHeaderAlreadyAvailable(WSA_ACTION, envelope,
- addressingNamespaceObject, replaceHeaders, false)){
+ private void processWSAAction() throws AxisFault {
+ String action = messageContextOptions.getAction();
+
if(log.isTraceEnabled()){
- log.trace(msgCtxt.getLogIDString()+" processWSAAction: No existing wsa:Action header found");
+ log.trace(messageContext.getLogIDString()+" processWSAAction: action from messageContext: "+action);
}
- // If we don't have an action to add,
if(action == null || "".equals(action)){
- if(log.isTraceEnabled()){
- log.trace(msgCtxt.getLogIDString()+" processWSAAction: No action to add to header");
- }
- // Fault unless validation has been explictily turned off
- if(!Utils.isExplicitlyTrue(msgCtxt, AddressingConstants.DISABLE_OUTBOUND_ADDRESSING_VALIDATION)){
- throw new AxisFault(AddressingMessages.getMessage("outboundNoAction"));
+ if(messageContext.getAxisOperation()!=null){
+ action = messageContext.getAxisOperation().getOutputAction();
+ if(log.isTraceEnabled()){
+ log.trace(messageContext.getLogIDString()+" processWSAAction: action from AxisOperation: "+action);
+ }
}
- }else{
+ }
+
+ // Use the correct fault action for the selected namespace
+ if (Final.WSA_FAULT_ACTION.equals(action) || Submission.WSA_FAULT_ACTION.equals(action)) {
+ action = isFinalAddressingNamespace ? Final.WSA_FAULT_ACTION : Submission.WSA_FAULT_ACTION;
+ messageContextOptions.setAction(action);
+ }
+ else if (!isFinalAddressingNamespace && Final.WSA_SOAP_FAULT_ACTION.equals(action)) {
+ action = Submission.WSA_FAULT_ACTION;
+ messageContextOptions.setAction(action);
+ }
+
+ // If we need to add a wsa:Action header
+ if(!isAddressingHeaderAlreadyAvailable(WSA_ACTION, false)){
if(log.isTraceEnabled()){
- log.trace(msgCtxt.getLogIDString()+" processWSAAction: Adding action to header: "+action);
+ log.trace(messageContext.getLogIDString()+" processWSAAction: No existing wsa:Action header found");
}
- // Otherwise just add the header
- OMElement oe = processStringInfo(action, WSA_ACTION, envelope, addressingNamespaceObject);
- ArrayList attributes = (ArrayList)messageContextOptions.getProperty(AddressingConstants.ACTION_ATTRIBUTES);
- if(attributes!= null && !attributes.isEmpty()){
- Iterator attrIterator = attributes.iterator();
- while(attrIterator.hasNext()){
- AttributeHelper.importOMAttribute((OMAttribute)attrIterator.next(), oe);
+ // If we don't have an action to add,
+ if(action == null || "".equals(action)){
+ if(log.isTraceEnabled()){
+ log.trace(messageContext.getLogIDString()+" processWSAAction: No action to add to header");
+ }
+ // Fault unless validation has been explictily turned off
+ if(!Utils.isExplicitlyTrue(messageContext, AddressingConstants.DISABLE_OUTBOUND_ADDRESSING_VALIDATION)){
+ throw new AxisFault(AddressingMessages.getMessage("outboundNoAction"));
+ }
+ }else{
+ if(log.isTraceEnabled()){
+ log.trace(messageContext.getLogIDString()+" processWSAAction: Adding action to header: "+action);
+ }
+ // Otherwise just add the header
+ OMElement oe = processStringInfo(action, WSA_ACTION);
+ ArrayList attributes = (ArrayList)messageContextOptions.getProperty(AddressingConstants.ACTION_ATTRIBUTES);
+ if(attributes!= null && !attributes.isEmpty()){
+ Iterator attrIterator = attributes.iterator();
+ while(attrIterator.hasNext()){
+ AttributeHelper.importOMAttribute((OMAttribute)attrIterator.next(), oe);
+ }
}
}
}
}
- }
- private void processFaultsInfoIfPresent(SOAPEnvelope envelope, MessageContext msgContext, OMNamespace addressingNamespaceObject, boolean replaceHeaders, boolean isFinalAddressingNamespace) {
- OMElement detailElement = AddressingFaultsHelper.getDetailElementForAddressingFault(msgContext, addressingNamespaceObject);
- if(detailElement != null){
- //The difference between SOAP 1.1 and SOAP 1.2 fault messages is explained in the WS-Addressing Specs.
- if(isFinalAddressingNamespace && msgContext.isSOAP11()){
- // Add detail as a wsa:FaultDetail header
- if (!isAddressingHeaderAlreadyAvailable(Final.FAULT_HEADER_DETAIL, envelope, addressingNamespaceObject, replaceHeaders, false)) {
- SOAPHeaderBlock faultDetail = envelope.getHeader().addHeaderBlock(Final.FAULT_HEADER_DETAIL, addressingNamespaceObject);
- faultDetail.addChild(ElementHelper.importOMElement(detailElement, envelope.getOMFactory()));
- }
- }
- else if (!msgContext.isSOAP11()) {
- // Add detail to the Fault in the SOAP Body
- SOAPFault fault = envelope.getBody().getFault();
- if (fault != null && fault.getDetail() != null) {
- fault.getDetail().addDetailEntry(ElementHelper.importOMElement(detailElement, envelope.getOMFactory()));
+ private void processFaultsInfoIfPresent() {
+ OMElement detailElement = AddressingFaultsHelper.getDetailElementForAddressingFault(messageContext, addressingNamespaceObject);
+ if(detailElement != null){
+ //The difference between SOAP 1.1 and SOAP 1.2 fault messages is explained in the WS-Addressing Specs.
+ if(isFinalAddressingNamespace && messageContext.isSOAP11()){
+ // Add detail as a wsa:FaultDetail header
+ if (!isAddressingHeaderAlreadyAvailable(Final.FAULT_HEADER_DETAIL, false)) {
+ SOAPHeaderBlock faultDetail = header.addHeaderBlock(Final.FAULT_HEADER_DETAIL, addressingNamespaceObject);
+ faultDetail.addChild(ElementHelper.importOMElement(detailElement, factory));
+ }
+ }
+ else if (!messageContext.isSOAP11()) {
+ // Add detail to the Fault in the SOAP Body
+ SOAPFault fault = envelope.getBody().getFault();
+ if (fault != null && fault.getDetail() != null) {
+ fault.getDetail().addDetailEntry(ElementHelper.importOMElement(detailElement, factory));
+ }
}
}
}
- }
- private void processRelatesTo(SOAPEnvelope envelope, Options messageContextOptions, OMNamespace addressingNamespaceObject, boolean replaceHeaders, boolean isFinalAddressingNamespace, boolean includeOptionalHeaders) {
- if (!isAddressingHeaderAlreadyAvailable(WSA_RELATES_TO, envelope, addressingNamespaceObject, replaceHeaders, true))
- {
- RelatesTo[] relatesTo = messageContextOptions.getRelationships();
-
- if (relatesTo != null) {
- for (int i = 0, length = relatesTo.length; i < length; i++) {
- OMElement relatesToHeader = processStringInfo(relatesTo[i].getValue(),
- WSA_RELATES_TO, envelope, addressingNamespaceObject);
- String relationshipType = relatesTo[i].getRelationshipType();
-
- if (relatesToHeader != null) {
- if(relatesTo[i].getExtensibilityAttributes() != null){
- Iterator attributes = relatesTo[i].getExtensibilityAttributes().iterator();
- while(attributes.hasNext()){
- OMAttribute oma = (OMAttribute)attributes.next();
- AttributeHelper.importOMAttribute(oma, relatesToHeader);
- }
- }
-
- if (Final.WSA_DEFAULT_RELATIONSHIP_TYPE.equals(relationshipType) ||
- Submission.WSA_DEFAULT_RELATIONSHIP_TYPE.equals(relationshipType)) {
- if (includeOptionalHeaders) {
- relationshipType = isFinalAddressingNamespace ?
- Final.WSA_DEFAULT_RELATIONSHIP_TYPE : Submission.WSA_DEFAULT_RELATIONSHIP_TYPE;
- relatesTo[i].setRelationshipType(relationshipType);
+ private void processRelatesTo() {
+ if (!isAddressingHeaderAlreadyAvailable(WSA_RELATES_TO, true))
+ {
+ RelatesTo[] relatesTo = messageContextOptions.getRelationships();
+
+ if (relatesTo != null) {
+ for (int i = 0, length = relatesTo.length; i < length; i++) {
+ OMElement relatesToHeader = processStringInfo(relatesTo[i].getValue(),
+ WSA_RELATES_TO);
+ String relationshipType = relatesTo[i].getRelationshipType();
+
+ if (relatesToHeader != null) {
+ if(relatesTo[i].getExtensibilityAttributes() != null){
+ Iterator attributes = relatesTo[i].getExtensibilityAttributes().iterator();
+ while(attributes.hasNext()){
+ OMAttribute oma = (OMAttribute)attributes.next();
+ AttributeHelper.importOMAttribute(oma, relatesToHeader);
+ }
}
- else {
- continue; //Omit the relationship type
+
+ if (Final.WSA_DEFAULT_RELATIONSHIP_TYPE.equals(relationshipType) ||
+ Submission.WSA_DEFAULT_RELATIONSHIP_TYPE.equals(relationshipType)) {
+ if (includeOptionalHeaders) {
+ relationshipType = isFinalAddressingNamespace ?
+ Final.WSA_DEFAULT_RELATIONSHIP_TYPE : Submission.WSA_DEFAULT_RELATIONSHIP_TYPE;
+ relatesTo[i].setRelationshipType(relationshipType);
+ }
+ else {
+ continue; //Omit the relationship type
+ }
}
+
+ relatesToHeader.addAttribute(WSA_RELATES_TO_RELATIONSHIP_TYPE,
+ relationshipType,
+ null);
}
-
- relatesToHeader.addAttribute(WSA_RELATES_TO_RELATIONSHIP_TYPE,
- relationshipType,
- null);
}
}
}
}
- }
- private void processFaultToEPR(Options messageContextOptions, SOAPEnvelope envelope, OMNamespace addressingNamespaceObject, boolean replaceHeaders, boolean isFinalAddressingNamespace, boolean includeOptionalHeaders) throws AxisFault {
- EndpointReference epr = messageContextOptions.getFaultTo();
- String headerName = AddressingConstants.WSA_FAULT_TO;
-
- //Omit the header if the epr is null.
- if (epr != null && !isAddressingHeaderAlreadyAvailable(headerName, envelope, addressingNamespaceObject, replaceHeaders, false)) {
- addToSOAPHeader(epr, headerName, envelope, addressingNamespaceObject, replaceHeaders, isFinalAddressingNamespace, includeOptionalHeaders);
+ private void processFaultToEPR() throws AxisFault {
+ EndpointReference epr = messageContextOptions.getFaultTo();
+ String headerName = AddressingConstants.WSA_FAULT_TO;
+
+ //Omit the header if the epr is null.
+ if (epr != null && !isAddressingHeaderAlreadyAvailable(headerName, false)) {
+ addToSOAPHeader(epr, headerName);
+ }
}
- }
- private void processFromEPR(Options messageContextOptions, SOAPEnvelope envelope, OMNamespace addressingNamespaceObject, boolean replaceHeaders, boolean isFinalAddressingNamespace, boolean includeOptionalHeaders) throws AxisFault {
- EndpointReference epr = messageContextOptions.getFrom();
- String headerName = AddressingConstants.WSA_FROM;
-
- //Omit the header if the epr is null.
- if (epr != null && !isAddressingHeaderAlreadyAvailable(headerName, envelope, addressingNamespaceObject, replaceHeaders, false)) {
- addToSOAPHeader(epr, headerName, envelope, addressingNamespaceObject, replaceHeaders, isFinalAddressingNamespace, includeOptionalHeaders);
+ private void processFromEPR() throws AxisFault {
+ EndpointReference epr = messageContextOptions.getFrom();
+ String headerName = AddressingConstants.WSA_FROM;
+
+ //Omit the header if the epr is null.
+ if (epr != null && !isAddressingHeaderAlreadyAvailable(headerName, false)) {
+ addToSOAPHeader(epr, headerName);
+ }
}
- }
- private void processReplyTo(SOAPEnvelope envelope, Options messageContextOptions, MessageContext msgContext, OMNamespace addressingNamespaceObject, boolean replaceHeaders, boolean isFinalAddressingNamespace, boolean includeOptionalHeaders) throws AxisFault {
- EndpointReference epr = messageContextOptions.getReplyTo();
- String headerName = AddressingConstants.WSA_REPLY_TO;
-
- //Don't check epr for null here as addToSOAPHeader() will provide an appropriate default.
- //This default is especially useful for client side outbound processing.
- if (!isAddressingHeaderAlreadyAvailable(headerName, envelope, addressingNamespaceObject, replaceHeaders, false)) {
- addToSOAPHeader(epr, headerName, envelope, addressingNamespaceObject, replaceHeaders, isFinalAddressingNamespace, includeOptionalHeaders);
+ private void processReplyTo() throws AxisFault {
+ EndpointReference epr = messageContextOptions.getReplyTo();
+ String headerName = AddressingConstants.WSA_REPLY_TO;
+
+ //Don't check epr for null here as addToSOAPHeader() will provide an appropriate default.
+ //This default is especially useful for client side outbound processing.
+ if (!isAddressingHeaderAlreadyAvailable(headerName, false)) {
+ addToSOAPHeader(epr, headerName);
+ }
}
- }
- private void processToEPR(Options messageContextOptions, SOAPEnvelope envelope, OMNamespace addressingNamespaceObject, boolean replaceHeaders, boolean isFinalAddressingNamespace, boolean includeOptionalHeaders) {
- EndpointReference epr = messageContextOptions.getTo();
- if (epr != null && !isAddressingHeaderAlreadyAvailable(WSA_TO, envelope, addressingNamespaceObject, replaceHeaders, false))
- {
- Map referenceParameters = epr.getAllReferenceParameters();
- String address = epr.getAddress();
-
- if (!"".equals(address) && address != null) {
- if (!includeOptionalHeaders && isFinalAddressingNamespace &&
- (Final.WSA_ANONYMOUS_URL.equals(address) || //Don't use epr.hasAnonymousAddress() here as it may
- Submission.WSA_ANONYMOUS_URL.equals(address))) { //recognize none WS-Addressing anonymous values.
- return; //Omit the header.
- }
-
- SOAPHeaderBlock toHeaderBlock = envelope.getHeader().addHeaderBlock(WSA_TO, addressingNamespaceObject);
- toHeaderBlock.setText(address);
- if(epr.getAddressAttributes() != null){
- Iterator addressAttributes = epr.getAddressAttributes().iterator();
- while(addressAttributes.hasNext()){
- OMAttribute attr = (OMAttribute)addressAttributes.next();
- AttributeHelper.importOMAttribute(attr, toHeaderBlock);
+ private void processToEPR() {
+ EndpointReference epr = messageContextOptions.getTo();
+ if (epr != null && !isAddressingHeaderAlreadyAvailable(WSA_TO, false))
+ {
+ Map referenceParameters = epr.getAllReferenceParameters();
+ String address = epr.getAddress();
+
+ if (!"".equals(address) && address != null) {
+ if (!includeOptionalHeaders && isFinalAddressingNamespace &&
+ (Final.WSA_ANONYMOUS_URL.equals(address) || //Don't use epr.hasAnonymousAddress() here as it may
+ Submission.WSA_ANONYMOUS_URL.equals(address))) { //recognize none WS-Addressing anonymous values.
+ return; //Omit the header.
+ }
+
+ SOAPHeaderBlock toHeaderBlock = header.addHeaderBlock(WSA_TO, addressingNamespaceObject);
+ toHeaderBlock.setText(address);
+ if(epr.getAddressAttributes() != null){
+ Iterator addressAttributes = epr.getAddressAttributes().iterator();
+ while(addressAttributes.hasNext()){
+ OMAttribute attr = (OMAttribute)addressAttributes.next();
+ AttributeHelper.importOMAttribute(attr, toHeaderBlock);
+ }
}
}
+ processToEPRReferenceInformation(referenceParameters, header);
}
- processToEPRReferenceInformation(referenceParameters, envelope.getHeader(), addressingNamespaceObject, isFinalAddressingNamespace);
}
- }
-
- private OMElement processStringInfo(String value,
- String headerName,
- SOAPEnvelope soapEnvelope, OMNamespace addressingNamespaceObject) {
- if (!"".equals(value) && value != null) {
- SOAPHeaderBlock soapHeaderBlock =
- soapEnvelope.getHeader().addHeaderBlock(headerName, addressingNamespaceObject);
- soapHeaderBlock.addChild(
- soapEnvelope.getOMFactory().createOMText(value));
- return soapHeaderBlock;
+ private OMElement processStringInfo(String value, String headerName) {
+ if(log.isTraceEnabled()){
+ log.trace("processStringInfo: value="+value+" headerName="+headerName);
+ }
+ if (!"".equals(value) && value != null) {
+ SOAPHeaderBlock soapHeaderBlock =
+ header.addHeaderBlock(headerName, addressingNamespaceObject);
+ soapHeaderBlock.addChild(factory.createOMText(value));
+ return soapHeaderBlock;
+ }
+ return null;
}
- return null;
- }
- private void addToSOAPHeader(EndpointReference epr,
- String headerName,
- SOAPEnvelope envelope, OMNamespace addressingNamespaceObject, boolean replaceHeaders, boolean isFinalAddressingNamespace, boolean includeOptionalHeaders) throws AxisFault {
- String namespace = addressingNamespaceObject.getNamespaceURI();
- String prefix = addressingNamespaceObject.getPrefix();
- String anonymous = isFinalAddressingNamespace ?
- Final.WSA_ANONYMOUS_URL : Submission.WSA_ANONYMOUS_URL;
+ private void addToSOAPHeader(EndpointReference epr, String headerName) throws AxisFault {
+ String prefix = addressingNamespaceObject.getPrefix();
+ String anonymous = isFinalAddressingNamespace ?
+ Final.WSA_ANONYMOUS_URL : Submission.WSA_ANONYMOUS_URL;
- if(log.isTraceEnabled()){
- log.trace("addToSOAPHeader: epr="+epr+" headerName="+headerName);
- }
-
- if (epr == null) {
- if (!includeOptionalHeaders && isFinalAddressingNamespace &&
- AddressingConstants.WSA_REPLY_TO.equals(headerName)) {
- return; //Omit the header.
- }
- else {
- epr = new EndpointReference(anonymous);
+ if(log.isTraceEnabled()){
+ log.trace("addToSOAPHeader: epr="+epr+" headerName="+headerName);
}
- }
- else if (!isFinalAddressingNamespace && epr.hasNoneAddress()) {
- return; //Omit the header.
- }
- else if (Final.WSA_ANONYMOUS_URL.equals(epr.getAddress()) || //Don't use epr.hasAnonymousAddress() here as it may
- Submission.WSA_ANONYMOUS_URL.equals(epr.getAddress())) { //recognize none WS-Addressing anonymous values.
- if (!includeOptionalHeaders && isFinalAddressingNamespace &&
- AddressingConstants.WSA_REPLY_TO.equals(headerName)) {
- return; //Omit the header.
+ if (epr == null) {
+ if (!includeOptionalHeaders && isFinalAddressingNamespace &&
+ AddressingConstants.WSA_REPLY_TO.equals(headerName)) {
+ return; //Omit the header.
+ }
+ else {
+ epr = new EndpointReference(anonymous);
+ }
}
- else {
- epr.setAddress(anonymous);
+ else if (!isFinalAddressingNamespace && epr.hasNoneAddress()) {
+ return; //Omit the header.
}
- }
-
- OMElement soapHeaderBlock = EndpointReferenceHelper.toOM(envelope.getOMFactory(),
- epr,
- new QName(namespace, headerName, prefix), namespace);
- envelope.getHeader().addChild(soapHeaderBlock);
- }
-
- /**
- * This will add reference parameters and/or reference properties in to the message
- *
- * @param referenceInformation
- */
- private void processToEPRReferenceInformation(Map referenceInformation, OMElement parent, OMNamespace addressingNamespaceObject, boolean isFinalAddressingNamespace) {
- if (referenceInformation != null && parent != null) {
- Iterator iterator = referenceInformation.keySet().iterator();
- while (iterator.hasNext()) {
- QName key = (QName) iterator.next();
- OMElement omElement = (OMElement) referenceInformation.get(key);
- parent.addChild(ElementHelper.importOMElement(omElement, parent.getOMFactory()));
-
- if (isFinalAddressingNamespace) {
- omElement.addAttribute(Final.WSA_IS_REFERENCE_PARAMETER_ATTRIBUTE, Final.WSA_TYPE_ATTRIBUTE_VALUE,
- addressingNamespaceObject);
+ else if (Final.WSA_ANONYMOUS_URL.equals(epr.getAddress()) || //Don't use epr.hasAnonymousAddress() here as it may
+ Submission.WSA_ANONYMOUS_URL.equals(epr.getAddress())) { //recognize none WS-Addressing anonymous values.
+
+ if (!includeOptionalHeaders && isFinalAddressingNamespace &&
+ AddressingConstants.WSA_REPLY_TO.equals(headerName)) {
+ return; //Omit the header.
+ } else {
+ epr.setAddress(anonymous);
}
}
- }
- }
-
- /**
- * This will check for the existence of message information headers already in the message. If there are already headers,
- * then replacing them or not depends on the replaceHeaders property.
- *
- * @param name - Name of the message information header
- * @param envelope
- * @param addressingNamespaceObject - namespace object of addressing representing the addressing version being used
- * @param replaceHeaders - determines whether we replace the existing headers or not, if they present
- * @param multipleHeaders - determines whether to search for multiple headers, or not.
- * @return false - if one can add new headers (always the case if multipleHeaders is true),
- * true - if new headers can't be added.
- */
- private boolean isAddressingHeaderAlreadyAvailable(String name, SOAPEnvelope envelope, OMNamespace addressingNamespaceObject, boolean replaceHeaders, boolean multipleHeaders) {
- QName qname = new QName(addressingNamespaceObject.getNamespaceURI(), name, addressingNamespaceObject.getPrefix());
- boolean status = false;
-
- if (multipleHeaders) {
- if (replaceHeaders) {
- Iterator iterator = envelope.getHeader().getChildrenWithName(qname);
+ OMElement soapHeaderBlock = EndpointReferenceHelper.toOM(factory,
+ epr,
+ new QName(addressingNamespace, headerName, prefix), addressingNamespace);
+ header.addChild(soapHeaderBlock);
+ }
+
+ /**
+ * This will add reference parameters and/or reference properties in to the message
+ *
+ * @param referenceInformation
+ * @param parent is the element to which the referenceparameters should be attached
+ */
+ private void processToEPRReferenceInformation(Map referenceInformation, OMElement parent) {
+ if (referenceInformation != null && parent != null) {
+ Iterator iterator = referenceInformation.keySet().iterator();
while (iterator.hasNext()) {
- OMElement addressingHeader = (OMElement) iterator.next();
- addressingHeader.detach();
+ QName key = (QName) iterator.next();
+ OMElement omElement = (OMElement) referenceInformation.get(key);
+ parent.addChild(ElementHelper.importOMElement(omElement, parent.getOMFactory()));
+
+ if (isFinalAddressingNamespace) {
+ omElement.addAttribute(Final.WSA_IS_REFERENCE_PARAMETER_ATTRIBUTE, Final.WSA_TYPE_ATTRIBUTE_VALUE,
+ addressingNamespaceObject);
+ }
}
}
}
- else {
- OMElement addressingHeader = envelope.getHeader().getFirstChildWithName(qname);
-
- if (addressingHeader != null && replaceHeaders) {
- if(log.isTraceEnabled()){
- log.trace("isAddressingHeaderAlreadyAvailable: Removing existing header:"+addressingHeader.getLocalName());
- }
- addressingHeader.detach();
+
+ /**
+ * This will check for the existence of message information headers already in the message. If there are already headers,
+ * then replacing them or not depends on the replaceHeaders property.
+ *
+ * @param name - Name of the message information header
+ * @param multipleHeaders - determines whether to search for multiple headers, or not.
+ * @return false - if one can add new headers (always the case if multipleHeaders is true),
+ * true - if new headers can't be added.
+ */
+ private boolean isAddressingHeaderAlreadyAvailable(String name, boolean multipleHeaders) {
+ QName qname = new QName(addressingNamespaceObject.getNamespaceURI(), name, addressingNamespaceObject.getPrefix());
+ boolean status = false;
+
+ if (multipleHeaders) {
+ if (replaceHeaders) {
+ Iterator iterator = header.getChildrenWithName(qname);
+ while (iterator.hasNext()) {
+ OMElement addressingHeader = (OMElement) iterator.next();
+ addressingHeader.detach();
+ }
+ }
}
else {
- status = addressingHeader != null;
+ OMElement addressingHeader = header.getFirstChildWithName(qname);
+
+ if (addressingHeader != null && replaceHeaders) {
+ if(log.isTraceEnabled()){
+ log.trace("isAddressingHeaderAlreadyAvailable: Removing existing header:"+addressingHeader.getLocalName());
+ }
+ addressingHeader.detach();
+ } else {
+ status = addressingHeader != null;
+ }
}
- }
- return status;
- }
-
- /**
- * Sets a mustUnderstand attribute on all headers that are found with the appropriate
- * addressing namespace.
- *
- * @param envelope
- * @param msgContext
- * @param addressingNamespaceObject
- */
- private void processMustUnderstandProperty(SOAPEnvelope envelope, MessageContext msgContext, OMNamespace addressingNamespaceObject, boolean addMustUnderstandAttribute) {
- if (addMustUnderstandAttribute) {
- List headers = envelope.getHeader().getHeaderBlocksWithNSURI(addressingNamespaceObject.getNamespaceURI());
-
- for (int i = 0, size = headers.size(); i < size; i++) {
- SOAPHeaderBlock soapHeaderBlock = (SOAPHeaderBlock) headers.get(i);
- soapHeaderBlock.setMustUnderstand(true);
- if(log.isTraceEnabled()){
- log.trace("processMustUnderstandProperty: Setting mustUnderstand=true on: "+soapHeaderBlock.getLocalName());
- }
+ if(log.isTraceEnabled()){
+ log.trace("isAddressingHeaderAlreadyAvailable: name="+name+" status="+status);
+ }
+ return status;
+ }
+
+ /**
+ * Sets a mustUnderstand attribute on all headers that are found with the appropriate
+ * addressing namespace.
+ */
+ private void processMustUnderstandProperty() {
+ if (addMustUnderstandAttribute) {
+ List headers = header.getHeaderBlocksWithNSURI(addressingNamespace);
+
+ for (int i = 0, size = headers.size(); i < size; i++) {
+ SOAPHeaderBlock soapHeaderBlock = (SOAPHeaderBlock) headers.get(i);
+ soapHeaderBlock.setMustUnderstand(true);
+ if(log.isTraceEnabled()){
+ log.trace("processMustUnderstandProperty: Setting mustUnderstand=true on: "+soapHeaderBlock.getLocalName());
+ }
+ }
}
}
}
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org