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 2011/01/04 14:22:52 UTC
svn commit: r1055030 - in /camel/trunk:
components/camel-servlet/src/main/java/org/apache/camel/component/servlet/
tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/
tests/camel-itest-osgi/src/test/resources/org/apache/camel/ites...
Author: ningjiang
Date: Tue Jan 4 13:22:51 2011
New Revision: 1055030
URL: http://svn.apache.org/viewvc?rev=1055030&view=rev
Log:
CAMEL-3485 Introduce CXFServletService Interface for camel-servlet component
Added:
camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelServletService.java (with props)
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletServicesTest.java (with props)
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/CamelServletWithServletServiceContext.xml (with props)
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/ServletServiceContext.xml (with props)
Modified:
camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java
camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java
Modified: camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java?rev=1055030&r1=1055029&r2=1055030&view=diff
==============================================================================
--- camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java (original)
+++ camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java Tue Jan 4 13:22:51 2011
@@ -29,7 +29,7 @@ import org.apache.commons.logging.LogFac
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
-public class CamelHttpTransportServlet extends CamelServlet {
+public class CamelHttpTransportServlet extends CamelServlet implements CamelServletService {
private static final transient Log LOG = LogFactory.getLog(CamelHttpTransportServlet.class);
private static final Map<String, CamelServlet> CAMEL_SERVLET_MAP = new ConcurrentHashMap<String, CamelServlet>();
private String servletName;
Added: camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelServletService.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelServletService.java?rev=1055030&view=auto
==============================================================================
--- camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelServletService.java (added)
+++ camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelServletService.java Tue Jan 4 13:22:51 2011
@@ -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.component.servlet;
+
+import org.apache.camel.component.http.HttpConsumer;
+
+public interface CamelServletService {
+
+ void connect(HttpConsumer consumer);
+
+ void disconnect(HttpConsumer consumer);
+
+}
Propchange: camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelServletService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelServletService.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java?rev=1055030&r1=1055029&r2=1055030&view=diff
==============================================================================
--- camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java (original)
+++ camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java Tue Jan 4 13:22:51 2011
@@ -40,9 +40,15 @@ public class ServletComponent extends Ht
private CamelServlet camelServlet;
+ private CamelServletService camelServletService;
+
public void setCamelServlet(CamelServlet servlet) {
camelServlet = servlet;
}
+
+ public void setCamelServletService(CamelServletService service) {
+ camelServletService = service;
+ }
public CamelServlet getCamelServlet(String servletName) {
CamelServlet answer;
@@ -58,6 +64,10 @@ public class ServletComponent extends Ht
return answer;
}
+ public CamelServletService getCamelServletService() {
+ return camelServletService;
+ }
+
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
uri = uri.startsWith("servlet:") ? remaining : uri;
@@ -119,17 +129,25 @@ public class ServletComponent extends Ht
}
public void connect(HttpConsumer consumer) throws Exception {
- ServletEndpoint endpoint = (ServletEndpoint) consumer.getEndpoint();
- CamelServlet servlet = getCamelServlet(endpoint.getServletName());
- ObjectHelper.notNull(servlet, "CamelServlet");
- servlet.connect(consumer);
+ if (getCamelServletService() != null) {
+ getCamelServletService().connect(consumer);
+ } else {
+ ServletEndpoint endpoint = (ServletEndpoint) consumer.getEndpoint();
+ CamelServlet servlet = getCamelServlet(endpoint.getServletName());
+ ObjectHelper.notNull(servlet, "CamelServlet");
+ servlet.connect(consumer);
+ }
}
public void disconnect(HttpConsumer consumer) throws Exception {
- ServletEndpoint endpoint = (ServletEndpoint) consumer.getEndpoint();
- CamelServlet servlet = getCamelServlet(endpoint.getServletName());
- ObjectHelper.notNull(servlet, "CamelServlet");
- servlet.disconnect(consumer);
+ if (getCamelServletService() != null) {
+ getCamelServletService().disconnect(consumer);
+ } else {
+ ServletEndpoint endpoint = (ServletEndpoint) consumer.getEndpoint();
+ CamelServlet servlet = getCamelServlet(endpoint.getServletName());
+ ObjectHelper.notNull(servlet, "CamelServlet");
+ servlet.disconnect(consumer);
+ }
}
}
\ No newline at end of file
Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletServicesTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletServicesTest.java?rev=1055030&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletServicesTest.java (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletServicesTest.java Tue Jan 4 13:22:51 2011
@@ -0,0 +1,75 @@
+/**
+ * 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.itest.osgi.servlet;
+
+import org.apache.camel.itest.osgi.OSGiIntegrationSpringTestSupport;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
+
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.profile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory;
+
+@RunWith(JUnit4TestRunner.class)
+public class ServletServicesTest extends OSGiIntegrationSpringTestSupport {
+
+ @Test
+ public void testSendMessage() {
+ String endpointURI = "http://localhost:9080/camel/services/hello";
+ String response = template.requestBody(endpointURI, "Hello World", String.class);
+ assertEquals("response is " , "Echo Hello World", response);
+ }
+
+ @Configuration
+ public static Option[] configure() {
+ Option[] options = options(
+
+ // install the spring dm profile
+ profile("spring.dm").version("1.2.0"),
+ // need to install some karaf features
+ scanFeatures(getKarafFeatureUrl(), "http", "war"),
+ // set the system property for pax web
+ org.ops4j.pax.exam.CoreOptions.systemProperty("org.osgi.service.http.port").value("9080"),
+
+ // this is how you set the default log level when using pax logging (logProfile)
+ org.ops4j.pax.exam.CoreOptions.systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+
+ // using the features to install the camel components
+ scanFeatures(getCamelKarafFeatureUrl(),
+ "camel-core", "camel-spring", "camel-test", "camel-http", "camel-servlet"),
+
+ workingDirectory("target/paxrunner/"),
+
+ felix(), equinox());
+
+ return options;
+ }
+
+ @Override
+ protected OsgiBundleXmlApplicationContext createApplicationContext() {
+ return new OsgiBundleXmlApplicationContext(new String[]{"org/apache/camel/itest/osgi/servlet/ServletServiceContext.xml",
+ "org/apache/camel/itest/osgi/servlet/CamelServletWithServletServiceContext.xml"});
+ }
+
+}
Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletServicesTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletServicesTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/CamelServletWithServletServiceContext.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/CamelServletWithServletServiceContext.xml?rev=1055030&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/CamelServletWithServletServiceContext.xml (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/CamelServletWithServletServiceContext.xml Tue Jan 4 13:22:51 2011
@@ -0,0 +1,43 @@
+<?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:camel="http://camel.apache.org/schema/spring"
+ xmlns:osgi="http://www.springframework.org/schema/osgi"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+ <osgi:reference id="camelHttpTransportServlet" interface="org.apache.camel.component.servlet.CamelServletService"/>
+
+ <bean id="servlet" class="org.apache.camel.component.servlet.ServletComponent">
+ <property name = "camelServletService" ref="camelHttpTransportServlet" />
+ </bean>
+
+ <bean id="servletProcessor" class="org.apache.camel.itest.osgi.servlet.ServletProcessor" />
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <camel:route>
+ <camel:from uri="servlet:///hello"/>
+ <camel:process ref="servletProcessor"/>
+ </camel:route>
+ </camelContext>
+
+</beans>
Propchange: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/CamelServletWithServletServiceContext.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/CamelServletWithServletServiceContext.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/CamelServletWithServletServiceContext.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/ServletServiceContext.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/ServletServiceContext.xml?rev=1055030&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/ServletServiceContext.xml (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/ServletServiceContext.xml Tue Jan 4 13:22:51 2011
@@ -0,0 +1,39 @@
+<?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:osgi="http://www.springframework.org/schema/osgi"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+ <bean id="osgiServlet" class="org.apache.camel.component.servlet.CamelHttpTransportServlet"/>
+
+ <osgi:service ref="osgiServlet">
+ <osgi:interfaces>
+ <value>javax.servlet.Servlet</value>
+ <value>org.apache.camel.component.servlet.CamelServletService</value>
+ </osgi:interfaces>
+ <osgi:service-properties>
+ <entry key="alias" value="/camel/services" />
+ <entry key="servlet-name" value="CamelServlet"/>
+ </osgi:service-properties>
+ </osgi:service>
+
+</beans>
Propchange: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/ServletServiceContext.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/ServletServiceContext.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/ServletServiceContext.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml