camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r707155 - in /activemq/camel/trunk: ./ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/util/ components/camel-guice/ components/camel-guice/src/main/java/org/apache/camel/guice/ components/camel-gui...
Date Wed, 22 Oct 2008 18:23:55 GMT
Author: jstrachan
Date: Wed Oct 22 11:23:55 2008
New Revision: 707155

URL: http://svn.apache.org/viewvc?rev=707155&view=rev
Log:
added support for CAMEL-1015 with tests showing @EndpointIjnject, @Produce, @Consume all working
with guice

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
  (contents, props changed)
      - copied, changed from r706910, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorSupport.java
    activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/ConsumerInjection.java
  (with props)
    activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/ProduceInjector.java
  (contents, props changed)
      - copied, changed from r707021, activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/EndpointInjector.java
    activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/consume/
    activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/consume/ConsumeTest.java
  (with props)
    activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/example/
    activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/produce/
    activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/produce/MyListener.java
  (with props)
    activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/produce/MyListenerService.java
  (with props)
    activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/produce/ProduceTest.java
  (with props)
Removed:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorSupport.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
    activemq/camel/trunk/components/camel-guice/pom.xml
    activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java
    activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/EndpointInjector.java
    activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java
    activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/EndpointInjectionTest.java
    activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceRouteWithNamedKeysTest.java
    activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceTest.java
    activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java
    activemq/camel/trunk/pom.xml

Copied: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
(from r706910, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorSupport.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java?p2=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java&p1=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorSupport.java&r1=706910&r2=707155&rev=707155&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorSupport.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
Wed Oct 22 11:23:55 2008
@@ -21,6 +21,8 @@
 import org.apache.camel.component.bean.BeanProcessor;
 import org.apache.camel.component.bean.ProxyHelper;
 import org.apache.camel.util.CamelContextHelper;
+import static org.apache.camel.util.ObjectHelper.isNotNullAndNonEmpty;
+import static org.apache.camel.util.ObjectHelper.isNullOrBlank;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -34,14 +36,17 @@
  *
  * @version $Revision: 1.1 $
  */
-public class CamelPostProcessorSupport implements CamelContextAware {
-    private static final transient Log LOG = LogFactory.getLog(CamelPostProcessorSupport.class);
+public class CamelPostProcessorHelper implements CamelContextAware {
+    private static final transient Log LOG = LogFactory.getLog(CamelPostProcessorHelper.class);
 
     @XmlTransient
     private CamelContext camelContext;
 
-    public CamelPostProcessorSupport(CamelContext camelContext) {
-        this.camelContext = camelContext;
+    public CamelPostProcessorHelper() {
+    }
+
+    public CamelPostProcessorHelper(CamelContext camelContext) {
+        this.setCamelContext(camelContext);
     }
 
     public CamelContext getCamelContext() {
@@ -69,7 +74,7 @@
     protected void subscribeMethod(Method method, Object bean, String endpointUri, String
endpointName) {
         // lets bind this method to a listener
         String injectionPointName = method.getName();
-        Endpoint endpoint = getEndpointInjection(endpointUri, endpointName, injectionPointName);
+        Endpoint endpoint = getEndpointInjection(endpointUri, endpointName, injectionPointName,
true);
         if (endpoint != null) {
             try {
                 Processor processor = createConsumerProcessor(bean, method, endpoint);
@@ -84,6 +89,7 @@
     }
 
     public void startService(Service service) throws Exception {
+        CamelContext camelContext = getCamelContext();
         if (camelContext instanceof DefaultCamelContext) {
             DefaultCamelContext defaultCamelContext = (DefaultCamelContext) camelContext;
             defaultCamelContext.addService(service);
@@ -103,36 +109,41 @@
         return answer;
     }
 
-    protected Endpoint getEndpointInjection(String uri, String name, String injectionPointName)
{
-        return CamelContextHelper.getEndpointInjection(camelContext, uri, name, injectionPointName);
+    protected Endpoint getEndpointInjection(String uri, String name, String injectionPointName,
boolean mandatory) {
+        return CamelContextHelper.getEndpointInjection(getCamelContext(), uri, name, injectionPointName,
mandatory);
     }
 
     /**
      * Creates the object to be injected for an {@link org.apache.camel.EndpointInject} or
{@link org.apache.camel.Produce} injection point
      */
     public Object getInjectionValue(Class<?> type, String endpointUri, String endpointRef,
String injectionPointName) {
-        Endpoint endpoint = getEndpointInjection(endpointUri, endpointRef, injectionPointName);
-        if (endpoint != null) {
-            if (type.isInstance(endpoint)) {
-                return endpoint;
-            } else if (type.isAssignableFrom(Producer.class)) {
-                return createInjectionProducer(endpoint);
-            } else if (type.isAssignableFrom(DefaultProducerTemplate.class)) {
-                return new DefaultProducerTemplate(getCamelContext(), endpoint);
-            } else if (type.isAssignableFrom(PollingConsumer.class)) {
-                return createInjectionPollingConsumer(endpoint);
-            } else if (type.isInterface()) {
-                // lets create a proxy
-                try {
-                    return ProxyHelper.createProxy(endpoint, type);
-                } catch (Exception e) {
-                    throw createProxyInstantiationRuntimeException(type, endpoint, e);
+        if (type.isAssignableFrom(ProducerTemplate.class)) {
+            // endpoint is optional for this injection point
+            Endpoint endpoint = getEndpointInjection(endpointUri, endpointRef, injectionPointName,
false);
+            return new DefaultProducerTemplate(getCamelContext(), endpoint);
+        }
+        else {
+            Endpoint endpoint = getEndpointInjection(endpointUri, endpointRef, injectionPointName,
true);
+            if (endpoint != null) {
+                if (type.isInstance(endpoint)) {
+                    return endpoint;
+                } else if (type.isAssignableFrom(Producer.class)) {
+                    return createInjectionProducer(endpoint);
+                } else if (type.isAssignableFrom(PollingConsumer.class)) {
+                    return createInjectionPollingConsumer(endpoint);
+                } else if (type.isInterface()) {
+                    // lets create a proxy
+                    try {
+                        return ProxyHelper.createProxy(endpoint, type);
+                    } catch (Exception e) {
+                        throw createProxyInstantiationRuntimeException(type, endpoint, e);
+                    }
+                } else {
+                    throw new IllegalArgumentException("Invalid type: " + type.getName()
+ " which cannot be injected via @EndpointInject for " + endpoint);
                 }
-            } else {
-                throw new IllegalArgumentException("Invalid type: " + type.getName() + "
which cannot be injected via @EndpointInject for " + endpoint);
             }
+            return null;
         }
-        return null;
     }
 
     protected RuntimeException createProxyInstantiationRuntimeException(Class<?> type,
Endpoint endpoint, Exception e) {

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java?rev=707155&r1=707154&r2=707155&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
Wed Oct 22 11:23:55 2008
@@ -189,7 +189,7 @@
     /**
      * Evaluates the @EndpointInject annotation using the given context
      */
-    public static Endpoint getEndpointInjection(CamelContext camelContext, String uri, String
name, String injectionPointName) {
+    public static Endpoint getEndpointInjection(CamelContext camelContext, String uri, String
name, String injectionPointName, boolean mandatory) {
         Endpoint endpoint = null;
         if (isNotNullAndNonEmpty(uri)) {
             endpoint = camelContext.getEndpoint(uri);
@@ -197,7 +197,12 @@
             if (isNullOrBlank(name)) {
                 name = injectionPointName;
             }
-            endpoint = mandatoryLookup(camelContext, name, Endpoint.class);
+            if (mandatory) {
+                endpoint = mandatoryLookup(camelContext, name, Endpoint.class);
+            }
+            else {
+                endpoint = lookup(camelContext, name, Endpoint.class);
+            }
         }
         return endpoint;
     }

Modified: activemq/camel/trunk/components/camel-guice/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/pom.xml?rev=707155&r1=707154&r2=707155&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-guice/pom.xml (original)
+++ activemq/camel/trunk/components/camel-guice/pom.xml Wed Oct 22 11:23:55 2008
@@ -57,6 +57,12 @@
 
     <!-- testing -->
     <dependency>
+      <groupId>org.guiceyfruit</groupId>
+      <artifactId>guiceyfruit-junit3</artifactId>
+      <version>${guiceyfruit-version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
       <scope>test</scope>

Modified: activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java?rev=707155&r1=707154&r2=707155&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java
(original)
+++ activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/CamelModule.java
Wed Oct 22 11:23:55 2008
@@ -17,11 +17,16 @@
 package org.apache.camel.guice;
 
 import com.google.inject.AbstractModule;
+import com.google.inject.matcher.Matchers;
 import com.google.inject.jsr250.Jsr250;
 import com.google.inject.jsr250.Jsr250Module;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Routes;
+import org.apache.camel.MessageDriven;
+import org.apache.camel.Consume;
 import org.apache.camel.guice.impl.EndpointInjector;
+import org.apache.camel.guice.impl.ProduceInjector;
+import org.apache.camel.guice.impl.ConsumerInjection;
 
 /**
  * A base Guice module for creating a {@link CamelContext} leaving it up to the users module
@@ -50,6 +55,14 @@
         bind(CamelContext.class).to(GuiceCamelContext.class).asEagerSingleton();
 
         bind(EndpointInjector.class);
+        bind(ProduceInjector.class);
+
+        ConsumerInjection consumerInjection = new ConsumerInjection();
+        requestInjection(consumerInjection);
+
+
+        bindConstructorInterceptor(Matchers.methodAnnotatedWith(MessageDriven.class), consumerInjection);
+        bindConstructorInterceptor(Matchers.methodAnnotatedWith(Consume.class), consumerInjection);
     }
 
 }

Added: activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/ConsumerInjection.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/ConsumerInjection.java?rev=707155&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/ConsumerInjection.java
(added)
+++ activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/ConsumerInjection.java
Wed Oct 22 11:23:55 2008
@@ -0,0 +1,59 @@
+/**
+ *
+ * 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.guice.impl;
+
+import org.aopalliance.intercept.ConstructorInterceptor;
+import org.aopalliance.intercept.ConstructorInvocation;
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.CamelPostProcessorHelper;
+
+import java.lang.reflect.Method;
+
+import com.google.inject.Inject;
+import com.google.common.base.Objects;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class ConsumerInjection extends CamelPostProcessorHelper implements ConstructorInterceptor
{
+    public Object construct(ConstructorInvocation invocation) throws Throwable {
+        Object object = invocation.proceed();
+        if (object != null) {
+            Class<?> type = object.getClass();
+            Method[] methods = type.getMethods();
+            for (Method method : methods) {
+                consumerInjection(method, object);
+            }
+        }
+        return object;
+
+    }
+
+    @Override
+    public CamelContext getCamelContext() {
+        CamelContext context = super.getCamelContext();
+        Objects.nonNull(context, "CamelContext not injected!");
+        return context;
+    }
+
+    @Inject
+    @Override
+    public void setCamelContext(CamelContext camelContext) {
+        super.setCamelContext(camelContext);
+    }
+}

Propchange: activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/ConsumerInjection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/EndpointInjector.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/EndpointInjector.java?rev=707155&r1=707154&r2=707155&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/EndpointInjector.java
(original)
+++ activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/EndpointInjector.java
Wed Oct 22 11:23:55 2008
@@ -29,13 +29,16 @@
 
 import org.apache.camel.EndpointInject;
 import org.apache.camel.CamelContext;
-import org.apache.camel.impl.CamelPostProcessorSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.impl.CamelPostProcessorHelper;
 
 /**
+ * Injects values into the {@link EndpointInject} injection point
+ *
  * @version $Revision: 1.1 $
  */
 @InjectionAnnotation(EndpointInject.class)
-public class EndpointInjector extends CamelPostProcessorSupport implements AnnotationProviderFactory
{
+public class EndpointInjector extends CamelPostProcessorHelper implements AnnotationProviderFactory
{
 
     @Inject
     public EndpointInjector(CamelContext camelContext) {
@@ -62,9 +65,7 @@
             Class<?>[] parameterTypes = method.getParameterTypes();
             if (parameterTypes.length == 1) {
                 type = parameterTypes[0];
-
-                // TODO remove setter method name?
-                injectionPointName = method.getName();
+                injectionPointName = ObjectHelper.getPropertyName(method);
             }
             else {
                 throw new UnsupportedOperationException("Only a single method parameter value
supported for @EndpointInject on " + method);

Copied: activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/ProduceInjector.java
(from r707021, activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/EndpointInjector.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/ProduceInjector.java?p2=activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/ProduceInjector.java&p1=activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/EndpointInjector.java&r1=707021&r2=707155&rev=707155&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/EndpointInjector.java
(original)
+++ activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/ProduceInjector.java
Wed Oct 22 11:23:55 2008
@@ -27,29 +27,32 @@
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 
-import org.apache.camel.EndpointInject;
 import org.apache.camel.CamelContext;
-import org.apache.camel.impl.CamelPostProcessorSupport;
+import org.apache.camel.Produce;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.impl.CamelPostProcessorHelper;
 
 /**
+ * Injects values into the {@link Produce} injection point
+ *
  * @version $Revision: 1.1 $
  */
-@InjectionAnnotation(EndpointInject.class)
-public class EndpointInjector extends CamelPostProcessorSupport implements AnnotationProviderFactory
{
+@InjectionAnnotation(Produce.class)
+public class ProduceInjector extends CamelPostProcessorHelper implements AnnotationProviderFactory
{
 
     @Inject
-    public EndpointInjector(CamelContext camelContext) {
+    public ProduceInjector(CamelContext camelContext) {
         super(camelContext);
     }
 
     public Provider createProvider(final AnnotatedElement member) {
-        final EndpointInject inject = member.getAnnotation(EndpointInject.class);
-        Objects.nonNull(inject, "@EndpointInject is not present!");
+        final Produce inject = member.getAnnotation(Produce.class);
+        Objects.nonNull(inject, "@Produce is not present!");
 
 
         final Class<?> type;
         final String injectionPointName;
-        final String endpointRef = inject.name();
+        final String endpointRef = inject.ref();
         final String uri = inject.uri();
 
         if (member instanceof Field) {
@@ -62,12 +65,10 @@
             Class<?>[] parameterTypes = method.getParameterTypes();
             if (parameterTypes.length == 1) {
                 type = parameterTypes[0];
-
-                // TODO remove setter method name?
-                injectionPointName = method.getName();
+                injectionPointName = ObjectHelper.getPropertyName(method);
             }
             else {
-                throw new UnsupportedOperationException("Only a single method parameter value
supported for @EndpointInject on " + method);
+                throw new UnsupportedOperationException("Only a single method parameter value
supported for @Produce on " + method);
             }
         }
         else {
@@ -80,4 +81,4 @@
             }
         };
     }
-}
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/ProduceInjector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/impl/ProduceInjector.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java?rev=707155&r1=707154&r2=707155&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java
(original)
+++ activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/ConciseGuiceRouteTest.java
Wed Oct 22 11:23:55 2008
@@ -34,7 +34,7 @@
 
     public void testGuice() throws Exception {
         // lets disable resource injection to avoid JNDI being used
-        Injector injector = Guice.createInjector(new CamelModuleWithRouteTypes(MyRouteInstaller.class,
MyHardcodeRoute.class).noResourceInjection());
+        Injector injector = Guice.createInjector(new CamelModuleWithRouteTypes(MyRouteInstaller.class,
MyHardcodeRoute.class));
         GuiceTest.assertCamelContextRunningThenCloseInjector(injector);
     }
 

Modified: activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/EndpointInjectionTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/EndpointInjectionTest.java?rev=707155&r1=707154&r2=707155&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/EndpointInjectionTest.java
(original)
+++ activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/EndpointInjectionTest.java
Wed Oct 22 11:23:55 2008
@@ -42,8 +42,6 @@
 
         @Override
         protected void configure() {
-            noResourceInjection();
-
             super.configure();
 
             bind(MyBean.class);

Modified: activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceRouteWithNamedKeysTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceRouteWithNamedKeysTest.java?rev=707155&r1=707154&r2=707155&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceRouteWithNamedKeysTest.java
(original)
+++ activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceRouteWithNamedKeysTest.java
Wed Oct 22 11:23:55 2008
@@ -41,11 +41,6 @@
 
     public static class MyModule extends CamelModuleWithMatchingRoutes {
 
-        public MyModule() {
-            // lets disable the use of JNDI
-            noResourceInjection();
-        }
-
         @Provides
         @Named("foo")
         protected MyConfigurableRoute2 createRoute1() {

Modified: activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceTest.java?rev=707155&r1=707154&r2=707155&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceTest.java
(original)
+++ activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/GuiceTest.java
Wed Oct 22 11:23:55 2008
@@ -62,7 +62,7 @@
 
     public void testGuice() throws Exception {
         // lets disable resource injection to avoid JNDI being used
-        Injector injector = Guice.createInjector(new CamelModuleWithMatchingRoutes().noResourceInjection());
+        Injector injector = Guice.createInjector(new CamelModuleWithMatchingRoutes());
 
         Cheese cheese = injector.getInstance(Cheese.class);
         assertNotNull("Should have cheese", cheese);

Modified: activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java?rev=707155&r1=707154&r2=707155&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java
(original)
+++ activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/TraditionalGuiceRouteTest.java
Wed Oct 22 11:23:55 2008
@@ -34,9 +34,6 @@
 
         public MyModule() {
             super(MyHardcodeRoute.class, MyRouteInstaller.class);
-
-            // lets disable the use of JNDI
-            noResourceInjection();
         }
     }
 

Added: activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/consume/ConsumeTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/consume/ConsumeTest.java?rev=707155&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/consume/ConsumeTest.java
(added)
+++ activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/consume/ConsumeTest.java
Wed Oct 22 11:23:55 2008
@@ -0,0 +1,66 @@
+/**
+ * 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.guice.consume;
+
+import junit.framework.Assert;
+import org.apache.camel.Produce;
+import org.apache.camel.Consume;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.guice.CamelModuleWithMatchingRoutes;
+import org.apache.camel.guice.produce.MyListener;
+import org.apache.camel.guice.produce.MyListenerService;
+import org.guiceyfruit.testing.junit3.GuiceyFruitTestCase;
+import com.google.inject.Inject;
+
+/**
+ * @version $Revision: 697494 $
+ */
+public class ConsumeTest extends GuiceyFruitTestCase {
+
+    @Inject
+    protected MyBean bean;
+    @Produce
+    protected ProducerTemplate template;
+
+    protected Object expectedBody = "<hello>world!</hello>";
+
+    public void testConsumingWorks() throws Exception {
+        template.sendBody("direct:start", expectedBody);
+
+        // lets check the bean has been invoked!
+        assertEquals("Body of bean", expectedBody, bean.body);
+    }
+
+    public static class Configuration extends CamelModuleWithMatchingRoutes {
+        @Override
+        protected void configure() {
+            super.configure();
+
+            bind(MyBean.class).asEagerSingleton();
+        }
+    }
+
+    public static class MyBean {
+        public String body;
+
+        @Consume(uri = "direct:start")
+        public void myHandler(String body) {
+            this.body = body;
+        }
+    }
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/consume/ConsumeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/produce/MyListener.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/produce/MyListener.java?rev=707155&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/produce/MyListener.java
(added)
+++ activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/produce/MyListener.java
Wed Oct 22 11:23:55 2008
@@ -0,0 +1,26 @@
+/**
+ * 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.guice.produce;
+
+/**
+ * @version $Revision: 697494 $
+ */
+public interface MyListener {
+
+    String sayHello(String name);
+
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/produce/MyListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/produce/MyListenerService.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/produce/MyListenerService.java?rev=707155&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/produce/MyListenerService.java
(added)
+++ activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/produce/MyListenerService.java
Wed Oct 22 11:23:55 2008
@@ -0,0 +1,38 @@
+/**
+ * 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.guice.produce;
+
+import org.apache.camel.Consume;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @version $Revision: 697494 $
+ */
+public class MyListenerService implements MyListener {
+
+    private static final Log LOG = LogFactory.getLog(MyListenerService.class);
+
+    public MyListenerService() {
+    }
+
+    @Consume(uri = "direct:myService")
+    public String sayHello(String name) {
+        LOG.debug("Invoked sayHello with: " + name);
+        return "Hello " + name;
+    }
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/produce/MyListenerService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/produce/ProduceTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/produce/ProduceTest.java?rev=707155&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/produce/ProduceTest.java
(added)
+++ activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/produce/ProduceTest.java
Wed Oct 22 11:23:55 2008
@@ -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.guice.produce;
+
+import junit.framework.Assert;
+import org.apache.camel.Produce;
+import org.apache.camel.guice.CamelModuleWithMatchingRoutes;
+import org.guiceyfruit.testing.junit3.GuiceyFruitTestCase;
+
+/**
+ * @version $Revision: 697494 $
+ */
+public class ProduceTest extends GuiceyFruitTestCase {
+
+    @Produce(uri = "direct:myService")
+    protected MyListener producer;
+
+    public void testInvokeService() throws Exception {
+        // lets send a message
+        String actual = producer.sayHello("James");
+        Assert.assertEquals("response", "Hello James", actual);
+    }
+
+    public static class Configuration extends CamelModuleWithMatchingRoutes {
+        @Override
+        protected void configure() {
+            super.configure();
+
+            bind(MyListenerService.class).asEagerSingleton();
+        }
+    }
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-guice/src/test/java/org/apache/camel/guice/produce/ProduceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java?rev=707155&r1=707154&r2=707155&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java
(original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java
Wed Oct 22 11:23:55 2008
@@ -25,9 +25,7 @@
 import javax.xml.bind.annotation.XmlTransient;
 
 import org.apache.camel.*;
-import org.apache.camel.component.bean.ProxyHelper;
-import org.apache.camel.impl.DefaultProducerTemplate;
-import org.apache.camel.impl.CamelPostProcessorSupport;
+import org.apache.camel.impl.CamelPostProcessorHelper;
 import org.apache.camel.spring.util.ReflectionUtils;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
@@ -38,8 +36,6 @@
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
 
-import static org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException;
-
 /**
  * A bean post processor which implements the <a href="http://activemq.apache.org/camel/bean-integration.html">Bean
Integration</a>
  * features in Camel such as the <a href="http://activemq.apache.org/camel/bean-injection.html">Bean
Injection</a> of objects like
@@ -66,7 +62,7 @@
     @XmlTransient
     private ApplicationContext applicationContext;
     @XmlTransient
-    private CamelPostProcessorSupport postProcessor;
+    private CamelPostProcessorHelper postProcessor;
 
     public CamelBeanPostProcessor() {
     }
@@ -102,7 +98,7 @@
 
     public void setCamelContext(SpringCamelContext camelContext) {
         this.camelContext = camelContext;
-        postProcessor = new CamelPostProcessorSupport(camelContext) {
+        postProcessor = new CamelPostProcessorHelper(camelContext) {
             @Override
             protected RuntimeException createProxyInstantiationRuntimeException(Class<?>
type, Endpoint endpoint, Exception e) {
                 return new BeanInstantiationException(type, "Could not instantiate proxy
of type " + type.getName() + " on endpoint " + endpoint, e);
@@ -198,7 +194,7 @@
         });
     }
 
-    public CamelPostProcessorSupport getPostProcessor() {
+    public CamelPostProcessorHelper getPostProcessor() {
         ObjectHelper.notNull(postProcessor, "postProcessor");
         return postProcessor;
     }

Modified: activemq/camel/trunk/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/pom.xml?rev=707155&r1=707154&r2=707155&view=diff
==============================================================================
--- activemq/camel/trunk/pom.xml (original)
+++ activemq/camel/trunk/pom.xml Wed Oct 22 11:23:55 2008
@@ -72,7 +72,7 @@
     <hibernate-entitymanager-version>3.2.1.ga</hibernate-entitymanager-version>
     <hsqldb-version>1.8.0.7</hsqldb-version>
     <groovy-version>1.5.6</groovy-version>
-    <guiceyfruit-version>2.0-beta-2</guiceyfruit-version>
+    <guiceyfruit-version>2.0-beta-3</guiceyfruit-version>
     <junit-version>3.8.2</junit-version>
     <saxon-version>9.1.0.1</saxon-version>
     <scala-version>2.7.2-rc1</scala-version>
@@ -747,6 +747,11 @@
         <artifactId>guiceyfruit-core</artifactId>
         <version>${guiceyfruit-version}</version>
       </dependency>
+      <dependency>
+        <groupId>org.guiceyfruit</groupId>
+        <artifactId>guiceyfruit-junit3</artifactId>
+        <version>${guiceyfruit-version}</version>
+      </dependency>
 
       <!-- optional mina dependencies -->
       <dependency>



Mime
View raw message