Author: ningjiang
Date: Mon May 18 14:07:16 2009
New Revision: 775959

URL: http://svn.apache.org/viewvc?rev=775959&view=rev
Log:
CAMEL-1622 Set the OsgiFactoryFinder to the CamelContext in OSGi plateform

Added:
    
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jaxb/
    
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jaxb/JaxbFallbackConverterTest.java
   (with props)
    
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jaxb/PersonType.java
   (with props)
Modified:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/FactoryFinderResolver.java
    
camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
    
camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactory.java
    
camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java
    
camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiFactoryFinderResolver.java
    
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/FactoryFinderResolver.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/FactoryFinderResolver.java?rev=775959&r1=775958&r2=775959&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/FactoryFinderResolver.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/FactoryFinderResolver.java
 Mon May 18 14:07:16 2009
@@ -24,9 +24,9 @@
 public interface FactoryFinderResolver {
 
     /**
-     * Creates a new defaut factory finder using a default resource path.
+     * Creates a new default factory finder using a default resource path.
      *
-     * @param classResolver the class resolcer to use
+     * @param classResolver the class resolver to use
      * @return a factory finder.
      */
     FactoryFinder resolveDefaultFactoryFinder(ClassResolver classResolver);
@@ -34,7 +34,7 @@
     /**
      * Creates a new factory finder.
      *
-     * @param classResolver the class resolcer to use
+     * @param classResolver the class resolver to use
      * @param resourcePath the resource path as base to lookup files within
      * @return a factory finder.
      */

Modified: 
camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java?rev=775959&r1=775958&r2=775959&view=diff
==============================================================================
--- 
camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
 (original)
+++ 
camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
 Mon May 18 14:07:16 2009
@@ -346,7 +346,7 @@
     private static void appendRecipientToMimeMessage(MimeMessage mimeMessage, 
String type, String recipient)
         throws MessagingException {
 
-        // we support that multi recipient can be given as a string seperated 
by comma or semi colon
+        // we support that multi recipient can be given as a string separated 
by comma or semicolon
         String[] lines = recipient.split("[,|;]");
         for (String line : lines) {
             line = line.trim();

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=775959&r1=775958&r2=775959&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
 Mon May 18 14:07:16 2009
@@ -51,12 +51,14 @@
     public DefaultCamelContext createContext() {
         DefaultCamelContext context = new DefaultCamelContext();
         if (bundleContext != null) {
-            LOG.debug("The bundle context is not be null, let's setup the Osgi 
resolvers");
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("The bundle context is not be null, let's setup the 
Osgi resolvers");
+            }
+            context.setFactoryFinderResolver(new OsgiFactoryFinderResolver());
             context.setPackageScanClassResolver(new 
OsgiPackageScanClassResolver(bundleContext));
             context.setComponentResolver(new OsgiComponentResolver());
             context.setLanguageResolver(new OsgiLanguageResolver());
-            addOsgiAnnotationTypeConverterLoader(context, bundleContext);
-            context.setFactoryFinderResolver(new OsgiFactoryFinderResolver());
+            addOsgiAnnotationTypeConverterLoader(context, bundleContext);      
      
         }
         
         return context;

Modified: 
camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java?rev=775959&r1=775958&r2=775959&view=diff
==============================================================================
--- 
camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java
 (original)
+++ 
camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java
 Mon May 18 14:07:16 2009
@@ -50,11 +50,13 @@
     protected SpringCamelContext createContext() {
         SpringCamelContext context = super.createContext();
         if (bundleContext != null) {
-            LOG.debug("The bundle context is not be null, let's setup the Osgi 
resolvers");
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("The bundle context is not be null, let's setup the 
Osgi resolvers");
+            }
+            context.setFactoryFinderResolver(new OsgiFactoryFinderResolver());
             context.setPackageScanClassResolver(new 
OsgiPackageScanClassResolver(bundleContext));
             context.setComponentResolver(new OsgiComponentResolver());
-            context.setLanguageResolver(new OsgiLanguageResolver());
-            context.setFactoryFinderResolver(new OsgiFactoryFinderResolver());
+            context.setLanguageResolver(new OsgiLanguageResolver());           
 
             addOsgiAnnotationTypeConverterLoader(context);
         }
         

Modified: 
camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiFactoryFinderResolver.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiFactoryFinderResolver.java?rev=775959&r1=775958&r2=775959&view=diff
==============================================================================
--- 
camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiFactoryFinderResolver.java
 (original)
+++ 
camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiFactoryFinderResolver.java
 Mon May 18 14:07:16 2009
@@ -16,16 +16,20 @@
  */
 package org.apache.camel.osgi;
 
+
 import org.apache.camel.spi.ClassResolver;
 import org.apache.camel.spi.FactoryFinder;
 import org.apache.camel.spi.FactoryFinderResolver;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * @version $Revision$
  */
 public class OsgiFactoryFinderResolver implements FactoryFinderResolver {
+    private static final transient Log LOG = 
LogFactory.getLog(OsgiFactoryFinderResolver.class);
 
-    public FactoryFinder resolveDefaultFactoryFinder(ClassResolver 
classResolver) {
+    public FactoryFinder resolveDefaultFactoryFinder(ClassResolver 
classResolver) {        
         return resolveFactoryFinder(classResolver, 
"META-INF/services/org/apache/camel/");
     }
 

Modified: 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java?rev=775959&r1=775958&r2=775959&view=diff
==============================================================================
--- 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java
 (original)
+++ 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java
 Mon May 18 14:07:16 2009
@@ -21,6 +21,8 @@
 import org.apache.camel.CamelContext;
 import org.apache.camel.osgi.CamelContextFactory;
 import org.apache.camel.test.CamelTestSupport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.junit.After;
 import org.junit.Before;
 import org.ops4j.pax.exam.Inject;
@@ -38,6 +40,7 @@
 import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
 
 public class OSGiIntegrationTestSupport extends CamelTestSupport {
+    private static final transient Log LOG = 
LogFactory.getLog(OSGiIntegrationTestSupport.class);
     @Inject
     protected BundleContext bundleContext;
             
@@ -54,6 +57,7 @@
     protected CamelContext createCamelContext() throws Exception {
         CamelContextFactory factory = new CamelContextFactory();
         factory.setBundleContext(bundleContext);
+        LOG.info("Get the bundleContext is " + bundleContext);
         return factory.createContext();
     }
     

Added: 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jaxb/JaxbFallbackConverterTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jaxb/JaxbFallbackConverterTest.java?rev=775959&view=auto
==============================================================================
--- 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jaxb/JaxbFallbackConverterTest.java
 (added)
+++ 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jaxb/JaxbFallbackConverterTest.java
 Mon May 18 14:07:16 2009
@@ -0,0 +1,87 @@
+/**
+ * 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.jaxb;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultClassResolver;
+import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
+import org.apache.camel.osgi.OsgiFactoryFinder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+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 static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.knopflerfish;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.logProfile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.profile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
+
+...@runwith(JUnit4TestRunner.class)
+public class JaxbFallbackConverterTest extends OSGiIntegrationTestSupport {
+    private static final transient Log LOG = 
LogFactory.getLog(JaxbFallbackConverterTest.class);
+    
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                
from("direct:start").convertBodyTo(PersonType.class).to("mock:bar");
+            }
+        };
+    }
+
+    @Test
+    public void testSendMessage() throws Exception {
+        MockEndpoint mock =  getMandatoryEndpoint("mock:bar", 
MockEndpoint.class);
+        assertNotNull("The mock endpoint should not be null", mock);
+        
+        PersonType expected = new PersonType();
+        expected.setFirstName("FOO");
+        expected.setLastName("BAR");
+        mock.expectedBodiesReceived(expected);
+        template.sendBody("direct:start", 
"<Person><firstName>FOO</firstName><lastName>BAR</lastName></Person>");
+        assertMockEndpointsSatisfied();        
+    }    
+    
+    @Configuration
+    public static Option[] configure() {
+        Option[] options = options(
+            // install log service using pax runners profile abstraction 
(there are more profiles, like DS)
+            logProfile().version("1.3.0"),
+            // install the spring dm profile            
+            profile("spring.dm").version("1.2.0"),    
+            // 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(mavenBundle().groupId("org.apache.camel.karaf").
+                         
artifactId("features").versionAsInProject().type("xml/features"),               
          
+                          "camel-core", "camel-osgi", "camel-spring", 
"camel-test", "camel-jaxb"),
+            
+            felix());
+        
+        return options;
+    }
+
+}

Propchange: 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jaxb/JaxbFallbackConverterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jaxb/JaxbFallbackConverterTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jaxb/PersonType.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jaxb/PersonType.java?rev=775959&view=auto
==============================================================================
--- 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jaxb/PersonType.java
 (added)
+++ 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jaxb/PersonType.java
 Mon May 18 14:07:16 2009
@@ -0,0 +1,123 @@
+/**
+ * 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.jaxb;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.apache.camel.util.ObjectHelper;
+
+
+/**
+ * <p>Java class for PersonType complex type.
+ * 
+ * <p>The following schema fragment specifies the expected content contained 
within this class.
+ * 
+ * <pre>
+ * &lt;complexType name="PersonType">
+ *   &lt;complexContent>
+ *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType";>
+ *       &lt;sequence>
+ *         &lt;element name="firstName" 
type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *         &lt;element name="lastName" 
type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *       &lt;/sequence>
+ *     &lt;/restriction>
+ *   &lt;/complexContent>
+ * &lt;/complexType>
+ * </pre>
+ * 
+ * 
+ */
+...@xmlrootelement(name = "Person")
+...@xmlaccessortype(XmlAccessType.FIELD)
+...@xmltype(name = "PersonType", propOrder = {"firstName", "lastName"})
+public class PersonType {
+
+    @XmlElement(required = true)
+    protected String firstName;
+    @XmlElement(required = true)
+    protected String lastName;
+
+    /**
+     * Gets the value of the firstName property.
+     * 
+     * @return
+     *     possible object is
+     *     {...@link String }
+     *     
+     */
+    public String getFirstName() {
+        return firstName;
+    }
+
+    /**
+     * Sets the value of the firstName property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {...@link String }
+     *     
+     */
+    public void setFirstName(String value) {
+        this.firstName = value;
+    }
+
+    /**
+     * Gets the value of the lastName property.
+     * 
+     * @return
+     *     possible object is
+     *     {...@link String }
+     *     
+     */
+    public String getLastName() {
+        return lastName;
+    }
+
+    /**
+     * Sets the value of the lastName property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {...@link String }
+     *     
+     */
+    public void setLastName(String value) {
+        this.lastName = value;
+    }
+   
+    @Override
+    public boolean equals(Object o) {
+        if (o instanceof PersonType) {
+            PersonType that = (PersonType)o;
+            return ObjectHelper.equal(this.firstName, that.firstName) 
+                && ObjectHelper.equal(this.lastName, that.lastName);           
      
+        }
+        return false;
+    }
+    
+    @Override
+    public int hashCode() {
+        return firstName.hashCode() + lastName.hashCode() * 100;
+    }
+    
+
+}

Propchange: 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jaxb/PersonType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jaxb/PersonType.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date


Reply via email to