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/12/08 05:27:07 UTC

[3/4] camel git commit: CAMEL-8128 Polish the example to show how to setup the camel context registry

CAMEL-8128 Polish the example to show how to setup the camel context registry


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

Branch: refs/heads/master
Commit: 8d98c900e83698b1f068df7cd0a86a4b9bdaa7cb
Parents: f60a8c9
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Dec 8 11:51:09 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Dec 8 12:26:53 2014 +0800

----------------------------------------------------------------------
 .../example/servletlistener/HelloBean.java      | 27 +++++++++
 .../example/servletlistener/MyLifecycle.java    | 61 ++++++++++++++++++++
 .../src/main/resources/camel-config.xml         |  4 +-
 .../src/main/webapp/WEB-INF/web.xml             |  8 +++
 4 files changed, 97 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8d98c900/examples/camel-example-servlet-tomcat-no-spring/src/main/java/org/apache/camel/example/servletlistener/HelloBean.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-servlet-tomcat-no-spring/src/main/java/org/apache/camel/example/servletlistener/HelloBean.java b/examples/camel-example-servlet-tomcat-no-spring/src/main/java/org/apache/camel/example/servletlistener/HelloBean.java
new file mode 100644
index 0000000..3912711
--- /dev/null
+++ b/examples/camel-example-servlet-tomcat-no-spring/src/main/java/org/apache/camel/example/servletlistener/HelloBean.java
@@ -0,0 +1,27 @@
+/**
+ * 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.example.servletlistener;
+
+import org.apache.camel.Header;
+
+public class HelloBean {
+    
+    public String sayHello(@Header("name")String name) {
+        return "Hello " + name + ", how are you?";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/8d98c900/examples/camel-example-servlet-tomcat-no-spring/src/main/java/org/apache/camel/example/servletlistener/MyLifecycle.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-servlet-tomcat-no-spring/src/main/java/org/apache/camel/example/servletlistener/MyLifecycle.java b/examples/camel-example-servlet-tomcat-no-spring/src/main/java/org/apache/camel/example/servletlistener/MyLifecycle.java
new file mode 100644
index 0000000..3a23c2a
--- /dev/null
+++ b/examples/camel-example-servlet-tomcat-no-spring/src/main/java/org/apache/camel/example/servletlistener/MyLifecycle.java
@@ -0,0 +1,61 @@
+/**
+ * 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.example.servletlistener;
+
+import org.apache.camel.component.servletlistener.CamelContextLifecycle;
+import org.apache.camel.component.servletlistener.ServletCamelContext;
+import org.apache.camel.impl.JndiRegistry;
+
+public class MyLifecycle implements CamelContextLifecycle<JndiRegistry> {
+
+    @Override
+    public void beforeStart(ServletCamelContext camelContext, JndiRegistry registry) throws Exception {
+        // enlist our bean(s) in the registry
+        registry.bind("myBean", new HelloBean());
+        
+    }
+    
+    @Override
+    public void beforeStop(ServletCamelContext camelContext, JndiRegistry registry) throws Exception {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void afterStop(ServletCamelContext camelContext, JndiRegistry registry) throws Exception {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void beforeAddRoutes(ServletCamelContext camelContext, JndiRegistry registry) throws Exception {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void afterAddRoutes(ServletCamelContext camelContext, JndiRegistry registry) throws Exception {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void afterStart(ServletCamelContext camelContext, JndiRegistry registry) throws Exception {
+        // TODO Auto-generated method stub
+        
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/8d98c900/examples/camel-example-servlet-tomcat-no-spring/src/main/resources/camel-config.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-servlet-tomcat-no-spring/src/main/resources/camel-config.xml b/examples/camel-example-servlet-tomcat-no-spring/src/main/resources/camel-config.xml
index 8bc495b..b99bae2 100755
--- a/examples/camel-example-servlet-tomcat-no-spring/src/main/resources/camel-config.xml
+++ b/examples/camel-example-servlet-tomcat-no-spring/src/main/resources/camel-config.xml
@@ -30,9 +30,7 @@
         <!-- is there a header with the key name? -->
         <header>name</header>
         <!-- yes so return back a message to the user -->
-        <transform>
-          <simple>Hello ${header.name} how are you?</simple>
-        </transform>
+        <to uri="bean:myBean"/>
       </when>
       <otherwise>
         <!-- if no name parameter then output a syntax to the user -->

http://git-wip-us.apache.org/repos/asf/camel/blob/8d98c900/examples/camel-example-servlet-tomcat-no-spring/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-servlet-tomcat-no-spring/src/main/webapp/WEB-INF/web.xml b/examples/camel-example-servlet-tomcat-no-spring/src/main/webapp/WEB-INF/web.xml
index d89109d..5192920 100755
--- a/examples/camel-example-servlet-tomcat-no-spring/src/main/webapp/WEB-INF/web.xml
+++ b/examples/camel-example-servlet-tomcat-no-spring/src/main/webapp/WEB-INF/web.xml
@@ -36,6 +36,14 @@
     <!-- note: instead of using a XML file we can also define the routes in Java code in a RouteBuilder class -->
     <param-value>classpath:camel-config.xml</param-value>
   </context-param>
+  <context-param>
+    <!-- define a lifecycle which could help user to setup the registry which could be use as a reference in camel route -->
+    <!-- If you use org.apache.camel.component.servletlistener.JndiCamelServletContextListener then the CamelContextLifecycle
+     must use the JndiRegistry as well. And likewise if the servlet is org.apache.camel.component.servletlistener.SimpleCamelServletContextListener 
+     then the CamelContextLifecycle must use the SimpleRegistry -->
+    <param-name>CamelContextLifecycle</param-name>
+    <param-value>org.apache.camel.example.servletlistener.MyLifecycle</param-value>
+  </context-param>
 
   <!-- the listener that kick-starts Camel -->
   <listener>