camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [1/3] git commit: CAMEL-7867 Fixed the NPE when using CXF endpoint to enrich
Date Mon, 29 Sep 2014 13:41:49 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.12.x 5de376a71 -> 80b34607f
  refs/heads/camel-2.13.x 66803bcc6 -> baac16768
  refs/heads/camel-2.14.x 9b1125b9f -> b93772286


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/b9377228
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b9377228
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b9377228

Branch: refs/heads/camel-2.14.x
Commit: b93772286df3a6000765ceb570cf30e8b14111ce
Parents: 9b1125b
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Mon Sep 29 21:12:56 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Mon Sep 29 21:40:38 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/b9377228/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 a4a5e51..39b6089 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/b9377228/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/b9377228/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


Mime
View raw message