You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ff...@apache.org on 2010/06/18 04:13:25 UTC

svn commit: r955813 - in /servicemix/components/bindings/servicemix-cxf-bc/trunk/src: main/java/org/apache/servicemix/cxfbc/interceptors/ test/java/org/apache/servicemix/cxfbc/ test/resources/org/apache/servicemix/cxfbc/

Author: ffang
Date: Fri Jun 18 02:13:25 2010
New Revision: 955813

URL: http://svn.apache.org/viewvc?rev=955813&view=rev
Log:
[SMXCOMP-759]cxf bc consumer should be able to extract and save extra prefix from soap env of incoming message

Added:
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcConsumerExtraPrefixTest.java
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/old_time_request_with_extra_prefix.xml
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/xbean_extra_prefix.xml
Modified:
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiInWsdl1Interceptor.java
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcProviderConsumerTest.java

Modified: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiInWsdl1Interceptor.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiInWsdl1Interceptor.java?rev=955813&r1=955812&r2=955813&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiInWsdl1Interceptor.java (original)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiInWsdl1Interceptor.java Fri Jun 18 02:13:25 2010
@@ -17,7 +17,10 @@
 package org.apache.servicemix.cxfbc.interceptors;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+
 import javax.xml.XMLConstants;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
@@ -27,10 +30,12 @@ import javax.xml.transform.dom.DOMSource
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
 import org.apache.cxf.binding.soap.Soap11;
+import org.apache.cxf.binding.soap.Soap12;
 import org.apache.cxf.binding.soap.SoapHeader;
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.binding.soap.SoapVersion;
@@ -75,7 +80,7 @@ public class JbiInWsdl1Interceptor exten
             return;
         }
         Document document = DomUtil.createDocument();
-
+              
         if (!useJBIWrapper) {
         	SoapVersion soapVersion = message.getVersion();
         	if (useSOAPEnvelope) {
@@ -87,14 +92,9 @@ public class JbiInWsdl1Interceptor exten
                     soapVersion.getBody().getNamespaceURI(), soapVersion
                             .getBody().getLocalPart(), soapVersion
                             .getPrefix()));
-                        soapEnv.setAttribute(XMLConstants.XMLNS_ATTRIBUTE + ":"
-                            + CxfJbiConstants.WSDL11_WRAPPER_XSD_PREFIX,
-                            XMLConstants.W3C_XML_SCHEMA_NS_URI);
-
-                        soapEnv.setAttribute(XMLConstants.XMLNS_ATTRIBUTE + ":"
-                            + CxfJbiConstants.WSDL11_WRAPPER_XSI_PREFIX,
-                            XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
-                        soapEnv.appendChild(soapBody);
+        		setExtraPrefix(message, soapEnv);
+                        
+                soapEnv.appendChild(soapBody);
         		Element body = getBodyElement(message);
                         
         		if (body != null) {
@@ -122,6 +122,32 @@ public class JbiInWsdl1Interceptor exten
         
     }
 
+    private void setExtraPrefix(SoapMessage message, Element soapEnv) {
+        Document savedEnv = (Document) message.getContent(Node.class);
+        if (savedEnv != null) {
+            NamedNodeMap attrs = savedEnv.getFirstChild().getAttributes();
+            Map<String, String> nsMap = message.getEnvelopeNs();
+            if (nsMap == null) {
+                nsMap = new HashMap<String, String>();
+            }
+            for (int i = 0; i < attrs.getLength(); i++) {
+                Node node = attrs.item(i);
+                if (!node.getNodeValue().equals(Soap11.SOAP_NAMESPACE)
+                        && !node.getNodeValue().equals(Soap12.SOAP_NAMESPACE)) {
+                    //set extra prefix
+                    soapEnv.setAttribute(XMLConstants.XMLNS_ATTRIBUTE + ":"
+                            + node.getLocalName(),
+                            node.getNodeValue());
+                    nsMap.put(node.getLocalName(), node.getNodeValue());
+                }
+                    
+            }
+            if (nsMap.size() > 0) {
+                message.put("soap.env.ns.map", nsMap);
+            }
+        }
+    }
+
     private Document createDOMWrapper(SoapMessage message) {
         Document document;
         BindingOperationInfo wsdlOperation = getOperation(message);
@@ -142,13 +168,7 @@ public class JbiInWsdl1Interceptor exten
                         + CxfJbiConstants.WSDL11_WRAPPER_MESSAGE_PREFIX,
                         typeNamespace);
         
-        root.setAttribute(XMLConstants.XMLNS_ATTRIBUTE + ":"
-                + CxfJbiConstants.WSDL11_WRAPPER_XSD_PREFIX,
-                XMLConstants.W3C_XML_SCHEMA_NS_URI);
-
-        root.setAttribute(XMLConstants.XMLNS_ATTRIBUTE + ":"
-                + CxfJbiConstants.WSDL11_WRAPPER_XSI_PREFIX,
-                XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
+        setExtraPrefix(message, root);
         
         String typeLocalName = wsdlMessage.getMessageInfo().getName()
                 .getLocalPart();

Added: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcConsumerExtraPrefixTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcConsumerExtraPrefixTest.java?rev=955813&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcConsumerExtraPrefixTest.java (added)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcConsumerExtraPrefixTest.java Fri Jun 18 02:13:25 2010
@@ -0,0 +1,73 @@
+/*
+ * 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.servicemix.cxfbc;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLConnection;
+
+
+import org.apache.cxf.calculator.CalculatorImpl;
+import org.apache.cxf.interceptor.LoggingInInterceptor;
+import org.apache.cxf.interceptor.LoggingOutInterceptor;
+import org.apache.cxf.jaxws.EndpointImpl;
+import org.apache.servicemix.tck.SpringTestSupport;
+import org.apache.servicemix.util.FileUtil;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+public class CxfBcConsumerExtraPrefixTest extends SpringTestSupport {
+public void testBridge() throws Exception {
+        
+        // start external service
+        EndpointImpl endpoint =
+            (EndpointImpl)javax.xml.ws.Endpoint.publish("http://localhost:9001/bridgetest", 
+                new CalculatorImpl());
+                        
+        endpoint.getInInterceptors().add(new LoggingInInterceptor());
+        endpoint.getOutInterceptors().add(new LoggingOutInterceptor());
+        endpoint.getInFaultInterceptors().add(new LoggingInInterceptor());
+        endpoint.getOutFaultInterceptors().add(new LoggingOutInterceptor());
+
+        // send request
+
+        URLConnection connection = new URL(
+                "http://localhost:19000/CalculatorService/SoapPort").openConnection();
+        connection.setDoInput(true);
+        connection.setDoOutput(true);
+        OutputStream os = connection.getOutputStream();
+        // Post the request file.
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "org/apache/servicemix/cxfbc/old_time_request_with_extra_prefix.xml");
+        FileUtil.copyInputStream(fis, os);
+        // Read the response.
+        InputStream is = connection.getInputStream();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        FileUtil.copyInputStream(is, baos);
+        assertTrue(baos.toString().contains("<return>3</return>"));
+       
+
+    }
+
+    @Override
+    protected AbstractXmlApplicationContext createBeanFactory() {
+        return new ClassPathXmlApplicationContext(
+                "org/apache/servicemix/cxfbc/xbean_extra_prefix.xml");
+    }
+}

Modified: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcProviderConsumerTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcProviderConsumerTest.java?rev=955813&r1=955812&r2=955813&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcProviderConsumerTest.java (original)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcProviderConsumerTest.java Fri Jun 18 02:13:25 2010
@@ -20,7 +20,6 @@ import java.net.URL;
 
 import javax.xml.namespace.QName;
 import javax.xml.ws.soap.SOAPBinding;
-import org.apache.cxf.calculator.AddNumbersFault;
 import org.apache.cxf.calculator.CalculatorImpl;
 import org.apache.cxf.calculator.CalculatorPortType;
 import org.apache.cxf.calculator.CalculatorService;

Added: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/old_time_request_with_extra_prefix.xml
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/old_time_request_with_extra_prefix.xml?rev=955813&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/old_time_request_with_extra_prefix.xml (added)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/old_time_request_with_extra_prefix.xml Fri Jun 18 02:13:25 2010
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><add xmlns="http://apache.org/cxf/calculator/types" xsi:type="dummyType"><arg0>1</arg0><arg1>2</arg1></add></soap:Body></soap:Envelope>

Added: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/xbean_extra_prefix.xml
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/xbean_extra_prefix.xml?rev=955813&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/xbean_extra_prefix.xml (added)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/xbean_extra_prefix.xml Fri Jun 18 02:13:25 2010
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  
+  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.
+  
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+       xmlns:cxfse="http://servicemix.apache.org/cxfse/1.0"
+       xmlns:cxfbc="http://servicemix.apache.org/cxfbc/1.0"
+       xmlns:test="urn:test"
+       xmlns:calculator="http://apache.org/cxf/calculator">
+  
+  <sm:container id="jbi" embedded="true">
+    
+    <sm:endpoints>
+      <cxfse:endpoint useJBIWrapper="false">
+        <cxfse:pojo>
+          <bean class="org.apache.servicemix.cxfbc.CalculatorImpl" />
+        </cxfse:pojo>
+        <cxfse:inInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+        </cxfse:inInterceptors>
+        <cxfse:outInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
+        </cxfse:outInterceptors>
+        <cxfse:inFaultInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+        </cxfse:inFaultInterceptors>
+        <cxfse:outFaultInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
+        </cxfse:outFaultInterceptors>
+      </cxfse:endpoint>
+      <cxfbc:consumer wsdl="/wsdl/calculator.wsdl"
+                      locationURI="http://localhost:19000/CalculatorService/SoapPort"
+                      targetEndpoint="CalculatorPort"
+                      targetService="calculator:CalculatorService"
+                      targetInterface="calculator:CalculatorPortType"
+                      useJBIWrapper="false"
+                      >
+        <cxfbc:inInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+        </cxfbc:inInterceptors>
+        <cxfbc:outInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
+        </cxfbc:outInterceptors>
+        <cxfbc:inFaultInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+        </cxfbc:inFaultInterceptors>
+        <cxfbc:outFaultInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
+        </cxfbc:outFaultInterceptors>
+      </cxfbc:consumer>
+    </sm:endpoints>
+    
+  </sm:container>
+  
+</beans>