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 fdccb99 CAMEL-10165: Fixed issue with camel-cxf getBasePath. Thanks to Krzysztof Mackowiak for patch. Added fix for https as well. fdccb99 is described below commit fdccb99dff9ca3eb53035b4e117a8a7023ec47f7 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Jan 11 15:17:01 2018 +0100 CAMEL-10165: Fixed issue with camel-cxf getBasePath. Thanks to Krzysztof Mackowiak for patch. Added fix for https as well. --- .../common/message/DefaultCxfMessageMapper.java | 3 + .../component/cxf/cxfbean/Camel10165BugTest.java | 75 ++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/message/DefaultCxfMessageMapper.java b/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/message/DefaultCxfMessageMapper.java index be85bb5..55f818e 100644 --- a/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/message/DefaultCxfMessageMapper.java +++ b/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/message/DefaultCxfMessageMapper.java @@ -156,6 +156,9 @@ public class DefaultCxfMessageMapper implements CxfMessageMapper { if (answer == null) { answer = camelExchange.getFromEndpoint().getEndpointUri(); + // remove leading scheme before the http(s) transport so we build a correct base path + answer = answer.replaceFirst("^\\w+:http", "http"); + answer = answer.replaceFirst("^\\w+:https", "https"); } return answer; diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/Camel10165BugTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/Camel10165BugTest.java new file mode 100644 index 0000000..dd53c2e --- /dev/null +++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/Camel10165BugTest.java @@ -0,0 +1,75 @@ +/** + * 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.cxf.cxfbean; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.cxf.CXFTestSupport; +import org.apache.camel.impl.JndiRegistry; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class Camel10165BugTest extends CamelTestSupport { + + private static final int PORT1 = CXFTestSupport.getPort("Camel10165BugTest.1"); + + @Test + public void testCallServiceWithBasePath() throws Exception { + String request = "abc"; + String response = template.requestBody("http://localhost:" + PORT1 + "/basePath/echo", request, String.class); + assertEquals(request, response); + } + + @Test + public void testCallServiceWithoutBasePath() throws Exception { + String request = "abc"; + String response = template.requestBody("http://localhost:" + PORT1 + "/echo", request, String.class); + assertEquals(request, response); + } + + @Override + protected RoutesBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("jetty:http://localhost:" + PORT1 + "/?matchOnUriPrefix=true") + .to("cxfbean:echoService"); + + from("jetty:http://localhost:" + PORT1 + "/basePath/?matchOnUriPrefix=true") + .to("cxfbean:echoService"); + } + }; + } + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry registry = super.createRegistry(); + registry.bind("echoService", new EchoService()); + return registry; + } + + @Path("echo") + public class EchoService { + @POST + public String echo(String request) { + return request; + } + } +} -- To stop receiving notification emails like this one, please contact ['"commits@camel.apache.org" <commits@camel.apache.org>'].