You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2007/09/19 21:49:23 UTC

svn commit: r577424 - in /activemq/camel/trunk: ./ camel-core/src/main/java/org/apache/camel/component/ref/ camel-core/src/main/resources/META-INF/services/org/apache/camel/component/ camel-core/src/test/java/org/apache/camel/builder/ components/camel-...

Author: gnodet
Date: Wed Sep 19 12:49:22 2007
New Revision: 577424

URL: http://svn.apache.org/viewvc?rev=577424&view=rev
Log:
CAMEL-152: Add a ref: protocol to lookup registered endpoints easily

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/ref/
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/ref/RefComponent.java
    activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/ref
Modified:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/InterceptorBuilderTest.java
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/EndpointFactoryBean.java
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/endpointReference.xml
    activemq/camel/trunk/pom.xml

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/ref/RefComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/ref/RefComponent.java?rev=577424&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/ref/RefComponent.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/ref/RefComponent.java Wed Sep 19 12:49:22 2007
@@ -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.ref;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+
+import java.util.Map;
+
+/**
+ *
+ */
+public class RefComponent extends DefaultComponent<Exchange> {
+
+    protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
+        String name = uri.substring(4);
+        return getCamelContext().getRegistry().lookup(name, Endpoint.class);
+    }
+
+}

Added: activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/ref
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/ref?rev=577424&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/ref (added)
+++ activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/ref Wed Sep 19 12:49:22 2007
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.component.ref.RefComponent
\ No newline at end of file

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/InterceptorBuilderTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/InterceptorBuilderTest.java?rev=577424&r1=577423&r2=577424&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/InterceptorBuilderTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/InterceptorBuilderTest.java Wed Sep 19 12:49:22 2007
@@ -60,6 +60,7 @@
 
         RouteBuilder builder = new RouteBuilder() {
             public void configure() {
+                //from("direct:a").intercept(interceptor1).intercept(interceptor2).to("direct:d");
                 from("direct:a").intercept(interceptor1).intercept(interceptor2).to("direct:d");
                 /*
                  * TODO keep old DSL? .intercept() .add(interceptor1)

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=577424&r1=577423&r2=577424&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java Wed Sep 19 12:49:22 2007
@@ -16,18 +16,6 @@
  */
 package org.apache.camel.spring;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.management.MBeanServer;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlElements;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlTransient;
-
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.model.IdentifiedType;
@@ -45,6 +33,12 @@
 import org.springframework.context.ApplicationListener;
 import org.springframework.context.event.ContextRefreshedEvent;
 
+import javax.management.MBeanServer;
+import javax.xml.bind.annotation.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
 /**
  * A Spring {@link FactoryBean} to create and initialize a
  * {@link SpringCamelContext} and install routes either explicitly configured in
@@ -245,6 +239,12 @@
      * Strategy to install all available routes into the context
      */
     protected void installRoutes() throws Exception {
+        Map builders = getApplicationContext().getBeansOfType(RouteBuilder.class, true, true);
+        if (builders != null) {
+            for (Object builder : builders.values()) {
+                getContext().addRoutes((RouteBuilder) builder);
+            }
+        }
         for (RouteBuilder routeBuilder : additionalBuilders) {
             getContext().addRoutes(routeBuilder);
         }

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/EndpointFactoryBean.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/EndpointFactoryBean.java?rev=577424&r1=577423&r2=577424&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/EndpointFactoryBean.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/EndpointFactoryBean.java Wed Sep 19 12:49:22 2007
@@ -16,19 +16,15 @@
  */
 package org.apache.camel.spring;
 
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlTransient;
-
 import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
 import org.apache.camel.Endpoint;
+import org.apache.camel.NoSuchEndpointException;
 import org.apache.camel.model.IdentifiedType;
-
+import static org.apache.camel.util.ObjectHelper.notNull;
 import org.springframework.beans.factory.FactoryBean;
 
-import static org.apache.camel.util.ObjectHelper.notNull;
+import javax.xml.bind.annotation.*;
 
 /**
  * A {@link FactoryBean} which instantiates {@link Endpoint} objects
@@ -37,7 +33,7 @@
  */
 @XmlRootElement(name = "endpoint")
 @XmlAccessorType(XmlAccessType.FIELD)
-public class EndpointFactoryBean extends IdentifiedType implements FactoryBean {
+public class EndpointFactoryBean extends IdentifiedType implements FactoryBean, CamelContextAware {
     @XmlAttribute
     private String uri;
     @XmlTransient
@@ -62,7 +58,7 @@
         return singleton;
     }
 
-    public CamelContext getContext() {
+    public CamelContext getCamelContext() {
         return context;
     }
 
@@ -71,7 +67,7 @@
      *
      * @param context the context used to resolve endpoints
      */
-    public void setContext(CamelContext context) {
+    public void setCamelContext(CamelContext context) {
         this.context = context;
     }
 
@@ -103,6 +99,10 @@
     protected Endpoint createEndpoint() {
         notNull(context, "context");
         notNull(uri, "uri");
-        return context.getEndpoint(uri);
+        Endpoint endpoint = context.getEndpoint(uri);
+        if (endpoint == null) {
+            throw new NoSuchEndpointException(uri);
+        }
+        return endpoint;
     }
 }

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java?rev=577424&r1=577423&r2=577424&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java Wed Sep 19 12:49:22 2007
@@ -30,20 +30,15 @@
 import org.apache.camel.spring.spi.SpringInjector;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.DisposableBean;
 import org.springframework.beans.factory.InitializingBean;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.context.ApplicationEvent;
-import org.springframework.context.ApplicationListener;
-import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.*;
 import org.springframework.context.event.ContextRefreshedEvent;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
- * A Spring aware implementation of {@link CamelContext} which will
+ * A Spring aware implementation of {@link org.apache.camel.CamelContext} which will
  * automatically register itself with Springs lifecycle methods plus allows
  * spring to be used to customize a any <a
  * href="http://activemq.apache.org/camel/type-converter.html">Type Converters</a>

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java?rev=577424&r1=577423&r2=577424&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java Wed Sep 19 12:49:22 2007
@@ -100,7 +100,7 @@
                             String id = childElement.getAttribute("id");
                             if (isNotNullAndNonEmpty(id)) {
                                 // TODO we can zap this?
-                                definition.getPropertyValues().addPropertyValue("context", new RuntimeBeanReference(contextId));
+                                definition.getPropertyValues().addPropertyValue("camelContext", new RuntimeBeanReference(contextId));
                                 // definition.getPropertyValues().addPropertyValue("context",
                                 // builder.getBeanDefinition());
                                 parserContext.registerComponent(new BeanComponentDefinition(definition, id));

Modified: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/endpointReference.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/endpointReference.xml?rev=577424&r1=577423&r2=577424&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/endpointReference.xml (original)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/endpointReference.xml Wed Sep 19 12:49:22 2007
@@ -33,7 +33,7 @@
 
     <route>
       <from ref="endpoint1"/>
-      <to ref="endpoint2"/>
+      <to uri="ref:endpoint2"/>
     </route>
   </camelContext>
   <!-- END SNIPPET: example -->

Modified: activemq/camel/trunk/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/pom.xml?rev=577424&r1=577423&r2=577424&view=diff
==============================================================================
--- activemq/camel/trunk/pom.xml (original)
+++ activemq/camel/trunk/pom.xml Wed Sep 19 12:49:22 2007
@@ -51,6 +51,7 @@
     <camel.osgi.import.pkg>*</camel.osgi.import.pkg>
     <camel.osgi.private.pkg>!*</camel.osgi.private.pkg>
     <camel.osgi.export>${camel.osgi.export.pkg}*;version=${camel.osgi.export.version}</camel.osgi.export>
+    <camel.osgi.export.version>${project.version}</camel.osgi.export.version>
     <camel.osgi.import>${camel.osgi.import.pkg}</camel.osgi.import>
     <camel.osgi.symbolic.name>${groupId}.${artifactId}</camel.osgi.symbolic.name>
   </properties>