camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1346921 - in /camel/trunk/components/camel-cxf/src: main/java/org/apache/camel/component/cxf/ test/java/org/apache/camel/component/cxf/ test/resources/org/apache/camel/component/cxf/
Date Wed, 06 Jun 2012 14:46:23 GMT
Author: ningjiang
Date: Wed Jun  6 14:46:22 2012
New Revision: 1346921

URL: http://svn.apache.org/viewvc?rev=1346921&view=rev
Log:
CAMEL-5330 supporting camel-cxf provider's null response handling

Added:
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultPayloadProviderSEI.java
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayloadProviderRouterTest.java
    camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfProviderRouterBeans.xml
Modified:
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java?rev=1346921&r1=1346920&r2=1346921&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
(original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
Wed Jun  6 14:46:22 2012
@@ -521,9 +521,18 @@ public class CxfEndpoint extends Default
     ServerFactoryBean createServerFactoryBean() throws Exception {
 
         Class<?> cls = null;
-        if (getDataFormat() == DataFormat.POJO || getServiceClass() != null) {
-            // get service class
+        if (getDataFormat() == DataFormat.POJO) {
             ObjectHelper.notNull(getServiceClass(), CxfConstants.SERVICE_CLASS);
+        }
+        
+        if (getWsdlURL() == null && getServiceClass() == null) {
+            // no WSDL and serviceClass specified, set our default serviceClass
+            if (getDataFormat().equals(DataFormat.PAYLOAD)) {
+                setServiceClass(org.apache.camel.component.cxf.DefaultPayloadProviderSEI.class.getName());
+            }
+        }
+        
+        if (getServiceClass() != null) {
             cls = getServiceClass();
         }
 

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java?rev=1346921&r1=1346920&r2=1346921&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
(original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
Wed Jun  6 14:46:22 2012
@@ -156,7 +156,15 @@ public class CxfSpringEndpoint extends C
         
         // get service class
         Class<?> cls = getSEIClass();                
-                
+        
+        if (getWsdlURL() == null && cls == null) {
+            // no WSDL and serviceClass specified, set our default serviceClass
+            if (getDataFormat().equals(DataFormat.PAYLOAD)) {
+                setServiceClass(org.apache.camel.component.cxf.DefaultPayloadProviderSEI.class.getName());
+            } 
+            cls = getServiceClass();
+        }
+        
         // create server factory bean
         // Shouldn't use CxfEndpointUtils.getServerFactoryBean(cls) as it is for
         // CxfSoapComponent

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java?rev=1346921&r1=1346920&r2=1346921&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
(original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
Wed Jun  6 14:46:22 2012
@@ -50,6 +50,7 @@ import org.apache.cxf.binding.soap.Soap1
 import org.apache.cxf.binding.soap.Soap12;
 import org.apache.cxf.binding.soap.SoapBindingConstants;
 import org.apache.cxf.binding.soap.SoapHeader;
+import org.apache.cxf.common.util.ReflectionUtil;
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.headers.Header;
@@ -60,6 +61,7 @@ import org.apache.cxf.jaxws.context.Wrap
 import org.apache.cxf.message.Attachment;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageContentsList;
+import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.security.SecurityContext;
 import org.apache.cxf.service.Service;
 import org.apache.cxf.service.model.BindingMessageInfo;
@@ -338,7 +340,13 @@ public class DefaultCxfBinding implement
                     LOG.trace("Set Out CXF message content = {}", resList);
                 }
             }
-        }         
+        } else if (!cxfExchange.isOneWay() 
+            && cxfExchange.getInMessage() != null
+            && MessageUtils.isTrue(cxfExchange.getInMessage().getContextualProperty("jaxws.provider.interpretNullAsOneway")))
{ 
+            // treat this non-oneway call as oneway when the provider returns a null
+            changeToOneway(cxfExchange);
+            return;
+        }
         
         // propagate attachments if the data format is not POJO
         if (!DataFormat.POJO.equals(dataFormat)) {
@@ -761,4 +769,19 @@ public class DefaultCxfBinding implement
         
     }
 
+    //TODO replace this method with the cxf util's method when it becomes available
+    private static void changeToOneway(org.apache.cxf.message.Exchange cxfExchange) {
+        cxfExchange.setOneWay(true);
+        Object httpresp = cxfExchange.getInMessage().get("HTTP.RESPONSE");
+        if (httpresp != null) {
+            try {
+                Method m = ReflectionUtil.findMethod(httpresp.getClass(), "setStatus", int.class);
+                if (m != null) {
+                    m.invoke(httpresp, 202);
+                }
+            } catch (Exception e) {
+                LOG.warn("Unable to set the http ", e);
+            }
+        }
+    }
 }

Added: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultPayloadProviderSEI.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultPayloadProviderSEI.java?rev=1346921&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultPayloadProviderSEI.java
(added)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultPayloadProviderSEI.java
Wed Jun  6 14:46:22 2012
@@ -0,0 +1,30 @@
+/**
+ * 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.component.cxf;
+
+import javax.xml.transform.Source;
+import javax.xml.ws.Provider;
+import javax.xml.ws.ServiceMode;
+import javax.xml.ws.WebServiceProvider;
+
+@WebServiceProvider(targetNamespace = "http://camel.apache.org/cxf/jaxws/provider")
+@ServiceMode (value = javax.xml.ws.Service.Mode.PAYLOAD)
+public interface DefaultPayloadProviderSEI extends Provider<Source> {
+    Source invoke(Source request);
+}

Added: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayloadProviderRouterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayloadProviderRouterTest.java?rev=1346921&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayloadProviderRouterTest.java
(added)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayloadProviderRouterTest.java
Wed Jun  6 14:46:22 2012
@@ -0,0 +1,132 @@
+/**
+ * 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.component.cxf;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Endpoint;
+import javax.xml.ws.Service;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.hello_world_soap_http.Greeter;
+import org.apache.hello_world_soap_http.GreeterImpl;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class CxfPayloadProviderRouterTest extends AbstractCXFGreeterRouterTest {
+    protected static Endpoint endpoint;
+    protected static GreeterImpl implementor;
+    
+    private final QName serviceName = new QName("http://apache.org/hello_world_soap_http",
+                                                "SOAPService");
+    private final QName routerPortName = new QName("http://apache.org/hello_world_soap_http",
+                                                "RouterPort");
+    
+    @AfterClass
+    public static void stopService() {
+        if (endpoint != null) {
+            endpoint.stop();
+        }
+    }
+
+    @BeforeClass
+    public static void startService() {
+        implementor = new GreeterImpl();
+        String address = "http://localhost:" + getPort1() + "/CxfPayLoadProviderRouterTest/SoapContext/SoapPort";
+        endpoint = Endpoint.publish(address, implementor); 
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("cxf:bean:routerEndpoint?synchronous=true&dataFormat=PAYLOAD")
+                    .setHeader("operationNamespace", constant("http://camel.apache.org/cxf/jaxws/dispatch"))
+                    .setHeader("operationName", constant("Invoke"))
+                    .to("cxf:bean:serviceEndpoint?synchronous=true&dataFormat=PAYLOAD");
+            }
+        };
+    }
+
+    @Override
+    protected ClassPathXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/CxfProviderRouterBeans.xml");
+    }
+
+    @Test
+    public void testPublishEndpointUrl() throws Exception {
+        final String path = getClass().getSimpleName() + "/CamelContext/RouterPort/" + getClass().getSimpleName();
+        String response = template.requestBody("http://localhost:" + getPort2() + "/" + path
+                                               + "?wsdl", null, String.class);
+        assertTrue("Can't find the right service location.", response.indexOf(path) >
0);
+    }
+
+    @Test
+    public void testInvokeGreetMeOverProvider() throws Exception {
+        Service service = Service.create(serviceName);
+        service.addPort(routerPortName, "http://schemas.xmlsoap.org/soap/",
+                        "http://localhost:" + getPort2() + "/"
+                        + getClass().getSimpleName() + "/CamelContext/RouterPort");
+        Greeter greeter = service.getPort(routerPortName, Greeter.class);
+        org.apache.cxf.endpoint.Client client = org.apache.cxf.frontend.ClientProxy.getClient(greeter);
+        VerifyInboundInterceptor icp = new VerifyInboundInterceptor();
+        client.getInInterceptors().add(icp);
+        
+        int ic = implementor.getInvocationCount();
+
+        icp.setCalled(false);
+        String reply = greeter.greetMe("test");
+        assertEquals("Got the wrong reply ", "Hello test", reply);
+        assertTrue("No Inbound message received", icp.isCalled());
+        assertEquals("The target service not invoked", ++ic, implementor.getInvocationCount());
+        
+        icp.setCalled(false);
+        greeter.greetMeOneWay("call greetMe OneWay !");
+        assertFalse("An unnecessary inbound message", icp.isCalled());
+        // wait a few seconds for the async oneway service to be invoked
+        Thread.sleep(3000);
+        assertEquals("The target service not invoked", ++ic, implementor.getInvocationCount());
+    }
+    
+    static class VerifyInboundInterceptor extends AbstractPhaseInterceptor<Message>
{
+        private boolean called;
+        
+        public VerifyInboundInterceptor() {
+            super(Phase.USER_PROTOCOL);
+        }
+
+        @Override
+        public void handleMessage(Message message) throws Fault {
+            called = true;
+        }
+        
+        public boolean isCalled() {
+            return called;
+        }
+        
+        public void setCalled(boolean b) {
+            called = b;
+        }
+        
+    }
+}

Added: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfProviderRouterBeans.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfProviderRouterBeans.xml?rev=1346921&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfProviderRouterBeans.xml
(added)
+++ camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfProviderRouterBeans.xml
Wed Jun  6 14:46:22 2012
@@ -0,0 +1,36 @@
+<?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:cxf="http://camel.apache.org/schema/cxf"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+
+  <cxf:cxfEndpoint id="routerEndpoint" address="http://localhost:${CXFTestSupport.port2}/CxfPayloadProviderRouterTest/CamelContext/RouterPort">
+    <cxf:properties>
+      <entry key="jaxws.provider.interpretNullAsOneway" value="true"/>
+    </cxf:properties>
+  </cxf:cxfEndpoint>
+
+  <cxf:cxfEndpoint id="serviceEndpoint" address="http://localhost:${CXFTestSupport.port1}/CxfPayLoadProviderRouterTest/SoapContext/SoapPort"/>
+
+</beans>



Mime
View raw message