Author: davsclaus
Date: Mon Dec 31 10:37:41 2012
New Revision: 1427073
URL: http://svn.apache.org/viewvc?rev=1427073&view=rev
Log:
CAMEL-5906: Added new camel-servletlistener component for bootstrapping Camel
in web app without using spring etc. Work in progress.
Added:
camel/trunk/components/camel-servletlistener/
camel/trunk/components/camel-servletlistener/pom.xml (with props)
camel/trunk/components/camel-servletlistener/src/
camel/trunk/components/camel-servletlistener/src/main/
camel/trunk/components/camel-servletlistener/src/main/java/
camel/trunk/components/camel-servletlistener/src/main/java/org/
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelContextLifecycle.java
(with props)
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelContextServletListener.java
(with props)
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/ServletCamelContext.java
(with props)
camel/trunk/components/camel-servletlistener/src/main/resources/
camel/trunk/components/camel-servletlistener/src/test/
camel/trunk/components/camel-servletlistener/src/test/java/
camel/trunk/components/camel-servletlistener/src/test/java/org/
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/CamelContextServletListenerTest.java
(with props)
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/MyRoute.java
(with props)
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/ServletCamelTestSupport.java
(with props)
camel/trunk/components/camel-servletlistener/src/test/resources/
camel/trunk/components/camel-servletlistener/src/test/resources/log4j.properties
(with props)
camel/trunk/components/camel-servletlistener/src/test/resources/myweb.xml
(with props)
Modified:
camel/trunk/components/pom.xml
Added: camel/trunk/components/camel-servletlistener/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-servletlistener/pom.xml?rev=1427073&view=auto
==============================================================================
--- camel/trunk/components/camel-servletlistener/pom.xml (added)
+++ camel/trunk/components/camel-servletlistener/pom.xml Mon Dec 31 10:37:41
2012
@@ -0,0 +1,89 @@
+<?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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>2.11-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-servletlistener</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: Servlet Listener</name>
+ <description>Camel servlet listener for bootstrapping Camel in Web
Applications</description>
+
+ <properties>
+
<camel.osgi.export.pkg>org.apache.camel.component.servletlistener.*</camel.osgi.export.pkg>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-servlet_2.5_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- test dependencies -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>httpunit</groupId>
+ <artifactId>httpunit</artifactId>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <forkMode>pertest</forkMode>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Propchange: camel/trunk/components/camel-servletlistener/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-servletlistener/pom.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-servletlistener/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added:
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelContextLifecycle.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelContextLifecycle.java?rev=1427073&view=auto
==============================================================================
---
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelContextLifecycle.java
(added)
+++
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelContextLifecycle.java
Mon Dec 31 10:37:41 2012
@@ -0,0 +1,35 @@
+/**
+ * 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.servletlistener;
+
+import org.apache.camel.util.jndi.JndiContext;
+
+/**
+ * A callback lifecycle allows end users to implement custom logic before
+ * the {@link ServletCamelContext} is started and stopped.
+ */
+public interface CamelContextLifecycle {
+
+ void preStart(ServletCamelContext camelContext, JndiContext jndi) throws
Exception;
+
+ void postStart(ServletCamelContext camelContext, JndiContext jndi) throws
Exception;
+
+ void preStop(ServletCamelContext camelContext, JndiContext jndi) throws
Exception;
+
+ void postStop(ServletCamelContext camelContext, JndiContext jndi) throws
Exception;
+
+}
Propchange:
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelContextLifecycle.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelContextLifecycle.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelContextServletListener.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelContextServletListener.java?rev=1427073&view=auto
==============================================================================
---
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelContextServletListener.java
(added)
+++
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelContextServletListener.java
Mon Dec 31 10:37:41 2012
@@ -0,0 +1,207 @@
+/**
+ * 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.servletlistener;
+
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import javax.naming.NamingException;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.jndi.JndiContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A {@link ServletContextListener} which is used to bootstrap
+ * {@link org.apache.camel.CamelContext} in web applications.
+ */
+public class CamelContextServletListener implements ServletContextListener {
+
+ // TODO: Refactor the init method into smaller methods
+ // TODO: Allow to lookup and configure some of the stuff we do in
camel-core-xml
+ // more easily with this listener as well
+ // TODO: Add more tests
+ // TODO: Lookup jndi and have expected type, and fail if not matching type
+ // TODO: Consider CamelContextLifecycle as a SPI in camel-core to make it
easier for
+ // everyone to do some custom code when Camel starts/stops. Though you can
use an EventListener
+ // but maybe this SPI is even easier and more common to use
+
+ public static ServletCamelContext instance;
+
+ private static final Logger LOG =
LoggerFactory.getLogger(CamelContextServletListener.class);
+ private JndiContext jndiContext;
+ private ServletCamelContext camelContext;
+ private CamelContextLifecycle camelContextLifecycle;
+ private boolean test;
+
+ @Override
+ public void contextInitialized(ServletContextEvent sce) {
+ LOG.info("CamelContextServletListener initializing ...");
+
+ try {
+ jndiContext = new JndiContext();
+ camelContext = new ServletCamelContext(jndiContext,
sce.getServletContext());
+ } catch (Exception e) {
+ LOG.error("Error creating CamelContext.", e);
+ throw new RuntimeException("Error creating CamelContext.", e);
+ }
+
+ // configure CamelContext with the init parameter
+ Map<String, Object> map = new LinkedHashMap<String, Object>();
+ Enumeration names = sce.getServletContext().getInitParameterNames();
+ while (names.hasMoreElements()) {
+ String name = (String) names.nextElement();
+ String value = sce.getServletContext().getInitParameter(name);
+
+ if (ObjectHelper.isNotEmpty(value)) {
+ Object target = value;
+ if (value.startsWith("#")) {
+ // a reference lookup in jndi
+ value = value.substring(1);
+ target = lookupJndi(jndiContext, value);
+ }
+ map.put(name, target);
+ }
+ }
+
+ // special for test parameter
+ String test = (String) map.remove("test");
+ if (test != null && "true".equalsIgnoreCase(test)) {
+ this.test = true;
+ }
+ LOG.trace("In test mode? {}", this.test);
+
+ if (!map.isEmpty()) {
+ try {
+ IntrospectionSupport.setProperties(camelContext, map);
+ } catch (Exception e) {
+ throw new RuntimeException("Error setting init parameters on
CamelContext.", e);
+ }
+ }
+
+ Set<String> routeBuilders = new HashSet<String>();
+ for (Map.Entry<String, Object> entry : map.entrySet()) {
+ if
(entry.getKey().toLowerCase(Locale.UK).startsWith("routebuilder")) {
+ routeBuilders.add(entry.getKey());
+ String value = (String) entry.getValue();
+ if (ObjectHelper.isNotEmpty(value)) {
+ Object target;
+ if (value.startsWith("#")) {
+ // a reference lookup in jndi
+ value = value.substring(1);
+ target = lookupJndi(jndiContext, value);
+ } else {
+ try {
+ Class<RouteBuilder> clazz =
camelContext.getClassResolver().resolveMandatoryClass(value,
RouteBuilder.class);
+ target =
camelContext.getInjector().newInstance(clazz);
+ } catch (Exception e) {
+ throw new RuntimeException("Error creating
RouteBuilder " + value, e);
+ }
+ }
+ if (target instanceof RouteBuilder) {
+ LOG.debug("Adding RouteBuilder {} -> {}",
entry.getKey(), target);
+ try {
+ camelContext.addRoutes((RoutesBuilder) target);
+ } catch (Exception e) {
+ throw new RuntimeException("Error adding
RouteBuilder " + value, e);
+ }
+ }
+ }
+ }
+ }
+
+ // after adding the route builders we should remove them from the map
+ for (String name : routeBuilders) {
+ map.remove(name);
+ }
+
+ // validate that we could set all the init parameters
+ if (!map.isEmpty()) {
+ throw new IllegalArgumentException("Error setting init parameters
on CamelContext."
+ + " There are " + map.size() + " unknown parameters. [" +
map + "]");
+ }
+
+ // Any custom CamelContextLifecycle
+ String lifecycle = (String)
map.remove(CamelContextLifecycle.class.getName());
+ if (lifecycle != null) {
+ try {
+ Class<CamelContextLifecycle> clazz =
camelContext.getClassResolver().resolveMandatoryClass(lifecycle,
CamelContextLifecycle.class);
+ camelContextLifecycle =
camelContext.getInjector().newInstance(clazz);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Error creating
CamelContextLifecycle class with name " + lifecycle, e);
+ }
+ }
+
+ try {
+ if (camelContextLifecycle != null) {
+ camelContextLifecycle.preStart(camelContext, jndiContext);
+ }
+ camelContext.start();
+ if (camelContextLifecycle != null) {
+ camelContextLifecycle.postStart(camelContext, jndiContext);
+ }
+ } catch (Exception e) {
+ LOG.error("Error starting CamelContext.", e);
+ throw new RuntimeException("Error starting CamelContext.", e);
+ }
+
+ if (this.test) {
+ instance = camelContext;
+ }
+
+ LOG.info("CamelContextServletListener initialized");
+ }
+
+ private static Object lookupJndi(JndiContext jndiContext, String name) {
+ try {
+ return jndiContext.lookup(name);
+ } catch (NamingException e) {
+ throw new RuntimeException("Error looking up in jndi with name: "
+ name, e);
+ }
+ }
+
+ @Override
+ public void contextDestroyed(ServletContextEvent sce) {
+ LOG.info("CamelContextServletListener destroying ...");
+ if (camelContext != null) {
+ try {
+ if (camelContextLifecycle != null) {
+ camelContextLifecycle.preStop(camelContext, jndiContext);
+ }
+ camelContext.stop();
+ if (camelContextLifecycle != null) {
+ camelContextLifecycle.postStop(camelContext, jndiContext);
+ }
+ } catch (Exception e) {
+ LOG.warn("Error stopping CamelContext. This exception will be
ignored.", e);
+ }
+ }
+ camelContext = null;
+ jndiContext = null;
+ instance = null;
+ LOG.info("CamelContextServletListener destroyed");
+ }
+}
Propchange:
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelContextServletListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/CamelContextServletListener.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/ServletCamelContext.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/ServletCamelContext.java?rev=1427073&view=auto
==============================================================================
---
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/ServletCamelContext.java
(added)
+++
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/ServletCamelContext.java
Mon Dec 31 10:37:41 2012
@@ -0,0 +1,35 @@
+/**
+ * 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.servletlistener;
+
+import javax.naming.Context;
+import javax.servlet.ServletContext;
+
+import org.apache.camel.impl.DefaultCamelContext;
+
+/**
+ * A servlet based {@link org.apache.camel.CamelContext}.
+ */
+public class ServletCamelContext extends DefaultCamelContext {
+
+ private final ServletContext servletContext;
+
+ public ServletCamelContext(Context jndiContext, ServletContext
servletContext) {
+ super(jndiContext);
+ this.servletContext = servletContext;
+ }
+}
Propchange:
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/ServletCamelContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-servletlistener/src/main/java/org/apache/camel/component/servletlistener/ServletCamelContext.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/CamelContextServletListenerTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/CamelContextServletListenerTest.java?rev=1427073&view=auto
==============================================================================
---
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/CamelContextServletListenerTest.java
(added)
+++
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/CamelContextServletListenerTest.java
Mon Dec 31 10:37:41 2012
@@ -0,0 +1,46 @@
+/**
+ * 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.servletlistener;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class CamelContextServletListenerTest extends ServletCamelTestSupport {
+
+ @Test
+ public void testCamelContext() throws Exception {
+ CamelContext context = getCamelContext();
+ assertNotNull(context);
+
+ assertEquals("MyCamel", context.getName());
+
+ ProducerTemplate template = context.createProducerTemplate();
+
+ MockEndpoint mock = context.getEndpoint("mock:foo",
MockEndpoint.class);
+ mock.expectedMessageCount(1);
+
+ template.sendBody("seda:foo", "Hello World");
+
+ mock.assertIsSatisfied();
+ template.stop();
+ }
+}
Propchange:
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/CamelContextServletListenerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/CamelContextServletListenerTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/MyRoute.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/MyRoute.java?rev=1427073&view=auto
==============================================================================
---
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/MyRoute.java
(added)
+++
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/MyRoute.java
Mon Dec 31 10:37:41 2012
@@ -0,0 +1,31 @@
+/**
+ * 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.servletlistener;
+
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ *
+ */
+public class MyRoute extends RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ from("seda:foo").routeId("foo")
+ .to("mock:foo");
+ }
+}
Propchange:
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/MyRoute.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/MyRoute.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/ServletCamelTestSupport.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/ServletCamelTestSupport.java?rev=1427073&view=auto
==============================================================================
---
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/ServletCamelTestSupport.java
(added)
+++
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/ServletCamelTestSupport.java
Mon Dec 31 10:37:41 2012
@@ -0,0 +1,62 @@
+/**
+ * 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.servletlistener;
+
+import java.io.InputStream;
+
+import com.meterware.httpunit.HttpUnitOptions;
+import com.meterware.servletunit.ServletRunner;
+import org.apache.camel.test.junit4.TestSupport;
+import org.junit.After;
+import org.junit.Before;
+
+/**
+ *
+ */
+public class ServletCamelTestSupport extends TestSupport {
+ public static final String CONTEXT = "/mycontext";
+ public static final String CONTEXT_URL = "http://localhost/mycontext";
+ protected ServletRunner sr;
+
+ @Before
+ public void setUp() throws Exception {
+ InputStream is =
this.getClass().getResourceAsStream(getConfiguration());
+ assertNotNull("The configuration input stream should not be null", is);
+ sr = new ServletRunner(is, CONTEXT);
+
+ HttpUnitOptions.setExceptionsThrownOnErrorStatus(true);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ if (sr != null) {
+ sr.shutDown();
+ }
+ }
+
+ /**
+ * @return The web.xml to use for testing.
+ */
+ protected String getConfiguration() {
+ return "/myweb.xml";
+ }
+
+ protected ServletCamelContext getCamelContext() {
+ return CamelContextServletListener.instance;
+ }
+
+}
Propchange:
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/ServletCamelTestSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-servletlistener/src/test/java/org/apache/camel/component/servletlistener/ServletCamelTestSupport.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-servletlistener/src/test/resources/log4j.properties
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-servletlistener/src/test/resources/log4j.properties?rev=1427073&view=auto
==============================================================================
---
camel/trunk/components/camel-servletlistener/src/test/resources/log4j.properties
(added)
+++
camel/trunk/components/camel-servletlistener/src/test/resources/log4j.properties
Mon Dec 31 10:37:41 2012
@@ -0,0 +1,37 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+#
+# The logging properties used
+#
+log4j.rootLogger=INFO, file
+
+#log4j.logger.org.apache.camel.component.servletlistener=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} -
%m%n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} -
%m%n
+log4j.appender.file.file=target/camel-servletlistener-test.log
+log4j.appender.file.append=true
+
+log4j.throwableRenderer=org.apache.log4j.EnhancedThrowableRenderer
\ No newline at end of file
Propchange:
camel/trunk/components/camel-servletlistener/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-servletlistener/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
camel/trunk/components/camel-servletlistener/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: camel/trunk/components/camel-servletlistener/src/test/resources/myweb.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-servletlistener/src/test/resources/myweb.xml?rev=1427073&view=auto
==============================================================================
--- camel/trunk/components/camel-servletlistener/src/test/resources/myweb.xml
(added)
+++ camel/trunk/components/camel-servletlistener/src/test/resources/myweb.xml
Mon Dec 31 10:37:41 2012
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!DOCTYPE web-app
+ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<!--
+ 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.
+-->
+<!-- START SNIPPET: web -->
+<web-app>
+
+ <!-- the test parameter is only to be used for unit testing -->
+ <context-param>
+ <param-name>test</param-name>
+ <param-value>true</param-value>
+ </context-param>
+
+ <!-- you can configure any of the properties on CamelContext, eg setName
will be configured as below -->
+ <context-param>
+ <param-name>name</param-name>
+ <param-value>MyCamel</param-value>
+ </context-param>
+
+ <!-- configure a route builder to use -->
+ <!-- Camel will pickup any parameter names that start with routeBuilder
(case ignored) -->
+ <context-param>
+ <param-name>routeBuilder-MyRoute</param-name>
+
<param-value>org.apache.camel.component.servletlistener.MyRoute</param-value>
+ </context-param>
+
+ <listener>
+
<listener-class>org.apache.camel.component.servletlistener.CamelContextServletListener</listener-class>
+ </listener>
+
+</web-app>
+<!-- END SNIPPET: web -->
\ No newline at end of file
Propchange:
camel/trunk/components/camel-servletlistener/src/test/resources/myweb.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-servletlistener/src/test/resources/myweb.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
camel/trunk/components/camel-servletlistener/src/test/resources/myweb.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified: camel/trunk/components/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/components/pom.xml?rev=1427073&r1=1427072&r2=1427073&view=diff
==============================================================================
--- camel/trunk/components/pom.xml (original)
+++ camel/trunk/components/pom.xml Mon Dec 31 10:37:41 2012
@@ -141,6 +141,7 @@
<module>camel-saxon</module>
<module>camel-script</module>
<module>camel-servlet</module>
+ <module>camel-servletlistener</module>
<module>camel-shiro</module>
<module>camel-sip</module>
<module>camel-smpp</module>