You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/09/29 15:41:50 UTC

[2/3] git commit: CAMEL-7867 Fixed the NPE when using CXF endpoint to enrich

CAMEL-7867 Fixed the NPE when using CXF endpoint to enrich


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/baac1676
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/baac1676
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/baac1676

Branch: refs/heads/camel-2.13.x
Commit: baac167688cbd135a56fac78ef0f0492ddb3663b
Parents: 66803bc
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Sep 29 21:12:56 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Sep 29 21:40:55 2014 +0800

----------------------------------------------------------------------
 .../apache/camel/impl/DefaultRouteContext.java  |  7 +++
 .../component/cxf/CXFGreeterEnrichTest.java     | 48 +++++++++++++++
 .../cxf/GreeterEnrichRouterContext.xml          | 61 ++++++++++++++++++++
 3 files changed, 116 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/baac1676/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
index aeb8b91..8109c1f 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
@@ -28,6 +28,7 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.NoSuchEndpointException;
 import org.apache.camel.Processor;
 import org.apache.camel.Route;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.ShutdownRoute;
 import org.apache.camel.ShutdownRunningTask;
 import org.apache.camel.model.FromDefinition;
@@ -123,6 +124,12 @@ public class DefaultRouteContext implements RouteContext {
             if (!this.getCamelContext().equals(endpoint.getCamelContext())) {
                 throw new NoSuchEndpointException("ref:" + ref, "make sure the endpoint has the same camel context as the route does.");
             }
+            try {
+                // need add the endpoint into service
+                getCamelContext().addService(endpoint);
+            } catch (Exception ex) {
+                throw new RuntimeCamelException(ex);
+            }
         }
         if (endpoint == null) {
             throw new IllegalArgumentException("Either 'uri' or 'ref' must be specified on: " + this);

http://git-wip-us.apache.org/repos/asf/camel/blob/baac1676/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFGreeterEnrichTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFGreeterEnrichTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFGreeterEnrichTest.java
new file mode 100644
index 0000000..da4c564
--- /dev/null
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFGreeterEnrichTest.java
@@ -0,0 +1,48 @@
+/**
+ * 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.ws.Endpoint;
+
+import org.apache.hello_world_soap_http.GreeterImpl;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class CXFGreeterEnrichTest extends AbstractCXFGreeterRouterTest {
+    protected static Endpoint endpoint;
+    @AfterClass
+    public static void stopService() {
+        if (endpoint != null) {
+            endpoint.stop();
+        }
+    }
+
+
+    @BeforeClass
+    public static void startService() {
+        Object implementor = new GreeterImpl();
+        String address = "http://localhost:" + getPort1() + "/CXFGreeterEnrichTest/SoapContext/SoapPort"; 
+        endpoint = Endpoint.publish(address, implementor); 
+    }
+
+    protected ClassPathXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/GreeterEnrichRouterContext.xml");
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/baac1676/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/GreeterEnrichRouterContext.xml
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/GreeterEnrichRouterContext.xml b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/GreeterEnrichRouterContext.xml
new file mode 100644
index 0000000..c6ff1c5
--- /dev/null
+++ b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/GreeterEnrichRouterContext.xml
@@ -0,0 +1,61 @@
+<?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"/>
+
+   <!-- START SNIPPET: example -->
+   <cxf:cxfEndpoint id="routerEndpoint" address="http://localhost:${CXFTestSupport.port2}/CXFGreeterEnrichTest/CamelContext/RouterPort"
+    		serviceClass="org.apache.hello_world_soap_http.GreeterImpl"
+    		skipFaultLogging="true">
+        <cxf:outInterceptors>
+            <!-- This interceptor will force the CXF server send the XML start document to client -->
+            <bean class="org.apache.camel.component.cxf.WriteXmlDeclarationInterceptor"/>
+        </cxf:outInterceptors>
+        <cxf:properties>
+            <!-- Set the publishedEndpointUrl which could override the service address from generated WSDL as you want -->
+    	    <entry key="publishedEndpointUrl" value="http://www.simple.com/services/test" />
+    	</cxf:properties>
+   </cxf:cxfEndpoint>
+   <!-- END SNIPPET: example --> 		
+
+   <cxf:cxfEndpoint id="serviceEndpoint" address="http://localhost:${CXFTestSupport.port1}/CXFGreeterEnrichTest/SoapContext/SoapPort"
+    		wsdlURL="testutils/hello_world.wsdl"
+    		serviceClass="org.apache.hello_world_soap_http.Greeter"
+    		endpointName="s:SoapPort"
+    		serviceName="s:SOAPService"
+    	xmlns:s="http://apache.org/hello_world_soap_http" />
+
+   <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+    <route errorHandlerRef="noErrorHandler">
+      <from ref="routerEndpoint" />
+      <enrich ref="serviceEndpoint" />
+    </route>
+   </camelContext>
+
+   <bean id="noErrorHandler" class="org.apache.camel.builder.NoErrorHandlerBuilder"/>
+
+</beans>
\ No newline at end of file