You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ch...@apache.org on 2005/11/02 11:05:21 UTC

svn commit: r330227 - in /webservices/axis2/trunk/java/modules: codegen/src/org/apache/axis2/databinding/utils/ core/src/org/apache/axis2/clientapi/ integration/test/org/apache/axis2/engine/ xml/src/org/apache/axis2/om/impl/llom/

Author: chinthaka
Date: Wed Nov  2 02:04:51 2005
New Revision: 330227

URL: http://svn.apache.org/viewcvs?rev=330227&view=rev
Log:
Adding a convenience method in MEPClient to add SOAP headers to the message.

Modified:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/utils/ADBPullParser.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/MEPClient.java
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/EchoRawXMLOnTwoChannelsTest.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/utils/ADBPullParser.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/utils/ADBPullParser.java?rev=330227&r1=330226&r2=330227&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/utils/ADBPullParser.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/utils/ADBPullParser.java Wed Nov  2 02:04:51 2005
@@ -156,10 +156,10 @@
      *                   <p/>
      *                                                                                                                                                                                                                         This is the how the passed array should look like
      *                                                                                                                                                                                                                                           Key             Value
-     *                                                                                                                                                                                                                                           String              String
-     *                                                                                                                                                                                                                                           QName               ADBBean, OMElement, Bean
-     *                                                                                                                                                                                                                                           String              String[]
-     *                                                                                                                                                                                                                                           QName               Object[] - this contains only one type of objects
+     *                                                                                                                                                                                                                                           String          String
+     *                                                                                                                                                                                                                                           QName           ADBBean, OMElement, Bean
+     *                                                                                                                                                                                                                                           String          String[]
+     *                                                                                                                                                                                                                                           QName           Object[] - this contains only one type of objects
      *                   <p/>
      *                   <p/>
      *                                                                                                                                                                                                                           This is how the passed attribute array should look like

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/MEPClient.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/MEPClient.java?rev=330227&r1=330226&r2=330227&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/MEPClient.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/clientapi/MEPClient.java Wed Nov  2 02:04:51 2005
@@ -30,8 +30,11 @@
 import org.apache.axis2.soap.SOAP12Constants;
 import org.apache.axis2.soap.SOAPEnvelope;
 import org.apache.axis2.soap.SOAPFactory;
+import org.apache.axis2.soap.SOAPHeader;
 
 import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * This is the Super Class for all the MEPClients, All the MEPClient will extend this.
@@ -43,6 +46,8 @@
     protected String soapAction = "";
     protected String wsaAction;
 
+    protected List soapHeaderList;
+
     /*
       If there is a SOAP Fault in the body of the incoming SOAP Message, system can be configured to
       throw an exception with the details extracted from the information from the fault message.
@@ -81,11 +86,35 @@
         //if operation not alrady added, add it
         if (serviceContext.getAxisService().getOperation(axisop.getName()) == null) {
             serviceContext.getAxisService().addOperation(axisop);
-        }        
+        }
         if (wsaAction != null) {
             msgCtx.setWSAAction(wsaAction);
         }
         msgCtx.setSoapAction(soapAction);
+
+        // check user has put any SOAPHeader using the call MEPClient methods and add them, if any, to the
+        // the SOAP message
+        addUserAddedSOAPHeaders(msgCtx);
+    }
+
+    private void addUserAddedSOAPHeaders(MessageContext msgCtx) {
+        if (soapHeaderList != null && soapHeaderList.size() > 0 && msgCtx.getEnvelope() != null) {
+            SOAPFactory soapFactory;
+            SOAPHeader header = msgCtx.getEnvelope().getHeader();
+            if (header == null) {
+                soapFactory = getCorrectSOAPFactory(msgCtx);
+                header = soapFactory.createSOAPHeader(msgCtx.getEnvelope());
+            }
+            if (!header.isComplete()) {
+                header.build();
+            }
+
+            for (int i = 0; i < soapHeaderList.size(); i++) {
+                OMElement headerBlock = (OMElement) soapHeaderList.get(i);
+                header.addChild(headerBlock);
+            }
+
+        }
     }
 
     /**
@@ -199,6 +228,24 @@
      */
     public void setExceptionToBeThrownOnSOAPFault(boolean exceptionToBeThrownOnSOAPFault) {
         isExceptionToBeThrownOnSOAPFault = exceptionToBeThrownOnSOAPFault;
+    }
+
+    public void addSOAPHeader(QName soapHeaderQName, String soapHeaderText) {
+        OMElement omElement = OMAbstractFactory.getOMFactory().createOMElement(soapHeaderQName, null);
+        omElement.setText(soapHeaderText);
+        if (soapHeaderList == null) {
+            soapHeaderList = new ArrayList();
+        }
+        soapHeaderList.add(omElement);
+    }
+
+    private SOAPFactory getCorrectSOAPFactory(MessageContext msgCtx) {
+        String soapNSURI = msgCtx.getEnvelope().getNamespace().getName();
+        if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapNSURI)) {
+            return OMAbstractFactory.getSOAP11Factory();
+        } else {
+            return OMAbstractFactory.getSOAP12Factory();
+        }
     }
 
 }

Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/EchoRawXMLOnTwoChannelsTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/EchoRawXMLOnTwoChannelsTest.java?rev=330227&r1=330226&r2=330227&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/EchoRawXMLOnTwoChannelsTest.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/EchoRawXMLOnTwoChannelsTest.java Wed Nov  2 02:04:51 2005
@@ -21,6 +21,7 @@
 import org.apache.axis2.Constants;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.clientapi.AsyncResult;
+import org.apache.axis2.clientapi.Call;
 import org.apache.axis2.clientapi.Callback;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.context.ServiceContext;
@@ -100,8 +101,8 @@
         value.setText("Isaac Assimov, the foundation Sega");
         method.addChild(value);
 
-        org.apache.axis2.clientapi.Call call =
-                new org.apache.axis2.clientapi.Call(
+        Call call =
+                new Call(
                 serviceContext);
         call.engageModule(new QName(Constants.MODULE_ADDRESSING));
 

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java?rev=330227&r1=330226&r2=330227&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java Wed Nov  2 02:04:51 2005
@@ -16,16 +16,7 @@
 
 package org.apache.axis2.om.impl.llom;
 
-import org.apache.axis2.om.OMAbstractFactory;
-import org.apache.axis2.om.OMAttribute;
-import org.apache.axis2.om.OMConstants;
-import org.apache.axis2.om.OMContainer;
-import org.apache.axis2.om.OMElement;
-import org.apache.axis2.om.OMException;
-import org.apache.axis2.om.OMNamespace;
-import org.apache.axis2.om.OMNode;
-import org.apache.axis2.om.OMText;
-import org.apache.axis2.om.OMXMLParserWrapper;
+import org.apache.axis2.om.*;
 import org.apache.axis2.om.impl.OMContainerEx;
 import org.apache.axis2.om.impl.OMNodeEx;
 import org.apache.axis2.om.impl.OMOutputImpl;
@@ -36,13 +27,12 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.io.ByteArrayOutputStream;
-import java.util.HashMap;
-import java.util.Iterator;
-
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
+import java.io.ByteArrayOutputStream;
+import java.util.HashMap;
+import java.util.Iterator;
 
 /**
  * Class OMElementImpl