Return-Path: Delivered-To: apmail-camel-commits-archive@www.apache.org Received: (qmail 22064 invoked from network); 1 Nov 2009 13:28:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 1 Nov 2009 13:28:46 -0000 Received: (qmail 33340 invoked by uid 500); 1 Nov 2009 13:28:46 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 33292 invoked by uid 500); 1 Nov 2009 13:28:46 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 33283 invoked by uid 99); 1 Nov 2009 13:28:46 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 01 Nov 2009 13:28:46 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 01 Nov 2009 13:28:43 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3BBFF23888DA; Sun, 1 Nov 2009 13:28:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r831674 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/bean/ main/java/org/apache/camel/language/ test/java/org/apache/camel/component/bean/ test/java/org/apache/camel/processor/ Date: Sun, 01 Nov 2009 13:28:16 -0000 To: commits@camel.apache.org From: davsclaus@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091101132817.3BBFF23888DA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: davsclaus Date: Sun Nov 1 13:28:16 2009 New Revision: 831674 URL: http://svn.apache.org/viewvc?rev=831674&view=rev Log: CAMEL-2122: Added resultType to @XPath. Thanks to Maciej Prochniak for patch. Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithXPathInjectionUsingResultTypeTest.java (with props) Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/XPathAnnotationExpressionFactory.java camel/trunk/camel-core/src/main/java/org/apache/camel/language/XPath.java camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThrottelingRoutePolicyTest.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/XPathAnnotationExpressionFactory.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/XPathAnnotationExpressionFactory.java?rev=831674&r1=831673&r2=831674&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/XPathAnnotationExpressionFactory.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/XPathAnnotationExpressionFactory.java Sun Nov 1 13:28:16 2009 @@ -36,7 +36,7 @@ @Override public Expression createExpression(CamelContext camelContext, Annotation annotation, LanguageAnnotation languageAnnotation, Class expressionReturnType) { String xpath = getExpressionFromAnnotation(annotation); - XPathBuilder builder = XPathBuilder.xpath(xpath); + XPathBuilder builder = XPathBuilder.xpath(xpath, getResultType(annotation)); NamespacePrefix[] namespaces = getExpressionNameSpacePrefix(annotation); if (namespaces != null) { for (NamespacePrefix namespacePrefix : namespaces) { @@ -46,14 +46,24 @@ } return builder; } - + + protected Class getResultType(Annotation annotation) { + try { + Method method = annotation.getClass().getMethod("resultType"); + Object value = ObjectHelper.invokeMethod(method, annotation); + return (Class) value; + } catch (NoSuchMethodException e) { + throw new IllegalArgumentException("Cannot determine the annotation: " + annotation + " as it does not have an resultType() method", e); + } + } + protected NamespacePrefix[] getExpressionNameSpacePrefix(Annotation annotation) { try { Method method = annotation.getClass().getMethod("namespaces"); Object value = ObjectHelper.invokeMethod(method, annotation); - return (NamespacePrefix[])value; + return (NamespacePrefix[]) value; } catch (NoSuchMethodException e) { throw new IllegalArgumentException("Cannot determine the annotation: " + annotation + " as it does not have an namespaces() method", e); - } + } } } Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/language/XPath.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/language/XPath.java?rev=831674&r1=831673&r2=831674&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/language/XPath.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/language/XPath.java Sun Nov 1 13:28:16 2009 @@ -22,6 +22,8 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.w3c.dom.NodeList; + import org.apache.camel.component.bean.XPathAnnotationExpressionFactory; /** @@ -40,4 +42,6 @@ NamespacePrefix[] namespaces() default { @NamespacePrefix(prefix = "soap", uri = "http://www.w3.org/2003/05/soap-envelope"), @NamespacePrefix(prefix = "xsd", uri = "http://www.w3.org/2001/XMLSchema")}; + + Class resultType() default NodeList.class; } \ No newline at end of file Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithXPathInjectionUsingResultTypeTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithXPathInjectionUsingResultTypeTest.java?rev=831674&view=auto ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithXPathInjectionUsingResultTypeTest.java (added) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithXPathInjectionUsingResultTypeTest.java Sun Nov 1 13:28:16 2009 @@ -0,0 +1,52 @@ +/** + * 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.bean; + +import javax.naming.Context; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.language.XPath; +import org.apache.camel.util.jndi.JndiContext; + +public class BeanWithXPathInjectionUsingResultTypeTest extends ContextTestSupport { + + protected MyBean myBean = new MyBean(); + + public void testSendMessage() throws Exception { + template.sendBody("bean:myBean", "12"); + assertEquals("bean ab: " + myBean, "12", myBean.ab); + assertEquals("bean abText: " + myBean, "a12", myBean.abText); + } + + @Override + protected Context createJndiContext() throws Exception { + JndiContext answer = new JndiContext(); + answer.bind("myBean", myBean); + return answer; + } + + public static class MyBean { + public String ab; + public String abText; + + public void read(@XPath("//a/b") String ab, + @XPath(value = "concat('a',//a/b)", resultType = String.class) String abText) { + this.ab = ab; + this.abText = abText; + } + } +} Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithXPathInjectionUsingResultTypeTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithXPathInjectionUsingResultTypeTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThrottelingRoutePolicyTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThrottelingRoutePolicyTest.java?rev=831674&r1=831673&r2=831674&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThrottelingRoutePolicyTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThrottelingRoutePolicyTest.java Sun Nov 1 13:28:16 2009 @@ -29,12 +29,12 @@ private int size = 100; public void testThrottelingRoutePolicy() throws Exception { - getMockEndpoint("mock:result").expectedMessageCount(size); - for (int i = 0; i < size; i++) { template.sendBody(url, "Message " + i); } + getMockEndpoint("mock:result").expectedMessageCount(size); + // now start the route context.startRoute("myRoute");