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 ch...@apache.org on 2005/12/01 10:02:29 UTC

svn commit: r350212 - in /webservices/axis2/trunk/java/modules/addressing: src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java test/org/apache/axis2/handlers/addressing/AddressingOutHandlerTest.java

Author: chinthaka
Date: Thu Dec  1 01:02:03 2005
New Revision: 350212

URL: http://svn.apache.org/viewcvs?rev=350212&view=rev
Log:
Addressing handler was putting addressing information in to the OUT message, irrespective of whether there are some addressing headers or not. Fixed so that addressing will not make any duplicates in the OUT message.
Thanks Sanjiva for pointing that out.

Modified:
    webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java
    webservices/axis2/trunk/java/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingOutHandlerTest.java

Modified: webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java?rev=350212&r1=350211&r2=350212&view=diff
==============================================================================
--- 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 Thu Dec  1 01:02:03 2005
@@ -50,7 +50,6 @@
     String addressingNamespace;
 
 
-
     public void invoke(MessageContext msgContext) throws AxisFault {
 
 
@@ -60,13 +59,13 @@
 
         // first check whether current message context can be used to determin the addressing version to be used
         Object addressingVersionFromCurrentMsgCtxt = msgContext.getProperty(WS_ADDRESSING_VERSION);
-        if(addressingVersionFromCurrentMsgCtxt != null){
+        if (addressingVersionFromCurrentMsgCtxt != null) {
             // since we support only two addressing versions I can avoid multiple  ifs here.
             // see that if message context property holds something other than Final.WSA_NAMESPACE
             // we always defaults to Submission.WSA_NAMESPACE. Hope this is fine.
             addressingNamespace = Final.WSA_NAMESPACE.equals(addressingVersionFromCurrentMsgCtxt)
                     ? Final.WSA_NAMESPACE : Submission.WSA_NAMESPACE;
-        }else if (msgContext.getOperationContext() != null) { // check for a IN message context, else default to WSA Submission
+        } else if (msgContext.getOperationContext() != null) { // check for a IN message context, else default to WSA Submission
             MessageContext inMessageContext = msgContext.getOperationContext()
                     .getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
             if (inMessageContext == null) {
@@ -99,9 +98,9 @@
         // define that in the Header itself.
         soapHeader.declareNamespace(addressingNamespaceObject);
 
-
+        // processing WSA To
         EndpointReference epr = messageInformationHeaders.getTo();
-        if (epr != null) {
+        if (epr != null && !isAddressingHeaderAlreadyAvailable(WSA_TO, soapHeader)) {
 
             String address = epr.getAddress();
             if (!"".equals(address) && address != null) {
@@ -118,31 +117,34 @@
             addToHeader(epr, soapHeader);
         }
 
+        // processing WSA Action
         String action = messageInformationHeaders.getAction();
-        if (action != null) {
+        if (action != null && !isAddressingHeaderAlreadyAvailable(WSA_ACTION, soapHeader)) {
             processStringInfo(action, WSA_ACTION, soapHeader);
         }
 
-        epr = messageInformationHeaders.getReplyTo();
-        if (epr == null) {//optional
-            // setting anonymous URI. Defaulting to Final.
-            String anonymousURI = Final.WSA_ANONYMOUS_URL;
-            if (Submission.WSA_NAMESPACE.equals(addressingNamespace)) {
-                anonymousURI = Submission.WSA_ANONYMOUS_URL;                    
+        // processing WSA replyTo
+        if (!isAddressingHeaderAlreadyAvailable(WSA_REPLY_TO, soapHeader)) {
+            epr = messageInformationHeaders.getReplyTo();
+            if (epr == null) {//optional
+                // setting anonymous URI. Defaulting to Final.
+                String anonymousURI = Final.WSA_ANONYMOUS_URL;
+                if (Submission.WSA_NAMESPACE.equals(addressingNamespace)) {
+                    anonymousURI = Submission.WSA_ANONYMOUS_URL;
+                }
+                epr = new EndpointReference(anonymousURI);
             }
-            epr = new EndpointReference(anonymousURI);
-        }
-        // add the service group id as a reference parameter
-        String serviceGroupContextId = msgContext.getServiceGroupContextId();
-        if (serviceGroupContextId != null && !"".equals(serviceGroupContextId)) {
-            if(epr.getReferenceParameters() == null){
-                epr.setReferenceParameters(new AnyContentType());
+            // add the service group id as a reference parameter
+            String serviceGroupContextId = msgContext.getServiceGroupContextId();
+            if (serviceGroupContextId != null && !"".equals(serviceGroupContextId)) {
+                if (epr.getReferenceParameters() == null) {
+                    epr.setReferenceParameters(new AnyContentType());
+                }
+                epr.getReferenceParameters().addReferenceValue(new QName(Constants.AXIS2_NAMESPACE_URI,
+                        Constants.SERVICE_GROUP_ID, Constants.AXIS2_NAMESPACE_PREFIX), serviceGroupContextId);
             }
-            epr.getReferenceParameters().addReferenceValue(new QName(Constants.AXIS2_NAMESPACE_URI,
-                    Constants.SERVICE_GROUP_ID, Constants.AXIS2_NAMESPACE_PREFIX), serviceGroupContextId);
+            addToSOAPHeader(epr, AddressingConstants.WSA_REPLY_TO, soapHeader);
         }
-        addToSOAPHeader(epr, AddressingConstants.WSA_REPLY_TO, soapHeader);
-
 
         epr = messageInformationHeaders.getFrom();
         if (epr != null) {//optional
@@ -155,30 +157,32 @@
         }
 
         String messageID = messageInformationHeaders.getMessageId();
-        if (messageID != null) {//optional
+        if (messageID != null && !isAddressingHeaderAlreadyAvailable(WSA_MESSAGE_ID, soapHeader)) {//optional
             processStringInfo(messageID, WSA_MESSAGE_ID, soapHeader);
         }
 
-        org.apache.axis2.addressing.RelatesTo relatesTo = messageInformationHeaders.getRelatesTo();
-        OMElement relatesToHeader = null;
+        if (!isAddressingHeaderAlreadyAvailable(WSA_RELATES_TO, soapHeader)) {
+            org.apache.axis2.addressing.RelatesTo relatesTo = messageInformationHeaders.getRelatesTo();
+            OMElement relatesToHeader = null;
+
+            if (relatesTo != null) {
+                relatesToHeader =
+                        processStringInfo(relatesTo.getValue(),
+                                WSA_RELATES_TO,
+                                soapHeader);
+            }
 
-        if (relatesTo != null) {
-            relatesToHeader =
-                    processStringInfo(relatesTo.getValue(),
-                            WSA_RELATES_TO,
-                            soapHeader);
+            if (relatesToHeader != null)
+                if ("".equals(relatesTo.getRelationshipType())) {
+                    relatesToHeader.addAttribute(WSA_RELATES_TO_RELATIONSHIP_TYPE,
+                            Submission.WSA_RELATES_TO_RELATIONSHIP_TYPE_DEFAULT_VALUE,
+                            addressingNamespaceObject);
+                } else {
+                    relatesToHeader.addAttribute(WSA_RELATES_TO_RELATIONSHIP_TYPE,
+                            relatesTo.getRelationshipType(),
+                            addressingNamespaceObject);
+                }
         }
-
-        if (relatesToHeader != null)
-            if ("".equals(relatesTo.getRelationshipType())) {
-                relatesToHeader.addAttribute(WSA_RELATES_TO_RELATIONSHIP_TYPE,
-                        Submission.WSA_RELATES_TO_RELATIONSHIP_TYPE_DEFAULT_VALUE,
-                        addressingNamespaceObject);
-            } else {
-                relatesToHeader.addAttribute(WSA_RELATES_TO_RELATIONSHIP_TYPE,
-                        relatesTo.getRelationshipType(),
-                        addressingNamespaceObject);
-            }
     }
 
 
@@ -198,7 +202,7 @@
     protected void addToSOAPHeader(EndpointReference epr,
                                    String type,
                                    SOAPHeader soapHeader) {
-        if (epr == null) {
+        if (epr == null || isAddressingHeaderAlreadyAvailable(type, soapHeader)) {
             return;
         }
 
@@ -309,6 +313,10 @@
                 omElement.setText(value);
             }
         }
+    }
+
+    private boolean isAddressingHeaderAlreadyAvailable(String name, SOAPHeader soapHeader) {
+        return soapHeader.getFirstChildWithName(new QName(addressingNamespaceObject.getName(), name, addressingNamespaceObject.getPrefix())) != null;
     }
 }
 

Modified: webservices/axis2/trunk/java/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingOutHandlerTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingOutHandlerTest.java?rev=350212&r1=350211&r2=350212&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingOutHandlerTest.java (original)
+++ webservices/axis2/trunk/java/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingOutHandlerTest.java Thu Dec  1 01:02:03 2005
@@ -17,10 +17,10 @@
 package org.apache.axis2.handlers.addressing;
 
 import junit.framework.TestCase;
+import org.apache.axis2.AxisFault;
 import org.apache.axis2.addressing.AddressingConstants;
 import org.apache.axis2.addressing.AnyContentType;
 import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.addressing.MessageInformationHeaders;
 import org.apache.axis2.addressing.ServiceName;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.handlers.util.TestUtil;
@@ -144,5 +144,30 @@
                 xmlComparator.compare(msgCtxt.getEnvelope(),
                         testUtil.getOMBuilder("OutHandlerTest.xml")
                 .getDocumentElement()));
+    }
+
+    public void testDuplicateHeaders() throws AxisFault {
+
+        // this will check whether we can add to epr, if there is one already.
+        EndpointReference eprOne = new EndpointReference("http://whatever.org");
+        EndpointReference duplicateEpr = new EndpointReference("http://whatever.duplicate.org");
+        msgCtxt = new MessageContext(null);
+        SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
+        SOAPEnvelope defaultEnvelope = factory.getDefaultEnvelope();
+        msgCtxt.setEnvelope(defaultEnvelope);
+
+        msgCtxt.setTo(eprOne);
+        outHandler.invoke(msgCtxt);
+        System.out.println("defaultEnvelope = " + defaultEnvelope);
+
+        // now the soap message within the msgCtxt must have a to header.
+        // lets invoke twice and see
+        msgCtxt.setTo(duplicateEpr);
+        outHandler.invoke(msgCtxt);
+
+        System.out.println("defaultEnvelope = " + defaultEnvelope);
+        assertTrue(defaultEnvelope.getHeader().getFirstChildWithName(new QName("http://whatever.duplicate.org")) == null);
+
+
     }
 }