camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r915775 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/component/bean/ components/camel-soap/ components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/ components/camel-soap/src/main/java/org/apache/camel/dataforma...
Date Wed, 24 Feb 2010 13:16:17 GMT
Author: ningjiang
Date: Wed Feb 24 13:16:17 2010
New Revision: 915775

URL: http://svn.apache.org/viewvc?rev=915775&view=rev
Log:
CAMEL-2396 Applied patch with thanks to Christian

Added:
    camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfClientTest.java
  (with props)
    camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfServerTest.java
  (with props)
    camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapCxfClientTest-context.xml
  (with props)
    camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapCxfServerTest-context.xml
  (with props)
Removed:
    camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/ExceptionNameStrategy.java
    camel/trunk/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/ExceptionNameStrategyTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/CamelInvocationHandler.java
    camel/trunk/components/camel-soap/pom.xml
    camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/SoapJaxbDataFormat.java
    camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/ElementNameStrategy.java
    camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/QNameStrategy.java
    camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/ServiceInterfaceStrategy.java
    camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/TypeNameStrategy.java
    camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapClientTest.java
    camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java
    camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapMarshalTestExpectedFault.xml
    camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/responseFault.xml

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/CamelInvocationHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/CamelInvocationHandler.java?rev=915775&r1=915774&r2=915775&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/CamelInvocationHandler.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/CamelInvocationHandler.java
Wed Feb 24 13:16:17 2010
@@ -17,7 +17,6 @@
 package org.apache.camel.component.bean;
 
 import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 import org.apache.camel.Endpoint;
@@ -74,7 +73,7 @@
                 }
                 throw (RuntimeCamelException) fault;
             }
-            throw new InvocationTargetException(fault);
+            throw fault;
         }
 
         // do not return a reply if the method is VOID or the MEP is not OUT capable

Modified: camel/trunk/components/camel-soap/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/pom.xml?rev=915775&r1=915774&r2=915775&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/pom.xml (original)
+++ camel/trunk/components/camel-soap/pom.xml Wed Feb 24 13:16:17 2010
@@ -61,8 +61,8 @@
             <artifactId>jaxb-impl</artifactId>
         </dependency>
 
-	<!-- JAXWS api jars -->
-	<dependency>
+		<!-- JAXWS api jars -->
+		<dependency>
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-ws-metadata_2.0_spec</artifactId>
             <version>1.1.2</version>
@@ -96,6 +96,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-cxf</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>commons-logging</groupId>
             <artifactId>commons-logging</artifactId>
             <scope>test</scope>
@@ -116,6 +121,11 @@
             <artifactId>mockito-core</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+        	<groupId>org.springframework</groupId>
+        	<artifactId>spring-test</artifactId>
+        	<scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>

Modified: camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/SoapJaxbDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/SoapJaxbDataFormat.java?rev=915775&r1=915774&r2=915775&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/SoapJaxbDataFormat.java
(original)
+++ camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/SoapJaxbDataFormat.java
Wed Feb 24 13:16:17 2010
@@ -19,20 +19,23 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
+import java.util.List;
 
+import javax.jws.WebMethod;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.JAXBIntrospector;
 import javax.xml.namespace.QName;
+import javax.xml.ws.WebFault;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.bean.BeanInvocation;
 import org.apache.camel.converter.jaxb.JaxbDataFormat;
 import org.apache.camel.dataformat.soap.name.ElementNameStrategy;
-import org.apache.camel.dataformat.soap.name.ExceptionNameStrategy;
 import org.apache.camel.dataformat.soap.name.TypeNameStrategy;
 import org.xmlsoap.schemas.soap.envelope.Body;
 import org.xmlsoap.schemas.soap.envelope.Detail;
@@ -42,15 +45,17 @@
 
 /**
  * Marshaling from Objects to SOAP and back by using JAXB. The classes to be
- * processed need to have JAXB annotations. For marshaling a
- * ElementNameStrategy is used to determine how the top level elements in SOAP
- * are named as this can not be extracted from JAXB.
+ * processed need to have JAXB annotations. For marshaling a ElementNameStrategy
+ * is used to determine how the top level elements in SOAP are named as this can
+ * not be extracted from JAXB.
  */
 public class SoapJaxbDataFormat extends JaxbDataFormat {
     private static final String SOAP_PACKAGE_NAME = Envelope.class.getPackage().getName();
 
+    private static final QName FAULT_CODE_SERVER = new QName("http://www.w3.org/2003/05/soap-envelope",
"Receiver");
+
     private ElementNameStrategy elementNameStrategy;
-    
+
     private String elementNameStrategyRef;
 
     /**
@@ -65,8 +70,8 @@
      * 
      * @param contexPath
      */
-    public SoapJaxbDataFormat(String contexPath) {
-        super(contexPath);
+    public SoapJaxbDataFormat(String contextPath) {
+        super(contextPath);
     }
 
     /**
@@ -83,15 +88,16 @@
         this(contextPath);
         this.elementNameStrategy = elementNameStrategy;
     }
-    
+
     public void setElementNameStrategy(Object nameStrategy) {
         if (nameStrategy instanceof ElementNameStrategy) {
             this.elementNameStrategy = (ElementNameStrategy) nameStrategy;
         } else {
-            new IllegalArgumentException("The argument for setElementNameStrategy should
be subClass of " + ElementNameStrategy.class.getName());
+            new IllegalArgumentException("The argument for setElementNameStrategy should
be subClass of "
+                    + ElementNameStrategy.class.getName());
         }
     }
-    
+
     protected void checkElementNameStrategy(Exchange exchange) {
         if (elementNameStrategy == null) {
             synchronized (this) {
@@ -99,7 +105,8 @@
                     return;
                 } else {
                     if (elementNameStrategyRef != null) {
-                        elementNameStrategy = exchange.getContext().getRegistry().lookup(elementNameStrategyRef,
ElementNameStrategy.class);
+                        elementNameStrategy = exchange.getContext().getRegistry().lookup(elementNameStrategyRef,
+                                ElementNameStrategy.class);
                     } else {
                         elementNameStrategy = new TypeNameStrategy();
                     }
@@ -109,16 +116,25 @@
     }
 
     /**
-     * Marshal inputObject to SOAP xml. If the exchange or message has an EXCEPTION_CAUGTH
-     * property or header then instead of the object the exception is marshaled.
+     * Marshal inputObject to SOAP xml. If the exchange or message has an
+     * EXCEPTION_CAUGTH property or header then instead of the object the
+     * exception is marshaled.
      * 
-     * To determine the name of the top level xml elment the elementNameStrategy is used.
+     * To determine the name of the top level xml elment the elementNameStrategy
+     * is used.
      */
     public void marshal(Exchange exchange, final Object inputObject, OutputStream stream)
throws IOException {
-        
+
         checkElementNameStrategy(exchange);
 
-        String soapAction = (String) exchange.getProperty(Exchange.SOAP_ACTION);
+        String soapAction = (String) exchange.getIn().getHeader(Exchange.SOAP_ACTION);
+        if (soapAction == null && inputObject instanceof BeanInvocation) {
+            BeanInvocation beanInvocation = (BeanInvocation) inputObject;
+            WebMethod webMethod = beanInvocation.getMethod().getAnnotation(WebMethod.class);
+            if (webMethod != null && webMethod.action() != null) {
+                soapAction = webMethod.action();
+            }
+        }
         Body body = new Body();
 
         Throwable exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
@@ -145,9 +161,12 @@
      * parameter are not supported. So the interface should be in doc lit bare
      * style.
      * 
-     * @param inputObject object to be put into the SOAP body
-     * @param soapAction for name resolution
-     * @param classResolver for name resolution
+     * @param inputObject
+     *            object to be put into the SOAP body
+     * @param soapAction
+     *            for name resolution
+     * @param classResolver
+     *            for name resolution
      * @return JAXBElement for the body content
      */
     @SuppressWarnings("unchecked")
@@ -178,7 +197,12 @@
      */
     @SuppressWarnings("unchecked")
     private JAXBElement<Fault> createFaultFromException(final Throwable exception,
String soapAction) {
-        QName name = new ExceptionNameStrategy().findQNameForSoapActionOrType(soapAction,
exception.getClass());
+        WebFault webFault = exception.getClass().getAnnotation(WebFault.class);
+        if (webFault == null || webFault.targetNamespace() == null) {
+            throw new RuntimeException("The exception " + exception.getClass().getName()
+                    + " needs to have an WebFault annotation with name and targetNamespace");
+        }
+        QName name = new QName(webFault.targetNamespace(), webFault.name());
         Object faultObject = null;
         try {
             Method method = exception.getClass().getMethod("getFaultInfo");
@@ -187,9 +211,7 @@
             throw new RuntimeCamelException("Exception while trying to get fault details",
e);
         }
         Fault fault = new Fault();
-        fault
-                .setFaultcode(new QName(exception.getClass().getPackage().getName(), exception.getClass()
-                        .getSimpleName()));
+        fault.setFaultcode(FAULT_CODE_SERVER);
         fault.setFaultstring(exception.getMessage());
         Detail detailEl = new ObjectFactory().createDetail();
         JAXBElement<?> faultDetailContent = new JAXBElement(name, faultObject.getClass(),
faultObject);
@@ -208,7 +230,51 @@
         }
         Envelope envelope = (Envelope) rootObject;
         Object payloadEl = envelope.getBody().getAny().get(0);
-        return (isIgnoreJAXBElement()) ? JAXBIntrospector.getValue(payloadEl) : payloadEl;
+        Object payload = JAXBIntrospector.getValue(payloadEl);
+        if (payload instanceof Fault) {
+            Exception exception = createExceptionFromFault((Fault) payload);
+            exchange.setException(exception);
+            return null;
+        } else {
+            return isIgnoreJAXBElement() ? payload : payloadEl;
+        }
+    }
+
+    /**
+     * Creates an exception and eventually an embedded bean that contains the
+     * fault detail. The exception class is determined by using the
+     * elementNameStrategy. The qName of the fault detail should match the
+     * WebFault annotation of the Exception class. If no fault detail is set the
+     * a RuntimeCamelException is created.
+     * 
+     * @param fault
+     *            Soap fault
+     * @return created Exception
+     */
+    private Exception createExceptionFromFault(Fault fault) {
+        List<Object> detailList = fault.getDetail().getAny();
+        String message = fault.getFaultstring();
+
+        if (detailList.size() == 0) {
+            return new RuntimeCamelException(message);
+        }
+        JAXBElement<?> detailEl = (JAXBElement<?>) detailList.get(0);
+        Class<? extends Exception> exceptionClass = elementNameStrategy.findExceptionForFaultName(detailEl.getName());
+        Constructor<? extends Exception> messageContructor;
+        Constructor<? extends Exception> constructor;
+
+        try {
+            messageContructor = exceptionClass.getConstructor(String.class);
+            Object detail = JAXBIntrospector.getValue(detailEl);
+            try {
+                constructor = exceptionClass.getConstructor(String.class, detail.getClass());
+                return constructor.newInstance(message, detail);
+            } catch (NoSuchMethodException e) {
+                return messageContructor.newInstance(message);
+            }
+        } catch (Exception e) {
+            throw new RuntimeCamelException(e);
+        }
     }
 
     /**

Modified: camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/ElementNameStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/ElementNameStrategy.java?rev=915775&r1=915774&r2=915775&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/ElementNameStrategy.java
(original)
+++ camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/ElementNameStrategy.java
Wed Feb 24 13:16:17 2010
@@ -31,4 +31,11 @@
      * @return resolved element name
      */
     QName findQNameForSoapActionOrType(String soapAction, Class<?> type);
+    
+    /**
+     * Determine exception class for given SOAP Fault QName
+     * @param faultName
+     * @return
+     */
+    Class<? extends Exception> findExceptionForFaultName(QName faultName);
 }

Modified: camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/QNameStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/QNameStrategy.java?rev=915775&r1=915774&r2=915775&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/QNameStrategy.java
(original)
+++ camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/QNameStrategy.java
Wed Feb 24 13:16:17 2010
@@ -19,25 +19,31 @@
 import javax.xml.namespace.QName;
 
 /**
- * Simply ElementNameStrategy that returns one preset QName
+ * Simply ElementNameStrategy that returns one preset QName. This can be handy
+ * for simple asynchronous calls
  */
 public class QNameStrategy implements ElementNameStrategy {
     private QName elementName;
-    
+
     /**
      * Initialize with one QName
      * 
-     * @param elmentName QName to be used for all finds
+     * @param elmentName
+     *            QName to be used for all finds
      */
     public QNameStrategy(QName elmentName) {
         this.elementName = elmentName;
     }
-    
+
     /**
      * @return preset element name
      */
     public QName findQNameForSoapActionOrType(String soapAction, Class<?> type) {
         return elementName;
     }
-    
+
+    public Class<? extends Exception> findExceptionForFaultName(QName faultName) {
+        throw new UnsupportedOperationException("Exception lookup is not supported for QNameStrategy");
+    }
+
 }

Modified: camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/ServiceInterfaceStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/ServiceInterfaceStrategy.java?rev=915775&r1=915774&r2=915775&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/ServiceInterfaceStrategy.java
(original)
+++ camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/ServiceInterfaceStrategy.java
Wed Feb 24 13:16:17 2010
@@ -27,6 +27,7 @@
 import javax.xml.namespace.QName;
 import javax.xml.ws.RequestWrapper;
 import javax.xml.ws.ResponseWrapper;
+import javax.xml.ws.WebFault;
 
 import org.apache.camel.RuntimeCamelException;
 
@@ -40,6 +41,7 @@
     private Map<String, QName> outTypeNameToQName = new HashMap<String, QName>();
     private boolean isClient;
     private ElementNameStrategy fallBackStrategy;
+    private Map<QName, Class<? extends Exception>> faultNameToException = new
HashMap<QName, Class<? extends Exception>>();
 
     /**
      * Init with JAX-WS service interface
@@ -115,6 +117,19 @@
                 soapActionToMethodInfo.put(info.getSoapAction(), info);
             }
             outTypeNameToQName.put(info.getOut().getTypeName(), info.getOut().getElName());
+            addExceptions(method);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private void addExceptions(Method method) {
+        Class<?>[] exTypes = method.getExceptionTypes();
+        for (Class<?> exType : exTypes) {
+            WebFault webFault = exType.getAnnotation(WebFault.class);
+            if (webFault != null) {
+                QName faultName = new QName(webFault.targetNamespace(), webFault.name());
+                faultNameToException.put(faultName, (Class<? extends Exception>) exType);
+            }
         }
     }
 
@@ -153,4 +168,9 @@
         }
         return qName;
     }
+
+    public Class<? extends Exception> findExceptionForFaultName(QName faultName) {
+        return faultNameToException.get(faultName);
+    }
+
 }

Modified: camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/TypeNameStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/TypeNameStrategy.java?rev=915775&r1=915774&r2=915775&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/TypeNameStrategy.java
(original)
+++ camel/trunk/components/camel-soap/src/main/java/org/apache/camel/dataformat/soap/name/TypeNameStrategy.java
Wed Feb 24 13:16:17 2010
@@ -21,14 +21,14 @@
 import javax.xml.namespace.QName;
 
 /**
- * Strategy to determine the marshalled element name by looking at the annotations of the
- * class to be marshalled
+ * Strategy to determine the marshalled element name by looking at the
+ * annotations of the class to be marshalled
  */
 public class TypeNameStrategy implements ElementNameStrategy {
 
     /**
-     * @return determine element name by using the XmlType.name() of the type to be
-     * marshalled and the XmlSchema.namespace() of the package-info
+     * @return determine element name by using the XmlType.name() of the type to
+     *         be marshalled and the XmlSchema.namespace() of the package-info
      */
     public QName findQNameForSoapActionOrType(String soapAction, Class<?> type) {
         XmlType xmlType = type.getAnnotation(XmlType.class);
@@ -44,5 +44,9 @@
         }
         return new QName(nameSpace, xmlType.name());
     }
-    
+
+    public Class<? extends Exception> findExceptionForFaultName(QName faultName) {
+        throw new UnsupportedOperationException("Exception lookup is not supported for TypeNameStrategy");
+    }
+
 }

Modified: camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapClientTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapClientTest.java?rev=915775&r1=915774&r2=915775&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapClientTest.java
(original)
+++ camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapClientTest.java
Wed Feb 24 13:16:17 2010
@@ -26,16 +26,14 @@
 import com.example.customerservice.GetCustomersByNameResponse;
 
 import org.apache.camel.Endpoint;
-import org.apache.camel.EndpointInject;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.Produce;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.bean.ProxyHelper;
-import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.dataformat.soap.name.ElementNameStrategy;
-import org.apache.camel.dataformat.soap.name.TypeNameStrategy;
+import org.apache.camel.dataformat.soap.name.ServiceInterfaceStrategy;
 import org.apache.camel.test.CamelTestSupport;
 
 public class SoapClientTest extends CamelTestSupport {
@@ -51,8 +49,6 @@
         }
     }
 
-    @EndpointInject(uri = "mock:result")
-    protected MockEndpoint resultEndpoint;
     protected CustomerService proxy;
 
     @Produce(uri = "direct:start")
@@ -80,12 +76,12 @@
 
             @Override
             public void configure() throws Exception {
-                ElementNameStrategy elNameStrat = new TypeNameStrategy();
+                ElementNameStrategy elNameStrat = new ServiceInterfaceStrategy(CustomerService.class,
true);
                 SoapJaxbDataFormat soapDataFormat = new SoapJaxbDataFormat(
                         jaxbPackage, elNameStrat);
                 final InputStream in = this.getClass().getResourceAsStream(
                         "response.xml");
-                from("direct:start").marshal(soapDataFormat).to("mock:result")
+                from("direct:start").marshal(soapDataFormat)
                         .process(new FileReplyProcessor(in)).unmarshal(
                                 soapDataFormat);
             }

Added: camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfClientTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfClientTest.java?rev=915775&view=auto
==============================================================================
--- camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfClientTest.java
(added)
+++ camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfClientTest.java
Wed Feb 24 13:16:17 2010
@@ -0,0 +1,84 @@
+/**
+ * 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.camel.dataformat.soap;
+
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import com.example.customerservice.Customer;
+import com.example.customerservice.CustomerService;
+import com.example.customerservice.GetCustomersByName;
+import com.example.customerservice.GetCustomersByNameResponse;
+import com.example.customerservice.NoSuchCustomer;
+import com.example.customerservice.NoSuchCustomerException;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.dataformat.soap.name.ElementNameStrategy;
+import org.apache.camel.dataformat.soap.name.TypeNameStrategy;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration
+public class SoapCxfClientTest extends RouteBuilder {
+    @Resource(name = "customerServiceCxfProxy")
+    protected CustomerService customerService;
+
+    @Test
+    public void testSuccess() throws NoSuchCustomerException {
+        GetCustomersByName request = new GetCustomersByName();
+        request.setName("test");
+        GetCustomersByNameResponse response = customerService.getCustomersByName(request);
+        Assert.assertNotNull(response);
+        List<Customer> customers = response.getReturn();
+        Assert.assertEquals(1, customers.size());
+        Assert.assertEquals("test", customers.get(0).getName());
+    }
+
+    @Test
+    public void testFault() {
+        GetCustomersByName request = new GetCustomersByName();
+        request.setName("none");
+        try {
+            customerService.getCustomersByName(request);
+            Assert.fail("NoSuchCustomerException expected");
+        } catch (NoSuchCustomerException e) {
+            NoSuchCustomer info = e.getFaultInfo();
+            Assert.assertEquals("none", info.getCustomerId());
+        }
+
+    }
+
+    public void configure() throws Exception {
+        String jaxbPackage = GetCustomersByName.class.getPackage().getName();
+        ElementNameStrategy elNameStrat = new TypeNameStrategy();
+        SoapJaxbDataFormat soapDataFormat = new SoapJaxbDataFormat(jaxbPackage, elNameStrat);
+        CustomerServerBean serverBean = new CustomerServerBean();
+        from("direct:cxfclient").onException(Exception.class) // 
+                .handled(true) //
+                .marshal(soapDataFormat) //
+                .end() //
+                .unmarshal(soapDataFormat) //
+                .bean(serverBean) //
+                .marshal(soapDataFormat);
+    }
+
+}

Propchange: camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfClientTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfClientTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfServerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfServerTest.java?rev=915775&view=auto
==============================================================================
--- camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfServerTest.java
(added)
+++ camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfServerTest.java
Wed Feb 24 13:16:17 2010
@@ -0,0 +1,89 @@
+/**
+ * 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.camel.dataformat.soap;
+
+import java.util.List;
+
+import com.example.customerservice.Customer;
+import com.example.customerservice.CustomerService;
+import com.example.customerservice.GetCustomersByName;
+import com.example.customerservice.GetCustomersByNameResponse;
+import com.example.customerservice.NoSuchCustomer;
+import com.example.customerservice.NoSuchCustomerException;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.bean.ProxyHelper;
+import org.apache.camel.component.direct.DirectEndpoint;
+import org.apache.camel.dataformat.soap.name.ElementNameStrategy;
+import org.apache.camel.dataformat.soap.name.ServiceInterfaceStrategy;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration
+public class SoapCxfServerTest extends RouteBuilder {
+    protected CustomerService customerServiceProxy;
+
+    @EndpointInject(uri = "direct:camelClient")
+    protected DirectEndpoint clientEndpoint;
+
+    @SuppressWarnings("unchecked")
+    @Before
+    public void init() throws Exception {
+        customerServiceProxy = ProxyHelper.createProxy(clientEndpoint, CustomerService.class);
+    }
+
+    @Test
+    public void testSuccess() throws NoSuchCustomerException {
+        GetCustomersByName request = new GetCustomersByName();
+        request.setName("test");
+        GetCustomersByNameResponse response = customerServiceProxy.getCustomersByName(request);
+        Assert.assertNotNull(response);
+        List<Customer> customers = response.getReturn();
+        Assert.assertEquals(1, customers.size());
+        Assert.assertEquals("test", customers.get(0).getName());
+    }
+
+    @Test
+    public void testFault() {
+        GetCustomersByName request = new GetCustomersByName();
+        request.setName("none");
+        try {
+            customerServiceProxy.getCustomersByName(request);
+            Assert.fail("NoSuchCustomerException expected");
+        } catch (NoSuchCustomerException e) {
+            NoSuchCustomer info = e.getFaultInfo();
+            Assert.assertEquals("none", info.getCustomerId());
+        }
+    }
+
+    public void configure() throws Exception {
+        String jaxbPackage = GetCustomersByName.class.getPackage().getName();
+        ElementNameStrategy elNameStrat = new ServiceInterfaceStrategy(CustomerService.class,
true);
+        SoapJaxbDataFormat soapDataFormat = new SoapJaxbDataFormat(jaxbPackage, elNameStrat);
+        from("direct:camelClient").onException(NoSuchCustomerException.class).handled(true).unmarshal(soapDataFormat)
+                .end().marshal(soapDataFormat) //
+                .to("direct:cxfEndpoint") //
+                .unmarshal(soapDataFormat);
+    }
+
+}

Propchange: camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfServerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfServerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java?rev=915775&r1=915774&r2=915775&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java
(original)
+++ camel/trunk/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java
Wed Feb 24 13:16:17 2010
@@ -29,8 +29,6 @@
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.dataformat.soap.name.ElementNameStrategy;
-import org.apache.camel.dataformat.soap.name.TypeNameStrategy;
 import org.apache.camel.test.CamelTestSupport;
 
 public class SoapUnMarshalTest extends CamelTestSupport {

Added: camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapCxfClientTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapCxfClientTest-context.xml?rev=915775&view=auto
==============================================================================
--- camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapCxfClientTest-context.xml
(added)
+++ camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapCxfClientTest-context.xml
Wed Feb 24 13:16:17 2010
@@ -0,0 +1,46 @@
+<?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="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xmlns:context="http://www.springframework.org/schema/context"
+	xmlns:jaxws="http://cxf.apache.org/jaxws"
+	xmlns:customer="http://customerservice.example.com/"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
+		http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
+		http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
+		http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+">
+
+	<import resource="classpath:META-INF/cxf/cxf.xml" />
+	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
+	<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
+	<import resource="classpath:META-INF/cxf/cxf-extension-camel.xml" />
+
+	<jaxws:client id="customerServiceCxfProxy" 
+		serviceName="customer:CustomerServiceService" 
+		endpointName="customer:CustomerServiceEndpoint"
+		address="camel://direct:cxfclient" 
+		serviceClass="com.example.customerservice.CustomerService">
+	</jaxws:client>
+	
+	<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
+		<routeBuilder ref="testClass" />    
+	</camelContext>
+	
+	<bean id="testClass" class="org.apache.camel.dataformat.soap.SoapCxfClientTest"/>
+</beans>

Propchange: camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapCxfClientTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapCxfClientTest-context.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapCxfClientTest-context.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapCxfServerTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapCxfServerTest-context.xml?rev=915775&view=auto
==============================================================================
--- camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapCxfServerTest-context.xml
(added)
+++ camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapCxfServerTest-context.xml
Wed Feb 24 13:16:17 2010
@@ -0,0 +1,48 @@
+<?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="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xmlns:context="http://www.springframework.org/schema/context"
+	xmlns:jaxws="http://cxf.apache.org/jaxws"
+	xmlns:customer="http://customerservice.example.com/"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
+		http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
+		http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
+		http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+">
+
+	<import resource="classpath:META-INF/cxf/cxf.xml" />
+	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
+	<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
+	<import resource="classpath:META-INF/cxf/cxf-extension-camel.xml" />
+
+	<bean id="serviceImpl" class="org.apache.camel.dataformat.soap.CustomerServerBean"/>
+	
+	<jaxws:endpoint id="customerServiceEndpoint" 
+		serviceName="customer:CustomerServiceService" 
+		endpointName="customer:CustomerServiceEndpoint"
+		address="camel://direct:cxfEndpoint" 
+		implementor="#serviceImpl"
+	/>
+	
+	<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
+		<routeBuilder ref="testClass" />    
+	</camelContext>
+	
+	<bean id="testClass" class="org.apache.camel.dataformat.soap.SoapCxfServerTest"/>
+</beans>

Propchange: camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapCxfServerTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapCxfServerTest-context.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapCxfServerTest-context.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapMarshalTestExpectedFault.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapMarshalTestExpectedFault.xml?rev=915775&r1=915774&r2=915775&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapMarshalTestExpectedFault.xml
(original)
+++ camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/SoapMarshalTestExpectedFault.xml
Wed Feb 24 13:16:17 2010
@@ -2,7 +2,7 @@
 <ns2:Envelope xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns3="http://customerservice.example.com/">
     <ns2:Body>
         <ns2:Fault>
-            <faultcode xmlns:ns4="com.example.customerservice">ns4:NoSuchCustomerException</faultcode>
+            <faultcode xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">ns4:Receiver</faultcode>
             <faultstring>No customer found</faultstring>
             <detail>
                 <ns3:NoSuchCustomer>

Modified: camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/responseFault.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/responseFault.xml?rev=915775&r1=915774&r2=915775&view=diff
==============================================================================
--- camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/responseFault.xml
(original)
+++ camel/trunk/components/camel-soap/src/test/resources/org/apache/camel/dataformat/soap/responseFault.xml
Wed Feb 24 13:16:17 2010
@@ -2,7 +2,7 @@
 <ns2:Envelope xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns3="http://customerservice.example.com/">
     <ns2:Body>
         <ns2:Fault>
-            <faultcode xmlns:ns4="com.example.customerservice">ns4:NoSuchCustomerException</faultcode>
+            <faultcode xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">ns4:Receiver</faultcode>
             <faultstring>Customer not found</faultstring>
             <detail>
                 <ns3:NoSuchCustomer>



Mime
View raw message