You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/11/11 20:07:46 UTC

[camel] 02/02: CAMEL-17187: camel-xpath - @XPath annotation should never pre-compile

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.11.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit cfc5f27a9cdbd9b0c2d36ac21ece6e6aa061ae96
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Nov 11 21:00:16 2021 +0100

    CAMEL-17187: camel-xpath - @XPath annotation should never pre-compile
---
 .../org/apache/camel/language/xpath/XPath.java     | 10 ---
 .../xpath/XPathAnnotationExpressionFactory.java    | 12 +--
 .../BeanWithXPathInjectionPreCompileTest.java      | 97 ----------------------
 3 files changed, 2 insertions(+), 117 deletions(-)

diff --git a/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPath.java b/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPath.java
index 922259f..718e07e 100644
--- a/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPath.java
+++ b/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPath.java
@@ -64,14 +64,4 @@ public @interface XPath {
      */
     boolean logNamespaces() default false;
 
-    /**
-     * Whether to enable pre-compiling the xpath expression during initialization phase. pre-compile is enabled by
-     * default.
-     *
-     * This can be used to turn off, for example in cases the compilation phase is desired at the starting phase, such
-     * as if the application is ahead of time compiled (for example with camel-quarkus) which would then load the xpath
-     * factory of the built operating system, and not a JVM runtime.
-     */
-    boolean preCompile() default true;
-
 }
diff --git a/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathAnnotationExpressionFactory.java b/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathAnnotationExpressionFactory.java
index 26aa250..ec76f1d 100644
--- a/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathAnnotationExpressionFactory.java
+++ b/components/camel-xpath/src/main/java/org/apache/camel/language/xpath/XPathAnnotationExpressionFactory.java
@@ -42,7 +42,8 @@ public class XPathAnnotationExpressionFactory extends DefaultAnnotationExpressio
         }
 
         XPathBuilder builder = XPathBuilder.xpath(xpath, resultType);
-        builder.preCompile(isPreCompile(annotation));
+        // @XPath annotation cannot pre-compile so turn it off
+        builder.preCompile(false);
         builder.setLogNamespaces(isLogNamespaces(annotation));
         NamespacePrefix[] namespaces = getExpressionNameSpacePrefix(annotation);
         if (namespaces != null) {
@@ -95,13 +96,4 @@ public class XPathAnnotationExpressionFactory extends DefaultAnnotationExpressio
         return false;
     }
 
-    protected boolean isPreCompile(Annotation annotation) {
-        // in case @XPath is extended in a custom annotation then it may not have the method
-        try {
-            return (boolean) getAnnotationObjectValue(annotation, "preCompile");
-        } catch (Exception e) {
-            // Do Nothing
-        }
-        return false;
-    }
 }
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/BeanWithXPathInjectionPreCompileTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/BeanWithXPathInjectionPreCompileTest.java
deleted file mode 100644
index 00586f3..0000000
--- a/core/camel-core/src/test/java/org/apache/camel/processor/BeanWithXPathInjectionPreCompileTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * 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.processor;
-
-import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.language.xpath.XPath;
-import org.apache.camel.spi.Registry;
-import org.junit.jupiter.api.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-public class BeanWithXPathInjectionPreCompileTest extends ContextTestSupport {
-    private static final Logger LOG = LoggerFactory.getLogger(BeanRouteTest.class);
-    protected MyBean myBean = new MyBean();
-
-    @Test
-    public void testSendMessage() throws Exception {
-        String expectedBody = "<env:Envelope xmlns:env='http://www.w3.org/2003/05/soap-envelope'><env:Body>"
-                              + "<foo>bar</foo></env:Body></env:Envelope>";
-
-        template.sendBodyAndHeader("direct:in", expectedBody, "foo", "bar");
-
-        assertEquals(expectedBody, myBean.body, "bean body: " + myBean);
-        assertEquals("bar", myBean.foo, "bean foo: " + myBean);
-    }
-
-    @Test
-    public void testSendTwoMessages() throws Exception {
-        // 1st message
-        String expectedBody = "<env:Envelope xmlns:env='http://www.w3.org/2003/05/soap-envelope'><env:Body>"
-                              + "<foo>bar</foo></env:Body></env:Envelope>";
-
-        template.sendBodyAndHeader("direct:in", expectedBody, "foo", "bar");
-
-        assertEquals(expectedBody, myBean.body, "bean body: " + myBean);
-        assertEquals("bar", myBean.foo, "bean foo: " + myBean);
-
-        // 2nd message
-        String expectedBody2 = "<env:Envelope xmlns:env='http://www.w3.org/2003/05/soap-envelope'><env:Body>"
-                               + "<foo>baz</foo></env:Body></env:Envelope>";
-
-        template.sendBodyAndHeader("direct:in", expectedBody2, "foo", "baz");
-
-        assertEquals(expectedBody2, myBean.body, "bean body: " + myBean);
-        assertEquals("baz", myBean.foo, "bean foo: " + myBean);
-    }
-
-    @Override
-    protected Registry createRegistry() throws Exception {
-        Registry answer = super.createRegistry();
-
-        answer.bind("myBean", myBean);
-        return answer;
-    }
-
-    @Override
-    protected RouteBuilder createRouteBuilder() {
-        return new RouteBuilder() {
-            public void configure() {
-                from("direct:in").bean("myBean");
-            }
-        };
-    }
-
-    public static class MyBean {
-        public String body;
-        public String foo;
-
-        @Override
-        public String toString() {
-            return "MyBean[foo: " + foo + " body: " + body + "]";
-        }
-
-        public void read(String body, @XPath(value = "/soap:Envelope/soap:Body/foo/text()", preCompile = false) String foo) {
-            this.foo = foo;
-            this.body = body;
-            LOG.info("read() method called on " + this);
-        }
-    }
-}