Author: veithen
Date: Sun May 29 15:54:01 2016
New Revision: 1746027

URL: http://svn.apache.org/viewvc?rev=1746027&view=rev
Log:
SYNAPSE-1027: Fix a performance regression caused by pass through related code. 
Patch provided by Auke Schrijnen. Also update the Axis2 version to 
1.7.3-SNAPSHOT since the unit test depends on a fix in the Axis2 transport 
testkit.

Added:
    
synapse/trunk/java/modules/transports/core/nhttp/src/test/java/org/apache/synapse/transport/passthru/
    
synapse/trunk/java/modules/transports/core/nhttp/src/test/java/org/apache/synapse/transport/passthru/util/
    
synapse/trunk/java/modules/transports/core/nhttp/src/test/java/org/apache/synapse/transport/passthru/util/RelayUtilsTest.java
   (with props)
Modified:
    
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/RelayUtils.java
    synapse/trunk/java/pom.xml

Modified: 
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/RelayUtils.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/RelayUtils.java?rev=1746027&r1=1746026&r2=1746027&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/RelayUtils.java
 (original)
+++ 
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/util/RelayUtils.java
 Sun May 29 15:54:01 2016
@@ -42,6 +42,7 @@ import org.apache.synapse.transport.pass
 
 import javax.activation.DataHandler;
 import javax.activation.DataSource;
+import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 
 import java.io.BufferedInputStream;
@@ -88,10 +89,20 @@ public class RelayUtils {
         }
 
         SOAPEnvelope envelope = messageContext.getEnvelope();
-        OMElement contentEle = envelope.getBody().getFirstChildWithName(
-                RelayConstants.BINARY_CONTENT_QNAME);
 
-        if (contentEle != null) {
+        QName firstElementQName;
+        if (envelope.getSOAPBodyFirstElementNS() != null) {
+            firstElementQName = new QName(
+                    envelope.getSOAPBodyFirstElementNS().getNamespaceURI(),
+                    envelope.getSOAPBodyFirstElementLocalName());
+        } else if (envelope.getSOAPBodyFirstElementLocalName() != null){
+            firstElementQName = new 
QName(envelope.getSOAPBodyFirstElementLocalName());
+        } else {
+            firstElementQName = null;
+        }
+
+        if (RelayConstants.BINARY_CONTENT_QNAME.equals(firstElementQName)) {
+            OMElement contentEle = envelope.getBody().getFirstElement();
             OMNode node = contentEle.getFirstOMChild();
             if (node != null && (node instanceof OMText)) {
                 OMText binaryDataNode = (OMText) node;

Added: 
synapse/trunk/java/modules/transports/core/nhttp/src/test/java/org/apache/synapse/transport/passthru/util/RelayUtilsTest.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/test/java/org/apache/synapse/transport/passthru/util/RelayUtilsTest.java?rev=1746027&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/transports/core/nhttp/src/test/java/org/apache/synapse/transport/passthru/util/RelayUtilsTest.java
 (added)
+++ 
synapse/trunk/java/modules/transports/core/nhttp/src/test/java/org/apache/synapse/transport/passthru/util/RelayUtilsTest.java
 Sun May 29 15:54:01 2016
@@ -0,0 +1,102 @@
+/*
+ *  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.synapse.transport.passthru.util;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.nio.charset.Charset;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.commons.io.input.ReaderInputStream;
+import org.junit.Before;
+import org.junit.Test;
+
+public class RelayUtilsTest {
+
+    private static final Charset UTF8 = Charset.forName("UTF-8");
+
+    private final String xml =
+            "<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'>"
+            + "<s:Body><payload><data>value</data></payload></s:Body>"
+            + "</s:Envelope>";
+
+    private final QName payloadQName = new QName("payload");
+
+    MessageContext msgCtx;
+
+    @Before
+    public void setUp() throws Exception {
+        msgCtx = new MessageContext();
+
+        AxisConfiguration configuration = new AxisConfiguration();
+        ConfigurationContext context = new ConfigurationContext(configuration);
+        msgCtx.setConfigurationContext(context);
+    }
+
+    @Test
+    public void testSOAPBodyIsntFullyReadWhenNotUsingBinaryRelayBuilder()
+            throws IOException, XMLStreamException {
+
+        SOAPEnvelope envelope = OMXMLBuilderFactory
+                .createSOAPModelBuilder(new 
StringReader(xml)).getSOAPEnvelope();
+
+        msgCtx.setEnvelope(envelope);
+
+        // Build message when using pass through pipe or binary relay builder
+        RelayUtils.buildMessage(msgCtx);
+
+        // Ensure that the payload element is accessible
+        assertEquals(payloadQName, 
msgCtx.getEnvelope().getBody().getFirstElement().getQName());
+
+        // Ensure that the body isn't fully build to support the use of 
deferred building
+        assertFalse(msgCtx.getEnvelope().getBody().isComplete());
+    }
+
+    @Test
+    public void testBinaryRelayPayloadExpandsToOriginalPayload()
+            throws IOException, XMLStreamException {
+
+        // Transform request soap message into a binary payload
+        BinaryRelayBuilder builder = new BinaryRelayBuilder();
+        InputStream stream = new ReaderInputStream(new StringReader(xml), 
UTF8);
+        OMElement element = builder.processDocument(stream, "text/xml", 
msgCtx);
+        msgCtx.setEnvelope((SOAPEnvelope)element);
+
+        // Build message when using pass through pipe or binary relay builder
+        RelayUtils.buildMessage(msgCtx);
+
+        // Ensure that the binary payload is transformed to the appropriate 
element
+        assertEquals(payloadQName, 
msgCtx.getEnvelope().getBody().getFirstElement().getQName());
+
+        // Ensure that the body isn't fully build to support the use of 
deferred building
+        assertFalse(msgCtx.getEnvelope().getBody().isComplete());
+    }
+
+}

Propchange: 
synapse/trunk/java/modules/transports/core/nhttp/src/test/java/org/apache/synapse/transport/passthru/util/RelayUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: synapse/trunk/java/pom.xml
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/pom.xml?rev=1746027&r1=1746026&r2=1746027&view=diff
==============================================================================
--- synapse/trunk/java/pom.xml (original)
+++ synapse/trunk/java/pom.xml Sun May 29 15:54:01 2016
@@ -1035,7 +1035,7 @@
         <commons.codec.version>1.6</commons.codec.version>
 
         <!-- Axis2 and its dependencies -->
-        <axis2.version>1.7.2</axis2.version>
+        <axis2.version>1.7.3-SNAPSHOT</axis2.version>
         <axiom.version>1.2.19</axiom.version>
         <wsdl4j.version>1.6.2</wsdl4j.version>
 


Reply via email to