This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 3512e9b CAMEL-16459 jsonpath: If used after platform-http-vertx, it causes PathNotFoundException (#5299) 3512e9b is described below commit 3512e9b3fdea84bf1011da2b7f0d381b5b6b5235 Author: JiriOndrusek <ondrusek.j...@gmail.com> AuthorDate: Thu Apr 8 06:21:00 2021 +0200 CAMEL-16459 jsonpath: If used after platform-http-vertx, it causes PathNotFoundException (#5299) --- components/camel-jsonpath/pom.xml | 12 ++- .../org/apache/camel/jsonpath/JsonPathEngine.java | 8 +- .../camel/jsonpath/JsonPathPlatformHttpTest.java | 92 ++++++++++++++++++++++ .../ROOT/pages/camel-3x-upgrade-guide-3_10.adoc | 9 +++ 4 files changed, 116 insertions(+), 5 deletions(-) diff --git a/components/camel-jsonpath/pom.xml b/components/camel-jsonpath/pom.xml index b33ed03..13b81ac 100644 --- a/components/camel-jsonpath/pom.xml +++ b/components/camel-jsonpath/pom.xml @@ -79,11 +79,21 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-platform-http-vertx</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> <scope>test</scope> </dependency> - + <dependency> + <groupId>io.rest-assured</groupId> + <artifactId>rest-assured</artifactId> + <version>${rest-assured-version}</version> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java b/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java index e62cb7d..6fb4f8c 100644 --- a/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java +++ b/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java @@ -181,11 +181,11 @@ public class JsonPathEngine { List list = (List) json; return JsonPath.using(configuration).parse(list).read(path); } else { - // can we find an adapter which can read the message body/header - Object answer = readWithAdapter(path, exchange); + //try to auto convert into inputStream + Object answer = readWithInputStream(path, exchange); if (answer == null) { - // fallback and attempt input stream for any other types - answer = readWithInputStream(path, exchange); + // fallback and attempt an adapter which can read the message body/header + answer = readWithAdapter(path, exchange); } if (answer != null) { return answer; diff --git a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathPlatformHttpTest.java b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathPlatformHttpTest.java new file mode 100644 index 0000000..1e71ef3 --- /dev/null +++ b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathPlatformHttpTest.java @@ -0,0 +1,92 @@ +/* + * 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.jsonpath; + +import io.restassured.RestAssured; +import io.restassured.http.ContentType; +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.platform.http.vertx.VertxPlatformHttpServer; +import org.apache.camel.component.platform.http.vertx.VertxPlatformHttpServerConfiguration; +import org.apache.camel.model.ProcessorDefinition; +import org.apache.camel.test.AvailablePortFinder; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class JsonPathPlatformHttpTest extends CamelTestSupport { + + public static final String BODY = "{\"room\":{\"temperature\":30}}"; + public static final String JSON_PATH = "$.room[?(@.temperature > 20)]"; + public static final String RESULT = "HOT"; + + private static final int PORT = AvailablePortFinder.getNextAvailable(); + + @Test + public void testWithPlatformHttp() { + String result = RestAssured.given() + .port(PORT) + .contentType(ContentType.JSON) + .body(BODY) + .post("/getTemperature") + .then() + .statusCode(200) + .extract().asString(); + + assertEquals(RESULT, result); + } + + @Test + public void testWithoutPlatformHttp() { + String result = template.requestBody("direct:getTemperature", BODY, String.class); + + assertEquals(RESULT, result); + } + + @Override + protected CamelContext createCamelContext() throws Exception { + CamelContext context = super.createCamelContext(); + + VertxPlatformHttpServerConfiguration conf = new VertxPlatformHttpServerConfiguration(); + conf.setBindPort(PORT); + + context.addService(new VertxPlatformHttpServer(conf)); + + return context; + + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + + addRoute("platform-http:/getTemperature"); + + addRoute("direct:getTemperature"); + } + + private ProcessorDefinition<?> addRoute(String from) { + return from(from).choice().when().jsonpath(JSON_PATH).setBody(simple("HOT")) + .otherwise().setBody(constant("WARM")).end(); + } + }; + } + +} diff --git a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_10.adoc b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_10.adoc index cd88179..db9a465 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_10.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_10.adoc @@ -21,3 +21,12 @@ The option configures the pool size of the scheduled thread pool used by the sch If the scheduler thread is being blocked by anywhere in the downstream routing, and you want the scheduler to schedule with a fixed interval, you can use the Threads EIP as queue for pending tasks. +=== camel-jsonpath + +Usage of `JacksonJsonAdapter` has been slightly changed. + +Component was trying to use `JacksonJsonAdapter` ahead of automatic conversion of the payload to the `InputStream` +in the previous version. New version tries to convert the payload into `InpuStream` first. `JacksonJsonAdapter` is used +only if conversion to `InputStream` is not possible. + +Order of the basic payload types (like `String`, `Map`, `File`) has not been changed.