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 sc...@apache.org on 2008/04/23 18:05:34 UTC

svn commit: r650924 - in /webservices/axis2/trunk/java/modules/kernel: src/org/apache/axis2/ src/org/apache/axis2/builder/ src/org/apache/axis2/context/ test/org/apache/axis2/builder/

Author: scheu
Date: Wed Apr 23 09:05:29 2008
New Revision: 650924

URL: http://svn.apache.org/viewvc?rev=650924&view=rev
Log:
WSCOMMONS-330
Contributor:Rich Scheuerle
Applied the DispatchableInputStream to the incoming stream for SOAPBuilder/ApplicationXMLBuilder.
Changed MessageContext to get the inbound content length using information collected in the DispatchableInputStream.
Added a simple validation test.

Added:
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/builder/
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/builder/SOAPBuilderTest.java
Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/ApplicationXMLBuilder.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/SOAPBuilder.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java?rev=650924&r1=650923&r2=650924&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java Wed Apr 23 09:05:29 2008
@@ -263,6 +263,15 @@
      * from SOAPFault to AxisFault
      */
     public static final String INBOUND_FAULT_OVERRIDE = "inboundFaultOverride";
+    
+    
+    /**
+     * On inbound requests, the detachable input stream can be queried to get
+     * the inbound length.  It can also be "detached" from the inbound http stream
+     * to allow resources to be freed.
+     */
+    public static final String DETACHABLE_INPUT_STREAM = 
+        "org.apache.axiom.om.util.DetachableInputStream";
 
     /** SOAP Role Configuration */
     public static final String SOAP_ROLE_CONFIGURATION_ELEMENT = "SOAPRoleConfiguration";

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/ApplicationXMLBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/ApplicationXMLBuilder.java?rev=650924&r1=650923&r2=650924&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/ApplicationXMLBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/ApplicationXMLBuilder.java Wed Apr 23 09:05:29 2008
@@ -23,6 +23,7 @@
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.impl.OMNodeEx;
 import org.apache.axiom.om.impl.builder.StAXBuilder;
+import org.apache.axiom.om.util.DetachableInputStream;
 import org.apache.axiom.soap.SOAPBody;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.SOAPFactory;
@@ -50,7 +51,13 @@
         SOAPEnvelope soapEnvelope = soapFactory.getDefaultEnvelope();
         if (inputStream != null) {
             try {
-                PushbackInputStream pushbackInputStream = new PushbackInputStream(inputStream);
+                // Apply a detachable inputstream.  This can be used later
+                // to (a) get the length of the incoming message or (b)
+                // free transport resources.
+                DetachableInputStream is = new DetachableInputStream(inputStream);
+                messageContext.setProperty(Constants.DETACHABLE_INPUT_STREAM, is);
+                
+                PushbackInputStream pushbackInputStream = new PushbackInputStream(is);
                 int b;
                 if ((b = pushbackInputStream.read()) > 0) {
                     pushbackInputStream.unread(b);

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/SOAPBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/SOAPBuilder.java?rev=650924&r1=650923&r2=650924&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/SOAPBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/builder/SOAPBuilder.java Wed Apr 23 09:05:29 2008
@@ -22,6 +22,7 @@
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.impl.builder.StAXBuilder;
 import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.om.util.DetachableInputStream;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 import org.apache.axis2.AxisFault;
@@ -43,8 +44,14 @@
             String charSetEncoding = (String) messageContext
                     .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
             
+            // Apply a detachable inputstream.  This can be used later
+            // to (a) get the length of the incoming message or (b)
+            // free transport resources.
+            DetachableInputStream is = new DetachableInputStream(inputStream);
+            messageContext.setProperty(Constants.DETACHABLE_INPUT_STREAM, is);
+            
             // Get the actual encoding by looking at the BOM of the InputStream
-            PushbackInputStream pis = BuilderUtil.getPushbackInputStream(inputStream);
+            PushbackInputStream pis = BuilderUtil.getPushbackInputStream(is);
             String actualCharSetEncoding = BuilderUtil.getCharSetEncoding(pis, charSetEncoding);
             
             // Get the XMLStreamReader for this input stream

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java?rev=650924&r1=650923&r2=650924&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java Wed Apr 23 09:05:29 2008
@@ -21,6 +21,7 @@
 
 import org.apache.axiom.attachments.Attachments;
 import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.util.DetachableInputStream;
 import org.apache.axiom.om.util.UUIDGenerator;
 import org.apache.axiom.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP12Constants;
@@ -1179,6 +1180,24 @@
         return isSOAP11;
     }
 
+    /**
+     * @return inbound content length of 0
+     */
+    public long getInboundContentLength() throws IOException {
+        // If there is an attachment map, the Attachments keep track
+        // of the inbound content length.
+        if (attachments != null) {
+            return attachments.getContentLength();
+        } 
+        
+        // Otherwise the length is accumulated by the DetachableInputStream.
+        DetachableInputStream dis = 
+            (DetachableInputStream) getProperty(Constants.DETACHABLE_INPUT_STREAM);
+        if (dis != null) {
+            return dis.length();
+        }
+        return 0;
+    }
     /**
      * @return Returns boolean.
      */

Added: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/builder/SOAPBuilderTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/builder/SOAPBuilderTest.java?rev=650924&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/builder/SOAPBuilderTest.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/builder/SOAPBuilderTest.java Wed Apr 23 09:05:29 2008
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.builder;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axis2.AbstractTestCase;
+import org.apache.axis2.context.MessageContext;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+
+/**
+ * Tests for SOAPBuilder
+ */
+public class SOAPBuilderTest extends AbstractTestCase {
+
+    public SOAPBuilderTest(String testName) {
+        super(testName);
+    }
+
+    /**
+     * Simple test the makes sure SOAPBuilder builds a document and
+     * has a content length
+     * @throws Exception
+     */
+    public void test() throws Exception {
+        File file = getTestResourceFile("soapmessage.xml");
+        SOAPBuilder soapBuilder = new SOAPBuilder();
+        FileInputStream fis = new FileInputStream(file);
+        MessageContext mc = new MessageContext();
+        OMElement envelope = soapBuilder.processDocument(fis, "text/xml", mc);
+        assertTrue(envelope != null);
+        assertTrue(envelope instanceof SOAPEnvelope);
+        assertTrue(mc.getInboundContentLength() > 2000);
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org