You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/10/26 18:11:59 UTC
svn commit: r588697 - in /activemq/camel/trunk:
camel-core/src/main/java/org/apache/camel/
camel-core/src/main/java/org/apache/camel/builder/
camel-core/src/main/java/org/apache/camel/component/bean/
camel-core/src/main/java/org/apache/camel/impl/ came...
Author: jstrachan
Date: Fri Oct 26 09:11:55 2007
New Revision: 588697
URL: http://svn.apache.org/viewvc?rev=588697&view=rev
Log:
added a fix and a test case for https://issues.apache.org/activemq/browse/CAMEL-192 along with supporting @OutHeaders and ensuring that all injected producers & consumers are properly shut down
Added:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/OutHeaders.java
- copied, changed from r588611, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Headers.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithPropertiesAndHeadersAndBodyInjectionTest.java
- copied, changed from r588611, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithPropertiesAndHeadersInjectionTest.java
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/bind/
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/bind/JmsMessageBindTest.java (with props)
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/bind/MyBean.java (with props)
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/bind/
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/bind/spring.xml
- copied, changed from r588611, activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/remoting/spring.xml
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/AmbiguousMethodCallException.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ParameterInfo.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java
Copied: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/OutHeaders.java (from r588611, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Headers.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/OutHeaders.java?p2=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/OutHeaders.java&p1=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Headers.java&r1=588611&r2=588697&rev=588697&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Headers.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/OutHeaders.java Fri Oct 26 09:11:55 2007
@@ -22,12 +22,12 @@
import java.lang.annotation.Target;
/**
- * Marks a parameter as being an injection point of the headers of an inbound {@link Message}
+ * Marks a parameter as being an injection point of the headers of an outbound {@link Message}
*
* @see Message#getHeaders()
* @version $Revision: 523756 $
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER })
-public @interface Headers {
+public @interface OutHeaders {
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java?rev=588697&r1=588696&r2=588697&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java Fri Oct 26 09:11:55 2007
@@ -69,7 +69,7 @@
* @see Message#getHeaders()
* @return an expression object which will return the inbound headers
*/
- public static <E extends Exchange> Expression<E> headersExpresion() {
+ public static <E extends Exchange> Expression<E> headersExpression() {
return new Expression<E>() {
public Object evaluate(E exchange) {
return exchange.getIn().getHeaders();
@@ -107,6 +107,25 @@
}
/**
+ * Returns an expression for the outbound message headers
+ *
+ * @see Message#getHeaders()
+ * @return an expression object which will return the inbound headers
+ */
+ public static <E extends Exchange> Expression<E> outHeadersExpression() {
+ return new Expression<E>() {
+ public Object evaluate(E exchange) {
+ return exchange.getOut().getHeaders();
+ }
+
+ @Override
+ public String toString() {
+ return "outHeaders";
+ }
+ };
+ }
+
+ /**
* Returns an expression for the property value with the given name
*
* @see Exchange#getProperty(String)
@@ -133,7 +152,7 @@
* @see Exchange#getProperties()
* @return an expression object which will return the properties
*/
- public static <E extends Exchange> Expression<E> propertiesExpresion() {
+ public static <E extends Exchange> Expression<E> propertiesExpression() {
return new Expression<E>() {
public Object evaluate(E exchange) {
return exchange.getProperties();
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/AmbiguousMethodCallException.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/AmbiguousMethodCallException.java?rev=588697&r1=588696&r2=588697&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/AmbiguousMethodCallException.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/AmbiguousMethodCallException.java Fri Oct 26 09:11:55 2007
@@ -17,6 +17,7 @@
package org.apache.camel.component.bean;
import java.util.List;
+import java.util.Collection;
import org.apache.camel.CamelExchangeException;
import org.apache.camel.Exchange;
@@ -28,9 +29,9 @@
* @version $Revision: $
*/
public class AmbiguousMethodCallException extends CamelExchangeException {
- private final List<MethodInfo> methods;
+ private final Collection<MethodInfo> methods;
- public AmbiguousMethodCallException(Exchange exchange, List<MethodInfo> methods) {
+ public AmbiguousMethodCallException(Exchange exchange, Collection<MethodInfo> methods) {
super("Ambiguous method invocations possible: " + methods, exchange);
this.methods = methods;
}
@@ -38,7 +39,7 @@
/**
* The ambiguous methods for which a single method could not be chosen
*/
- public List<MethodInfo> getMethods() {
+ public Collection<MethodInfo> getMethods() {
return methods;
}
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java?rev=588697&r1=588696&r2=588697&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java Fri Oct 26 09:11:55 2007
@@ -32,6 +32,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -48,6 +49,7 @@
private Map<String, MethodInfo> operations = new ConcurrentHashMap<String, MethodInfo>();
private MethodInfo defaultMethod;
private List<MethodInfo> operationsWithBody = new ArrayList<MethodInfo>();
+ private List<MethodInfo> operationsWithCustomAnnotation = new ArrayList<MethodInfo>();;
public BeanInfo(CamelContext camelContext, Class type, ParameterMappingStrategy strategy) {
this.camelContext = camelContext;
@@ -129,11 +131,17 @@
parameterAnnotations);
hasCustomAnnotation |= expression != null;
+ ParameterInfo parameterInfo = new ParameterInfo(i, parameterType, parameterAnnotations,
+ expression);
+ parameters.add(parameterInfo);
+
if (expression == null) {
hasCustomAnnotation |= ObjectHelper.hasAnnotation(parameterAnnotations, Body.class);
if (bodyParameters.isEmpty()) {
// lets assume its the body
expression = ExpressionBuilder.bodyExpression(parameterType);
+ parameterInfo.setExpression(expression);
+ bodyParameters.add(parameterInfo);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("No expression available for method: " + method.toString()
@@ -144,12 +152,6 @@
}
}
- ParameterInfo parameterInfo = new ParameterInfo(i, parameterType, parameterAnnotations,
- expression);
- parameters.add(parameterInfo);
- if (isPossibleBodyParameter(parameterAnnotations)) {
- bodyParameters.add(parameterInfo);
- }
}
// now lets add the method to the repository
@@ -168,6 +170,9 @@
if (methodInfo.hasBodyParameter()) {
operationsWithBody.add(methodInfo);
}
+ if (methodInfo.isHasCustomAnnotation() && !methodInfo.hasBodyParameter()) {
+ operationsWithCustomAnnotation.add(methodInfo);
+ }
return methodInfo;
}
@@ -184,66 +189,81 @@
if (operationsWithBody.size() == 1) {
return operationsWithBody.get(0);
} else if (!operationsWithBody.isEmpty()) {
- // lets see if we can find a method who's body param type matches
- // the message body
- Message in = exchange.getIn();
- Object body = in.getBody();
- if (body != null) {
- Class bodyType = body.getClass();
-
- List<MethodInfo> possibles = new ArrayList<MethodInfo>();
- for (MethodInfo methodInfo : operationsWithBody) {
- if (methodInfo.bodyParameterMatches(bodyType)) {
- possibles.add(methodInfo);
- }
+ return chooseMethodWithMatchingBody(exchange, operationsWithBody);
+ }
+ else if (operationsWithCustomAnnotation.size() == 1) {
+ return operationsWithCustomAnnotation.get(0);
+ }
+ return null;
+ }
+
+ protected MethodInfo chooseMethodWithMatchingBody(Exchange exchange, Collection<MethodInfo> operationList) throws AmbiguousMethodCallException {
+ // lets see if we can find a method who's body param type matches
+ // the message body
+ Message in = exchange.getIn();
+ Object body = in.getBody();
+ if (body != null) {
+ Class bodyType = body.getClass();
+
+ List<MethodInfo> possibles = new ArrayList<MethodInfo>();
+ for (MethodInfo methodInfo : operationList) {
+ if (methodInfo.bodyParameterMatches(bodyType)) {
+ possibles.add(methodInfo);
}
- if (possibles.size() == 1) {
- return possibles.get(0);
- } else if (possibles.isEmpty()) {
- // lets try converting
- Object newBody = null;
- MethodInfo matched = null;
- for (MethodInfo methodInfo : operationsWithBody) {
- Object value = convertToType(exchange, methodInfo.getBodyParameterType(), body);
- if (value != null) {
- if (newBody != null) {
- throw new AmbiguousMethodCallException(exchange, Arrays.asList(matched,
- methodInfo));
- } else {
- newBody = value;
- matched = methodInfo;
- }
- }
- }
- if (matched != null) {
- in.setBody(newBody);
- return matched;
- }
- } else {
- // if we have only one method with custom annotations lets choose that
- MethodInfo chosen = null;
- for (MethodInfo possible : possibles) {
- if (possible.isHasCustomAnnotation()) {
- if (chosen != null) {
- chosen = null;
- break;
- }
- else {
- chosen = possible;
- }
+ }
+ if (possibles.size() == 1) {
+ return possibles.get(0);
+ } else if (possibles.isEmpty()) {
+ // lets try converting
+ Object newBody = null;
+ MethodInfo matched = null;
+ for (MethodInfo methodInfo : operationList) {
+ Object value = convertToType(exchange, methodInfo.getBodyParameterType(), body);
+ if (value != null) {
+ if (newBody != null) {
+ throw new AmbiguousMethodCallException(exchange, Arrays.asList(matched,
+ methodInfo));
+ } else {
+ newBody = value;
+ matched = methodInfo;
}
}
- if (chosen != null) {
- return chosen;
- }
- throw new AmbiguousMethodCallException(exchange, possibles);
}
+ if (matched != null) {
+ in.setBody(newBody);
+ return matched;
+ }
+ } else {
+ // if we only have a single method with custom annotations, lets use that one
+ if (operationsWithCustomAnnotation.size() == 1) {
+ return operationsWithCustomAnnotation.get(0);
+ }
+ return chooseMethodWithCustomAnnotations(exchange, possibles);
}
- return null;
}
return null;
}
+ protected MethodInfo chooseMethodWithCustomAnnotations(Exchange exchange, Collection<MethodInfo> possibles) throws AmbiguousMethodCallException {
+ // if we have only one method with custom annotations lets choose that
+ MethodInfo chosen = null;
+ for (MethodInfo possible : possibles) {
+ if (possible.isHasCustomAnnotation()) {
+ if (chosen != null) {
+ chosen = null;
+ break;
+ }
+ else {
+ chosen = possible;
+ }
+ }
+ }
+ if (chosen != null) {
+ return chosen;
+ }
+ throw new AmbiguousMethodCallException(exchange, possibles);
+ }
+
/**
* Creates an expression for the given parameter type if the parameter can
* be mapped automatically or null if the parameter cannot be mapped due to
@@ -267,7 +287,15 @@
protected boolean isPossibleBodyParameter(Annotation[] annotations) {
if (annotations != null) {
for (Annotation annotation : annotations) {
- if ((annotation instanceof Property) || (annotation instanceof Header)) {
+ if ((annotation instanceof Property)
+ || (annotation instanceof Header)
+ || (annotation instanceof Headers)
+ || (annotation instanceof OutHeaders)
+ || (annotation instanceof Properties)) {
+ return false;
+ }
+ LanguageAnnotation languageAnnotation = annotation.annotationType().getAnnotation(LanguageAnnotation.class);
+ if (languageAnnotation != null) {
return false;
}
}
@@ -282,12 +310,14 @@
Property propertyAnnotation = (Property)annotation;
return ExpressionBuilder.propertyExpression(propertyAnnotation.name());
} else if (annotation instanceof Properties) {
- return ExpressionBuilder.propertiesExpresion();
+ return ExpressionBuilder.propertiesExpression();
} else if (annotation instanceof Header) {
Header headerAnnotation = (Header)annotation;
return ExpressionBuilder.headerExpression(headerAnnotation.name());
} else if (annotation instanceof Headers) {
- return ExpressionBuilder.headersExpresion();
+ return ExpressionBuilder.headersExpression();
+ } else if (annotation instanceof OutHeaders) {
+ return ExpressionBuilder.outHeadersExpression();
} else {
LanguageAnnotation languageAnnotation = annotation.annotationType().getAnnotation(LanguageAnnotation.class);
if (languageAnnotation != null) {
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ParameterInfo.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ParameterInfo.java?rev=588697&r1=588696&r2=588697&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ParameterInfo.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ParameterInfo.java Fri Oct 26 09:11:55 2007
@@ -27,7 +27,7 @@
private final int index;
private final Class type;
private final Annotation[] annotations;
- private final Expression expression;
+ private Expression expression;
public ParameterInfo(int index, Class type, Annotation[] annotations, Expression expression) {
this.index = index;
@@ -50,5 +50,9 @@
public Class getType() {
return type;
+ }
+
+ public void setExpression(Expression expression) {
+ this.expression = expression;
}
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=588697&r1=588696&r2=588697&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Fri Oct 26 09:11:55 2007
@@ -331,6 +331,12 @@
}
+ public void addServiceToClose(Object object) {
+ if (object instanceof Service) {
+ Service service = (Service) object;
+ servicesToClose.add(service);
+ }
+ }
// Helper methods
// -----------------------------------------------------------------------
Copied: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithPropertiesAndHeadersAndBodyInjectionTest.java (from r588611, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithPropertiesAndHeadersInjectionTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithPropertiesAndHeadersAndBodyInjectionTest.java?p2=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithPropertiesAndHeadersAndBodyInjectionTest.java&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithPropertiesAndHeadersInjectionTest.java&r1=588611&r2=588697&rev=588697&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithPropertiesAndHeadersInjectionTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithPropertiesAndHeadersAndBodyInjectionTest.java Fri Oct 26 09:11:55 2007
@@ -16,6 +16,11 @@
*/
package org.apache.camel.component.bean;
+import java.util.Map;
+
+import javax.naming.Context;
+
+import org.apache.camel.Body;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
import org.apache.camel.Headers;
@@ -28,13 +33,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import javax.naming.Context;
-import java.util.Map;
-
/**
* @version $Revision: 1.1 $
*/
-public class BeanWithPropertiesAndHeadersInjectionTest extends ContextTestSupport {
+public class BeanWithPropertiesAndHeadersAndBodyInjectionTest extends ContextTestSupport {
private static final transient Log LOG = LogFactory.getLog(BeanRouteTest.class);
protected MyBean myBean = new MyBean();
@@ -47,6 +49,7 @@
Message in = exchange.getIn();
in.setHeader("h1", "xyz");
in.setHeader("h2", 456);
+ in.setBody("TheBody");
}
});
@@ -60,6 +63,7 @@
assertEquals("bar.h1", "xyz", bar.get("h1"));
assertEquals("bar.h2", 456, bar.get("h2"));
+ assertEquals("body", "TheBody", myBean.body);
}
@Override
@@ -80,15 +84,17 @@
public static class MyBean {
public Map foo;
public Map bar;
+ private String body;
@Override
public String toString() {
- return "MyBean[foo: " + foo + " bar: " + bar + "]";
+ return "MyBean[foo: " + foo + " bar: " + bar + " body: " + body + "]";
}
- public void myMethod(@Properties Map foo, @Headers Map bar) {
+ public void myMethod(@Properties Map foo, @Headers Map bar, @Body String body) {
this.foo = foo;
this.bar = bar;
+ this.body = body;
LOG.info("myMethod() method called on " + this);
}
}
Added: activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/bind/JmsMessageBindTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/bind/JmsMessageBindTest.java?rev=588697&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/bind/JmsMessageBindTest.java (added)
+++ activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/bind/JmsMessageBindTest.java Fri Oct 26 09:11:55 2007
@@ -0,0 +1,57 @@
+/**
+ *
+ * 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.jms.bind;
+
+import java.util.Map;
+
+import org.apache.camel.spring.SpringTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class JmsMessageBindTest extends SpringTestSupport {
+ public void testSendAMessageToBean() throws Exception {
+ MockEndpoint endpoint = getMockEndpoint("mock:result");
+ endpoint.expectedBodiesReceived("Completed");
+
+ template.sendBodyAndHeader("activemq:Test.BindingQueue", "SomeBody", "foo", "bar");
+
+ // lets wait for the method to be invoked
+ assertMockEndpointsSatisifed();
+
+ // now lets test that the bean is correct
+ MyBean bean = getMandatoryBean(MyBean.class, "myBean");
+ assertEquals("body", "SomeBody", bean.getBody());
+ Map headers = bean.getHeaders();
+ assertNotNull("No headers!", headers);
+ System.out.println("Headers: " + headers);
+
+ assertEquals("foo header", "bar", headers.get("foo"));
+ }
+
+ @Override
+ protected int getExpectedRouteCount() {
+ return 0;
+ }
+
+ protected ClassPathXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/component/jms/bind/spring.xml");
+ }
+}
Propchange: activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/bind/JmsMessageBindTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/bind/MyBean.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/bind/MyBean.java?rev=588697&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/bind/MyBean.java (added)
+++ activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/bind/MyBean.java Fri Oct 26 09:11:55 2007
@@ -0,0 +1,53 @@
+/**
+ *
+ * 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.jms.bind;
+
+import java.util.Map;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Headers;
+import org.apache.camel.MessageDriven;
+import org.apache.camel.ProducerTemplate;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class MyBean {
+ private Map headers;
+ private String body;
+ @EndpointInject(uri = "mock:result")
+ private ProducerTemplate producer;
+
+ @MessageDriven(uri = "activemq:Test.BindingQueue")
+ public void myMethod(@Headers Map headers, String body) {
+ System.out.println("Invoked bean with: " + headers + " and body: " + body);
+ this.headers = headers;
+ this.body = body;
+
+ // now lets notify we've completed
+ producer.sendBody("Completed");
+ }
+
+ public String getBody() {
+ return body;
+ }
+
+ public Map getHeaders() {
+ return headers;
+ }
+}
Propchange: activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/bind/MyBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/bind/spring.xml (from r588611, activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/remoting/spring.xml)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/bind/spring.xml?p2=activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/bind/spring.xml&p1=activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/remoting/spring.xml&r1=588611&r2=588697&rev=588697&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/remoting/spring.xml (original)
+++ activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/bind/spring.xml Fri Oct 26 09:11:55 2007
@@ -23,17 +23,9 @@
http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
">
- <bean id="sayService" class="org.apache.camel.spring.remoting.SayService"/>
+ <bean id="myBean" class="org.apache.camel.component.jms.bind.MyBean" scope="singleton"/>
<camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
- <!-- create the client proxy -->
- <proxy id="sayProxy" serviceUrl="activemq:test.serviceQueue"
- serviceInterface="org.apache.camel.spring.remoting.ISay"/>
-
- <!-- export the service -->
- <export id="say" uri="activemq:test.serviceQueue" serviceRef="sayService"
- serviceInterface="org.apache.camel.spring.remoting.ISay"/>
-
</camelContext>
<!-- configure the ActiveMQ component -->
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=588697&r1=588696&r2=588697&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 Fri Oct 26 09:11:55 2007
@@ -17,6 +17,7 @@
package org.apache.camel.spring;
import org.apache.camel.*;
+import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.component.bean.BeanProcessor;
import org.apache.camel.spring.util.ReflectionUtils;
import org.apache.camel.util.ObjectHelper;
@@ -53,8 +54,6 @@
@XmlTransient
private ApplicationContext applicationContext;
- // private List<Consumer> consumers = new ArrayList<Consumer>();
-
public CamelBeanPostProcessor() {
}
@@ -175,8 +174,7 @@
Processor processor = createConsumerProcessor(bean, method, endpoint);
LOG.info("Created processor: " + processor);
Consumer consumer = endpoint.createConsumer(processor);
- consumer.start();
- onConsumerAdded(consumer);
+ startService(consumer);
} catch (Exception e) {
LOG.warn(e);
throw new RuntimeCamelException(e);
@@ -185,6 +183,11 @@
}
}
+ protected void startService(Service service) throws Exception {
+ service.start();
+ camelContext.addServiceToClose(service);
+ }
+
/**
* Create a processor which invokes the given method when an incoming
* message exchange is received
@@ -195,9 +198,6 @@
return answer;
}
- protected void onConsumerAdded(Consumer consumer) {
- LOG.debug("Adding consumer: " + consumer);
- }
/**
* Creates the value for the injection point for the given annotation
@@ -227,7 +227,7 @@
protected PollingConsumer createInjectionPollingConsumer(Endpoint endpoint) {
try {
PollingConsumer pollingConsumer = endpoint.createPollingConsumer();
- pollingConsumer.start();
+ startService(pollingConsumer);
return pollingConsumer;
}
catch (Exception e) {
@@ -241,7 +241,7 @@
protected Producer createInjectionProducer(Endpoint endpoint) {
try {
Producer producer = endpoint.createProducer();
- producer.start();
+ startService(producer);
return producer;
} catch (Exception e) {
throw new RuntimeCamelException(e);