axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chinth...@apache.org
Subject svn commit: r355879 - in /webservices/axis2/trunk/java/modules: addressing/src/org/apache/axis2/handlers/addressing/ saaj/src/javax/xml/soap/ saaj/src/org/apache/axis2/saaj/ saaj/src/org/apache/axis2/soap/impl/dom/ xml/src/org/apache/axis2/soap/ xml/sr...
Date Sun, 11 Dec 2005 03:01:33 GMT
Author: chinthaka
Date: Sat Dec 10 19:01:24 2005
New Revision: 355879

URL: http://svn.apache.org/viewcvs?rev=355879&view=rev
Log:
Fixing a NPE problem in AddressingOutHandler and improving the code (Thanks Paul and Saminda
for pointing out the bug and thanks Sanjiva for the tip to improve the code)

Modified:
    webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java
    webservices/axis2/trunk/java/modules/saaj/src/javax/xml/soap/SOAPEnvelope.java
    webservices/axis2/trunk/java/modules/saaj/src/javax/xml/soap/SOAPHeader.java
    webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPEnvelopeImpl.java
    webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/soap/impl/dom/SOAPEnvelopeImpl.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/SOAPEnvelope.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/SOAPEnvelopeImpl.java
    webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/soap/SOAPEnvelopeTest.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=355879&r1=355878&r2=355879&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
Sat Dec 10 19:01:24 2005
@@ -21,11 +21,13 @@
 import org.apache.axis2.addressing.AddressingConstants;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.addressing.MessageInformationHeaders;
+import org.apache.axis2.addressing.RelatesTo;
 import org.apache.axis2.addressing.ServiceName;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.om.OMAbstractFactory;
 import org.apache.axis2.om.OMElement;
 import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.soap.SOAPEnvelope;
 import org.apache.axis2.soap.SOAPHeader;
 import org.apache.axis2.soap.SOAPHeaderBlock;
 import org.apache.wsdl.WSDLConstants;
@@ -86,26 +88,26 @@
 
         MessageInformationHeaders messageInformationHeaders =
                 msgContext.getMessageInformationHeaders();
-        SOAPHeader soapHeader = msgContext.getEnvelope().getHeader();
+        SOAPEnvelope envelope = msgContext.getEnvelope();
+        SOAPHeader soapHeader = envelope.getHeader();
 
         // 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.
-        soapHeader.declareNamespace(addressingNamespaceObject);
+        envelope.declareNamespace(addressingNamespaceObject);
 
         // processing WSA To
         EndpointReference epr = messageInformationHeaders.getTo();
-        if (epr != null && !isAddressingHeaderAlreadyAvailable(WSA_TO, soapHeader))
{
+        if (epr != null && !isAddressingHeaderAlreadyAvailable(WSA_TO, envelope))
{
 
             String address = epr.getAddress();
             if (!"".equals(address) && address != null) {
-                SOAPHeaderBlock toHeaderBlock = soapHeader.addHeaderBlock(
-                        WSA_TO, addressingNamespaceObject);
+                SOAPHeaderBlock toHeaderBlock = envelope.addHeaderBlock(WSA_TO, addressingNamespaceObject);
                 toHeaderBlock.setText(address);
             }
 
-            processReferenceInformation(epr.getAllReferenceParameters(), soapHeader);
+            processReferenceInformation(epr.getAllReferenceParameters(), soapHeader );
             processReferenceInformation(epr.getAllReferenceProperties(), soapHeader);
 
             addToHeader(epr, soapHeader);
@@ -113,12 +115,12 @@
 
         // processing WSA Action
         String action = messageInformationHeaders.getAction();
-        if (action != null && !isAddressingHeaderAlreadyAvailable(WSA_ACTION, soapHeader))
{
-            processStringInfo(action, WSA_ACTION, soapHeader);
+        if (action != null && !isAddressingHeaderAlreadyAvailable(WSA_ACTION, envelope))
{
+            processStringInfo(action, WSA_ACTION, envelope);
         }
 
         // processing WSA replyTo
-        if (!isAddressingHeaderAlreadyAvailable(WSA_REPLY_TO, soapHeader)) {
+        if (!isAddressingHeaderAlreadyAvailable(WSA_REPLY_TO, envelope)) {
             epr = messageInformationHeaders.getReplyTo();
             if (epr == null) {//optional
                 // setting anonymous URI. Defaulting to Final.
@@ -134,33 +136,33 @@
                 epr.addReferenceParameter(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, envelope);
         }
 
         epr = messageInformationHeaders.getFrom();
         if (epr != null) {//optional
-            addToSOAPHeader(epr, AddressingConstants.WSA_FROM, soapHeader);
+            addToSOAPHeader(epr, AddressingConstants.WSA_FROM, envelope);
         }
 
         epr = messageInformationHeaders.getFaultTo();
         if (epr != null) {//optional
-            addToSOAPHeader(epr, AddressingConstants.WSA_FAULT_TO, soapHeader);
+            addToSOAPHeader(epr, AddressingConstants.WSA_FAULT_TO, envelope);
         }
 
         String messageID = messageInformationHeaders.getMessageId();
-        if (messageID != null && !isAddressingHeaderAlreadyAvailable(WSA_MESSAGE_ID,
soapHeader)) {//optional
-            processStringInfo(messageID, WSA_MESSAGE_ID, soapHeader);
+        if (messageID != null && !isAddressingHeaderAlreadyAvailable(WSA_MESSAGE_ID,
envelope)) {//optional
+            processStringInfo(messageID, WSA_MESSAGE_ID, envelope);
         }
 
-        if (!isAddressingHeaderAlreadyAvailable(WSA_RELATES_TO, soapHeader)) {
-            org.apache.axis2.addressing.RelatesTo relatesTo = messageInformationHeaders.getRelatesTo();
+        if (!isAddressingHeaderAlreadyAvailable(WSA_RELATES_TO, envelope)) {
+            RelatesTo relatesTo = messageInformationHeaders.getRelatesTo();
             OMElement relatesToHeader = null;
 
             if (relatesTo != null) {
                 relatesToHeader =
                         processStringInfo(relatesTo.getValue(),
                                 WSA_RELATES_TO,
-                                soapHeader);
+                                envelope);
             }
 
             if (relatesToHeader != null)
@@ -179,10 +181,10 @@
 
     private OMElement processStringInfo(String value,
                                         String type,
-                                        SOAPHeader soapHeader) {
+                                        SOAPEnvelope soapEnvelope) {
         if (!"".equals(value) && value != null) {
             SOAPHeaderBlock soapHeaderBlock =
-                    soapHeader.addHeaderBlock(type, addressingNamespaceObject);
+                    soapEnvelope.addHeaderBlock(type, addressingNamespaceObject);
             soapHeaderBlock.addChild(
                     OMAbstractFactory.getOMFactory().createText(value));
             return soapHeaderBlock;
@@ -192,13 +194,13 @@
 
     protected void addToSOAPHeader(EndpointReference epr,
                                    String type,
-                                   SOAPHeader soapHeader) {
-        if (epr == null || isAddressingHeaderAlreadyAvailable(type, soapHeader)) {
+                                   SOAPEnvelope envelope) {
+        if (epr == null || isAddressingHeaderAlreadyAvailable(type, envelope)) {
             return;
         }
 
         SOAPHeaderBlock soapHeaderBlock =
-                soapHeader.addHeaderBlock(type, addressingNamespaceObject);
+                envelope.addHeaderBlock(type, addressingNamespaceObject);
 
         String address = epr.getAddress();
         if (!"".equals(address) && address != null) {
@@ -231,7 +233,7 @@
                         OMAbstractFactory.getOMFactory().createOMElement(
                                 Submission.EPR_REFERENCE_PROPERTIES,
                                 addressingNamespaceObject);
-                soapHeader.addChild(reference);
+                envelope.getHeader().addChild(reference);
                 processReferenceInformation(referenceParameters, reference);
             }
 
@@ -296,8 +298,13 @@
         }
     }
 
-    private boolean isAddressingHeaderAlreadyAvailable(String name, SOAPHeader soapHeader)
{
-        return soapHeader.getFirstChildWithName(new QName(addressingNamespaceObject.getName(),
name, addressingNamespaceObject.getPrefix())) != null;
+    private boolean isAddressingHeaderAlreadyAvailable(String name, SOAPEnvelope envelope)
{
+        boolean isAvail = envelope.getFirstChildWithName(new QName(addressingNamespaceObject.getName(),
name, addressingNamespaceObject.getPrefix())) != null;
+        if(!isAvail && envelope.getHeader() != null){
+            // check in headers too
+            isAvail = envelope.getHeader().getFirstChildWithName(new QName(addressingNamespaceObject.getName(),
name, addressingNamespaceObject.getPrefix())) != null;
+        }
+        return isAvail;
     }
 }
 

Modified: webservices/axis2/trunk/java/modules/saaj/src/javax/xml/soap/SOAPEnvelope.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/saaj/src/javax/xml/soap/SOAPEnvelope.java?rev=355879&r1=355878&r2=355879&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/javax/xml/soap/SOAPEnvelope.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/src/javax/xml/soap/SOAPEnvelope.java Sat Dec
10 19:01:24 2005
@@ -56,7 +56,7 @@
  * </PRE>
  * To create a <CODE>SOAPHeader</CODE> object to replace the one
  * that was removed, a client uses the method <CODE>
- * SOAPEnvelope.addHeader</CODE>, which creates a new header and
+ * SOAPEnvelope.addHeaderBlock</CODE>, which creates a new header and
  * adds it to the <CODE>SOAPEnvelope</CODE> object. Similarly, the
  * method <CODE>addBody</CODE> creates a new <CODE>SOAPBody</CODE>
  * object and adds it to the <CODE>SOAPEnvelope</CODE> object. The
@@ -67,7 +67,7 @@
  * SOAPPart sp = message.getSOAPPart();
  * SOAPEnvelope se = sp.getEnvelope();
  * se.getHeader().detachNode();
- * SOAPHeader sh = se.addHeader();
+ * SOAPHeader sh = se.addHeaderBlock();
  * se.getBody().detachNode();
  * SOAPBody sb = se.addBody();
  * </PRE>

Modified: webservices/axis2/trunk/java/modules/saaj/src/javax/xml/soap/SOAPHeader.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/saaj/src/javax/xml/soap/SOAPHeader.java?rev=355879&r1=355878&r2=355879&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/javax/xml/soap/SOAPHeader.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/src/javax/xml/soap/SOAPHeader.java Sat Dec 10
19:01:24 2005
@@ -35,12 +35,12 @@
  * se.getHeader().detachNode();
  * </PRE>
  * A <CODE>SOAPHeader</CODE> object is created with the <CODE>
- * SOAPEnvelope</CODE> method <CODE>addHeader</CODE>. This method,
+ * SOAPEnvelope</CODE> method <CODE>addHeaderBlock</CODE>. This method,
  * which creates a new header and adds it to the envelope, may be
  * called only after the existing header has been removed.
  * <PRE>
  * se.getHeader().detachNode();
- * SOAPHeader sh = se.addHeader();
+ * SOAPHeader sh = se.addHeaderBlock();
  * </PRE>
  * <p/>
  * <P>A <CODE>SOAPHeader</CODE> object can have only <CODE>

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPEnvelopeImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPEnvelopeImpl.java?rev=355879&r1=355878&r2=355879&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPEnvelopeImpl.java
(original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPEnvelopeImpl.java
Sat Dec 10 19:01:24 2005
@@ -139,7 +139,7 @@
     }
 
     /**
-     * method addHeader
+     * method addHeaderBlock
      *
      * @return
      * @throws SOAPException

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/soap/impl/dom/SOAPEnvelopeImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/soap/impl/dom/SOAPEnvelopeImpl.java?rev=355879&r1=355878&r2=355879&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/soap/impl/dom/SOAPEnvelopeImpl.java
(original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/soap/impl/dom/SOAPEnvelopeImpl.java
Sat Dec 10 19:01:24 2005
@@ -25,16 +25,7 @@
 import org.apache.axis2.om.impl.OMOutputImpl;
 import org.apache.axis2.om.impl.dom.DocumentImpl;
 import org.apache.axis2.om.impl.dom.NamespaceImpl;
-import org.apache.axis2.soap.SOAP11Constants;
-import org.apache.axis2.soap.SOAP12Constants;
-import org.apache.axis2.soap.SOAPBody;
-import org.apache.axis2.soap.SOAPConstants;
-import org.apache.axis2.soap.SOAPEnvelope;
-import org.apache.axis2.soap.SOAPFactory;
-import org.apache.axis2.soap.SOAPHeader;
-import org.apache.axis2.soap.SOAPHeaderBlock;
-import org.apache.axis2.soap.SOAPProcessingException;
-import org.apache.axis2.soap.impl.dom.SOAPElement;
+import org.apache.axis2.soap.*;
 import org.apache.axis2.soap.impl.dom.factory.DOMSOAPFactory;
 import org.apache.axis2.soap.impl.dom.soap11.SOAP11Factory;
 
@@ -101,28 +92,32 @@
 	/**
 	 * Convenience method to add a SOAP header to this envelope
 	 * 
-	 * @param namespaceURI
 	 * @param name
-	 */
-	public SOAPHeaderBlock addHeader(String namespaceURI, String name)
+     * @param namespaceURI
+     */
+	public SOAPHeaderBlock addHeaderBlock(String name, String namespaceURI)
 			throws OMException {
 		// TODO : cache SOAP header and body instead of looking them up?
 
-		SOAPHeader headerContainer = getHeader();
 		OMNamespace namespace = factory.createOMNamespace(namespaceURI, null);
-		return factory.createSOAPHeaderBlock(name, namespace, headerContainer);
+		return this.addHeaderBlock(name, namespace);
 	}
 
-	public void addChild(OMNode child) {
-		if ((child instanceof OMElement)
-				&& !(child instanceof SOAPHeader || child instanceof SOAPBody)) {
-			throw new SOAPProcessingException(
-					"SOAP Envelope can not have children other than SOAP Header and Body",
-					SOAP12Constants.FAULT_CODE_SENDER);
-		} else {
-			super.addChild(child);
-		}
-	}
+    public SOAPHeaderBlock addHeaderBlock(String name, OMNamespace namespace) throws OMException
{
+        SOAPHeader headerContainer = getHeader();
+        return factory.createSOAPHeaderBlock(name, namespace, headerContainer);
+    }
+
+    public void addChild(OMNode child) {
+        if ((child instanceof OMElement)
+                && !(child instanceof SOAPHeader || child instanceof SOAPBody)) {
+            throw new SOAPProcessingException(
+                    "SOAP Envelope can not have children other than SOAP Header and Body",
+                    SOAP12Constants.FAULT_CODE_SENDER);
+        } else {
+            super.addChild(child);
+        }
+    }
 
 	/**
 	 * Returns the <CODE>SOAPBody</CODE> object associated with this <CODE>SOAPEnvelope</CODE>

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/SOAPEnvelope.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/SOAPEnvelope.java?rev=355879&r1=355878&r2=355879&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/SOAPEnvelope.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/SOAPEnvelope.java Sat
Dec 10 19:01:24 2005
@@ -18,6 +18,7 @@
 
 import org.apache.axis2.om.OMElement;
 import org.apache.axis2.om.OMException;
+import org.apache.axis2.om.OMNamespace;
 
 /**
  * Interface SOAPEnvelope
@@ -41,10 +42,13 @@
     /**
      * Convenience method to add a SOAP header to this envelope
      *
-     * @param namespaceURI
      * @param name
+     * @param namespaceURI
      */
-    public abstract SOAPHeaderBlock addHeader(String namespaceURI, String name)
+    public abstract SOAPHeaderBlock addHeaderBlock(String name, String namespaceURI)
+            throws OMException;
+
+    public abstract SOAPHeaderBlock addHeaderBlock(String name, OMNamespace namespace)
             throws OMException;
 
     /**

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/SOAPEnvelopeImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/SOAPEnvelopeImpl.java?rev=355879&r1=355878&r2=355879&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/SOAPEnvelopeImpl.java
(original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/SOAPEnvelopeImpl.java
Sat Dec 10 19:01:24 2005
@@ -85,18 +85,20 @@
     /**
      * Convenience method to add a SOAP header to this envelope
      *
-     * @param namespaceURI
      * @param name
+     * @param namespaceURI
      */
-    public SOAPHeaderBlock addHeader(String namespaceURI, String name)
+    public SOAPHeaderBlock addHeaderBlock(String name, String namespaceURI)
             throws OMException {
         // TODO : cache SOAP header and body instead of looking them up?
 
-        SOAPHeader headerContainer = getHeader();
         OMNamespace namespace = factory.createOMNamespace(namespaceURI, null);
-        return factory.createSOAPHeaderBlock(name,
-                                                              namespace,
-                                                              headerContainer);
+        return this.addHeaderBlock(name, namespace);
+    }
+
+    public SOAPHeaderBlock addHeaderBlock(String name, OMNamespace namespace) throws OMException
{
+        SOAPHeader headerContainer = getHeader();
+        return factory.createSOAPHeaderBlock(name,namespace,headerContainer);
     }
 
     public void addChild(OMNode child) {

Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/soap/SOAPEnvelopeTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/soap/SOAPEnvelopeTest.java?rev=355879&r1=355878&r2=355879&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/soap/SOAPEnvelopeTest.java
(original)
+++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/soap/SOAPEnvelopeTest.java
Sat Dec 10 19:01:24 2005
@@ -25,10 +25,10 @@
         super(testName);
         soap11Envelope = soap11Factory.getDefaultEnvelope();
         // Toss in a header to make sure the SOAPHeader gets set up
-        soap11Envelope.addHeader("http://ns", "dummy");
+        soap11Envelope.addHeaderBlock("dummy", "http://ns");
         soap12Envelope = soap12Factory.getDefaultEnvelope();
         // Toss in a header to make sure the SOAPHeader gets set up
-        soap12Envelope.addHeader("http://ns", "dummy");
+        soap12Envelope.addHeaderBlock("dummy", "http://ns");
     }
 
     //SOAP 1.1 Envelope Test (Programaticaly Created)-----------------------------------------------



Mime
View raw message