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 2009/11/26 09:36:16 UTC
svn commit: r884462 - in /camel/trunk:
components/camel-osgi/src/main/java/org/apache/camel/osgi/
components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/
examples/camel-example-spring-javaconfig/ examples/camel-example-spri...
Author: ningjiang
Date: Thu Nov 26 08:36:15 2009
New Revision: 884462
URL: http://svn.apache.org/viewvc?rev=884462&view=rev
Log:
CAMEL-2228 Fixed the issue that camel-example-spring-javaconfig can not work in Servicemix
Added:
camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/SpringCamelContextFactory.java (with props)
Modified:
camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactory.java
camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/CamelConfiguration.java
camel/trunk/examples/camel-example-spring-javaconfig/pom.xml
camel/trunk/examples/camel-example-spring-javaconfig/src/main/java/org/apache/camel/example/spring/javaconfig/MyRouteConfig.java
Modified: camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactory.java?rev=884462&r1=884461&r2=884462&view=diff
==============================================================================
--- camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactory.java (original)
+++ camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactory.java Thu Nov 26 08:36:15 2009
@@ -47,10 +47,14 @@
this.bundleContext = bundleContext;
}
+ protected DefaultCamelContext newCamelContext() {
+ return new DefaultCamelContext();
+ }
+
public DefaultCamelContext createContext() {
LOG.debug("Creating DefaultCamelContext");
- DefaultCamelContext context = new DefaultCamelContext();
+ DefaultCamelContext context = newCamelContext();
if (bundleContext != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Using OSGI resolvers");
Added: camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/SpringCamelContextFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/SpringCamelContextFactory.java?rev=884462&view=auto
==============================================================================
--- camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/SpringCamelContextFactory.java (added)
+++ camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/SpringCamelContextFactory.java Thu Nov 26 08:36:15 2009
@@ -0,0 +1,36 @@
+/**
+ * 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.osgi;
+
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.spring.SpringCamelContext;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
+public class SpringCamelContextFactory extends CamelContextFactory implements ApplicationContextAware {
+ private ApplicationContext applicationContext;
+
+ public void setApplicationContext(ApplicationContext context) {
+ this.applicationContext = context;
+ }
+
+ @Override
+ protected DefaultCamelContext newCamelContext() {
+ return new SpringCamelContext(applicationContext);
+ }
+
+}
Propchange: camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/SpringCamelContextFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/SpringCamelContextFactory.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/CamelConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/CamelConfiguration.java?rev=884462&r1=884461&r2=884462&view=diff
==============================================================================
--- camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/CamelConfiguration.java (original)
+++ camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/CamelConfiguration.java Thu Nov 26 08:36:15 2009
@@ -52,7 +52,7 @@
*/
@Bean
public CamelContext camelContext() throws Exception {
- SpringCamelContext camelContext = new SpringCamelContext(getApplicationContext());
+ CamelContext camelContext = createCamelContext();
setupCamelContext(camelContext);
List<RouteBuilder> routes = routes();
for (RoutesBuilder route : routes) {
@@ -61,8 +61,13 @@
return camelContext;
}
- // maybe register the camel component, language here
- public void setupCamelContext(CamelContext camelContext) throws Exception {
+ // Can register the camel component, language here
+ protected void setupCamelContext(CamelContext camelContext) throws Exception {
+
+ }
+
+ protected CamelContext createCamelContext() throws Exception {
+ return new SpringCamelContext(getApplicationContext());
}
/**
Modified: camel/trunk/examples/camel-example-spring-javaconfig/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-spring-javaconfig/pom.xml?rev=884462&r1=884461&r2=884462&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-spring-javaconfig/pom.xml (original)
+++ camel/trunk/examples/camel-example-spring-javaconfig/pom.xml Thu Nov 26 08:36:15 2009
@@ -33,8 +33,10 @@
<description>An example showing how to work with Camel and Spring Java Config</description>
<properties>
- <camel.osgi.export.pkg>org.apache.camel.example.spring.*</camel.osgi.export.pkg>
- <camel.osgi.import.pkg>org.apache.activemq.xbean,org.apache.activemq.broker,org.apache.activemq.pool,*</camel.osgi.import.pkg>
+ <camel.osgi.export>org.apache.camel.example.spring.*</camel.osgi.export>
+ <camel.osgi.import>org.apache.activemq.xbean,org.apache.activemq.broker,org.apache.activemq.pool</camel.osgi.import>
+ <!-- avoid to import the bunch of spring related package -->
+ <camel.osgi.dynamic>*</camel.osgi.dynamic>
</properties>
<dependencies>
@@ -46,6 +48,11 @@
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-javaconfig</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-osgi</artifactId>
</dependency>
<dependency>
@@ -57,6 +64,12 @@
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>log4j</groupId>
Modified: camel/trunk/examples/camel-example-spring-javaconfig/src/main/java/org/apache/camel/example/spring/javaconfig/MyRouteConfig.java
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-spring-javaconfig/src/main/java/org/apache/camel/example/spring/javaconfig/MyRouteConfig.java?rev=884462&r1=884461&r2=884462&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-spring-javaconfig/src/main/java/org/apache/camel/example/spring/javaconfig/MyRouteConfig.java (original)
+++ camel/trunk/examples/camel-example-spring-javaconfig/src/main/java/org/apache/camel/example/spring/javaconfig/MyRouteConfig.java Thu Nov 26 08:36:15 2009
@@ -16,14 +16,23 @@
*/
package org.apache.camel.example.spring.javaconfig;
+import java.util.List;
+
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsComponent;
+
+import org.apache.camel.osgi.SpringCamelContextFactory;
+import org.apache.camel.spring.SpringCamelContext;
import org.apache.camel.spring.javaconfig.Main;
import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
+import org.osgi.framework.BundleContext;
+import org.springframework.beans.factory.InitializingBean;
import org.springframework.config.java.annotation.Bean;
import org.springframework.config.java.annotation.Configuration;
+import org.springframework.osgi.context.BundleContextAware;
//START SNIPPET: RouteConfig
/**
@@ -32,7 +41,10 @@
* @version $Revision$
*/
@Configuration
-public class MyRouteConfig extends SingleRouteCamelConfiguration {
+public class MyRouteConfig extends SingleRouteCamelConfiguration implements InitializingBean, BundleContextAware {
+
+ private BundleContext bundleContext;
+
/**
* Allow this route to be run as an application
*
@@ -43,19 +55,38 @@
new Main().run(args);
}
+ public BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+
+ /**
+ * Returns the CamelContext which support OSGi
+ */
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ SpringCamelContextFactory factory = new SpringCamelContextFactory();
+ factory.setApplicationContext(getApplicationContext());
+ factory.setBundleContext(getBundleContext());
+ return factory.createContext();
+ }
+
@Override
// setup the ActiveMQ component and register it into the camel context
- public void setupCamelContext(CamelContext camelContext) throws Exception {
+ protected void setupCamelContext(CamelContext camelContext) throws Exception {
JmsComponent answer = new JmsComponent();
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
- connectionFactory.setBrokerURL("vm://localhost?broker.persistent=false&broker.useJmx=false");
+ connectionFactory.setBrokerURL("vm://localhost.spring.javaconfig?marshal=false&broker.persistent=false&broker.useJmx=false");
answer.setConnectionFactory(connectionFactory);
camelContext.addComponent("jms", answer);
}
public static class SomeBean {
-
public void someMethod(String body) {
System.out.println("Received: " + body);
}
@@ -80,5 +111,9 @@
}
};
}
+
+ public void afterPropertiesSet() throws Exception {
+ // just to make SpringDM happy do nothing here
+ }
}
//END SNIPPET: RouteConfig
\ No newline at end of file