This is an automated email from the ASF dual-hosted git repository.
Croway pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.18.x by this push:
new 26f6ff88116c CAMEL-27062: camel-cxf, camel-cxf-rest - the producers
say the former operationName header is not read, and do not send it (#30232)
26f6ff88116c is described below
commit 26f6ff88116c77826f85f60413bd508a7c62e9a8
Author: Federico Mariani <[email protected]>
AuthorDate: Tue Nov 17 14:02:04 2026 +0100
CAMEL-27062: camel-cxf, camel-cxf-rest - the producers say the former
operationName header is not read, and do not send it (#30232)
* CAMEL-27062: camel-cxf - the producer warns about the former
operationName header and an operation it picks itself, and does not send the
former header names
Since CAMEL-23526 the producer selects the operation from the
CamelCxfOperationName and CamelCxfOperationNamespace headers. A route that
still set operationName got no error and no WARN, and the producer invoked
the first operation that CXF returns, which is not the first one of the
WSDL.
- CxfProducer logs a WARN once when operationName or operationNamespace is
set without its replacement, and once when neither the header nor
defaultOperationName selects the operation of a service with more than one
operation. The former headers stay unread.
- CxfHeaderFilterStrategy filters operationName and operationNamespace
again, as it did before the rename.
- The "Can't find the BindingOperationInfo" error names the current headers
and options, and lists the operations of the service.
* CAMEL-27062: camel-cxf-rest - the proxy producer names the
CamelCxfOperationName header when it is missing, and does not send the former
operationName header
Since CAMEL-23526 the cxfrs producer finds the method of the resource class
from the CamelCxfOperationName header. With the proxy-based client API, a
route that still set operationName failed with "Cannot find method with
name: null", and the operationName header was sent to the service as an
HTTP header, with both client APIs.
- CxfRsProducer fails with a NoSuchMethodException that names
CamelCxfOperationName when this header is not set, and says that
operationName is not read when it is set. Every such exchange fails, so
the error is the hint and there is no WARN.
- CxfRsHeaderFilterStrategy filters operationName again, as it did before
the rename.
* CAMEL-27062: camel-cxf, camel-cxfrs - the upgrade guide entry links the
4.21 entry and uses shorter sentences
The entry links the camel-cxf section of the 4.21 upgrade guide, and says
that the filters drop the former header names again "as they did before
the rename", in shorter sentences.
(cherry picked from commit 6cb84a4de0ed76f306f50f72e1508756b091381a)
---
.../src/main/docs/cxfrs-component.adoc | 4 +
.../cxf/jaxrs/CxfRsHeaderFilterStrategy.java | 2 +
.../camel/component/cxf/jaxrs/CxfRsProducer.java | 26 +-
.../cxf/jaxrs/CxfRsHeaderFilterStrategyTest.java | 9 +
.../jaxrs/CxfRsProducerOperationHeaderTest.java | 205 ++++++++++++++
.../src/main/docs/cxf-component.adoc | 9 +-
.../camel/component/cxf/jaxws/CxfProducer.java | 63 ++++-
.../cxf/jaxws/CxfProducerOperationHeaderTest.java | 295 +++++++++++++++++++++
.../transport/header/CxfHeaderFilterStrategy.java | 3 +
9 files changed, 607 insertions(+), 9 deletions(-)
diff --git
a/components/camel-cxf/camel-cxf-rest/src/main/docs/cxfrs-component.adoc
b/components/camel-cxf/camel-cxf-rest/src/main/docs/cxfrs-component.adoc
index e5c97f6400b8..156c39118375 100644
--- a/components/camel-cxf/camel-cxf-rest/src/main/docs/cxfrs-component.adoc
+++ b/components/camel-cxf/camel-cxf-rest/src/main/docs/cxfrs-component.adoc
@@ -317,6 +317,10 @@ API].
You need to specify the operation name in the message header and
prepare the parameter in the message body, the camel-cxfrs producer will
generate the right REST request for you.
+Without the `CamelCxfOperationName` header, the producer fails with a
`NoSuchMethodException` that names it.
+
+The `CamelCxfOperationName` header replaced the `operationName` header. The
producer does not read the former name,
+and the default header filter strategy does not send it to the service as an
HTTP header.
Here is an example:
[source,java]
diff --git
a/components/camel-cxf/camel-cxf-rest/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsHeaderFilterStrategy.java
b/components/camel-cxf/camel-cxf-rest/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsHeaderFilterStrategy.java
index 422e1d3144bc..002fda05c45b 100644
---
a/components/camel-cxf/camel-cxf-rest/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsHeaderFilterStrategy.java
+++
b/components/camel-cxf/camel-cxf-rest/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsHeaderFilterStrategy.java
@@ -28,6 +28,8 @@ public class CxfRsHeaderFilterStrategy extends
DefaultHeaderFilterStrategy {
protected void initialize() {
getOutFilter().add(CxfConstants.OPERATION_NAME.toLowerCase());
+ // and the former name of this header, which the producer no longer
reads
+ getOutFilter().add("operationname");
getOutFilter().add("Content-Type".toLowerCase());
// Support to filter the Content-Type case insensitive
diff --git
a/components/camel-cxf/camel-cxf-rest/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
b/components/camel-cxf/camel-cxf-rest/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
index d03dfcee08f9..1f2680f315b7 100644
---
a/components/camel-cxf/camel-cxf-rest/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
+++
b/components/camel-cxf/camel-cxf-rest/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
@@ -67,6 +67,9 @@ public class CxfRsProducer extends DefaultAsyncProducer {
private static final Logger LOG =
LoggerFactory.getLogger(CxfRsProducer.class);
+ // the name of the operation header before CxfConstants.OPERATION_NAME
replaced it
+ private static final String FORMER_OPERATION_NAME = "operationName";
+
private boolean throwException;
// using a cache of factory beans instead of setting the address of a
single cfb
@@ -190,7 +193,7 @@ public class CxfRsProducer extends DefaultAsyncProducer {
protected void invokeAsyncProxyClient(Exchange exchange, final
AsyncCallback callback) throws Exception {
Message inMessage = exchange.getIn();
Object[] varValues =
inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_VAR_VALUES, Object[].class);
- String methodName = inMessage.getHeader(CxfConstants.OPERATION_NAME,
String.class);
+ String methodName = getMethodName(inMessage);
Client target;
JAXRSClientFactoryBean cfb =
clientFactoryBeanCache.get(CxfRsEndpointUtils
@@ -443,7 +446,7 @@ public class CxfRsProducer extends DefaultAsyncProducer {
protected void invokeProxyClient(Exchange exchange) throws Exception {
Message inMessage = exchange.getIn();
Object[] varValues =
inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_VAR_VALUES, Object[].class);
- String methodName = inMessage.getHeader(CxfConstants.OPERATION_NAME,
String.class);
+ String methodName = getMethodName(inMessage);
Client target = null;
JAXRSClientFactoryBean cfb =
clientFactoryBeanCache.get(CxfRsEndpointUtils
@@ -518,6 +521,25 @@ public class CxfRsProducer extends DefaultAsyncProducer {
}
}
+ /**
+ * The name of the method of the resource classes that the proxy-based
client API invokes, from the
+ * CamelCxfOperationName header. The operationName header, which
CamelCxfOperationName replaced, is not read.
+ */
+ private static String getMethodName(Message inMessage) throws
NoSuchMethodException {
+ String methodName = inMessage.getHeader(CxfConstants.OPERATION_NAME,
String.class);
+ if (methodName == null) {
+ String message = "The " + CxfConstants.OPERATION_NAME + " header
is not set: with the proxy-based client API"
+ + " (httpClientAPI=false) the producer invokes
the method of the resource classes that this"
+ + " header names.";
+ if (inMessage.getHeader(FORMER_OPERATION_NAME) != null) {
+ message += " The producer does not read the " +
FORMER_OPERATION_NAME + " header, which "
+ + CxfConstants.OPERATION_NAME + " replaced.";
+ }
+ throw new NoSuchMethodException(message);
+ }
+ return methodName;
+ }
+
private Method findRightMethod(
List<Class<?>> resourceClasses, String methodName,
Class<?>[] parameterTypes)
diff --git
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsHeaderFilterStrategyTest.java
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsHeaderFilterStrategyTest.java
index f6149cce88fd..82b860fc5a40 100644
---
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsHeaderFilterStrategyTest.java
+++
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsHeaderFilterStrategyTest.java
@@ -45,4 +45,13 @@ public class CxfRsHeaderFilterStrategyTest {
assertFalse(filter.applyFilterToCamelHeaders("MyWorld", "just a test",
null), "Get a wrong filtered result");
}
+ @Test
+ public void testFilterOperationNameHeaders() throws Exception {
+ HeaderFilterStrategy filter = new CxfRsHeaderFilterStrategy();
+
assertTrue(filter.applyFilterToCamelHeaders(CxfConstants.OPERATION_NAME,
"getCustomer", null),
+ "Get a wrong filtered result");
+ // the former name of the header
+ assertTrue(filter.applyFilterToCamelHeaders("operationName",
"getCustomer", null), "Get a wrong filtered result");
+ }
+
}
diff --git
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerOperationHeaderTest.java
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerOperationHeaderTest.java
new file mode 100644
index 000000000000..56de7a90d187
--- /dev/null
+++
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerOperationHeaderTest.java
@@ -0,0 +1,205 @@
+/*
+ * 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.jaxrs;
+
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.component.cxf.common.message.CxfConstants;
+import org.apache.camel.component.cxf.jaxrs.testbean.Customer;
+import org.apache.camel.component.cxf.jaxrs.testbean.CustomerService;
+import org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceImpl;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * How the producer finds the method to invoke with the proxy-based client API
from the CamelCxfOperationName header,
+ * what it reports when the header is not set, and which operation headers it
sends to the service.
+ */
+public class CxfRsProducerOperationHeaderTest extends CamelTestSupport {
+ private static AvailablePortFinder.Port port;
+
+ private final List<Map<String, List<String>>> serverHeaders = new
CopyOnWriteArrayList<>();
+ private Server rsServer;
+
+ @BeforeAll
+ static void allocatePort() {
+ port = AvailablePortFinder.find();
+ }
+
+ @AfterAll
+ static void releasePort() {
+ if (port != null) {
+ port.release();
+ }
+ }
+
+ @BeforeEach
+ public void startServer() {
+ JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
+ sf.setAddress(address());
+ // CustomerServiceImpl repeats @PathParam on its methods, which hides
the annotations of the interface from the
+ // server: serve the annotated interface backed by the implementation
+ sf.setResourceClasses(CustomerService.class);
+ sf.setResourceProvider(CustomerService.class, new
SingletonResourceProvider(new CustomerServiceImpl()));
+ sf.getInInterceptors().add(new
AbstractPhaseInterceptor<Message>(Phase.RECEIVE) {
+ @Override
+ public void handleMessage(Message message) throws Fault {
+ Map<String, List<String>> received = new
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>)
message.get(Message.PROTOCOL_HEADERS));
+ if (headers != null) {
+ received.putAll(headers);
+ }
+ serverHeaders.add(received);
+ }
+ });
+ rsServer = sf.create();
+ }
+
+ @AfterEach
+ public void stopServer() {
+ if (rsServer != null) {
+ rsServer.stop();
+ rsServer.destroy();
+ }
+ }
+
+ private static String address() {
+ return "http://localhost:" + port.getPort() +
"/CxfRsProducerOperationHeaderTest";
+ }
+
+ private static String proxyUri(String options) {
+ return "cxfrs://" + address() +
"?httpClientAPI=false&resourceClasses=" + CustomerService.class.getName() +
options;
+ }
+
+ private static String httpUri() {
+ return "cxfrs://" + address() + "?synchronous=true";
+ }
+
+ private Exchange send(String uri, Map<String, Object> headers, Object
body) {
+ return template.send(uri, e -> {
+ e.setPattern(ExchangePattern.InOut);
+ e.getIn().getHeaders().putAll(headers);
+ e.getIn().setBody(body);
+ });
+ }
+
+ private static void assertCustomer123(Exchange reply) {
+ assertNull(reply.getException());
+ Customer customer = assertInstanceOf(Customer.class,
reply.getMessage().getBody());
+ assertEquals(123, customer.getId());
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = { "&synchronous=true", "" })
+ public void missingOperationNameHeaderIsNamedInTheError(String options) {
+ Exchange reply = send(proxyUri(options), Map.of(), "123");
+
+ NoSuchMethodException e =
assertInstanceOf(NoSuchMethodException.class, reply.getException());
+ String message = e.getMessage();
+ assertTrue(message.contains("The " + CxfConstants.OPERATION_NAME + "
header is not set"), message);
+ assertTrue(message.contains("httpClientAPI=false"), message);
+ assertFalse(message.contains(" operationName "), message);
+ assertTrue(serverHeaders.isEmpty(), "server headers: " +
serverHeaders);
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = { "&synchronous=true", "" })
+ public void operationNameHeaderOfFormerNameIsNamedInTheError(String
options) {
+ Exchange reply = send(proxyUri(options), Map.of("operationName",
"getCustomer"), "123");
+
+ // the header is not read: it does not select the method
+ NoSuchMethodException e =
assertInstanceOf(NoSuchMethodException.class, reply.getException());
+ String message = e.getMessage();
+ assertTrue(message.contains("The " + CxfConstants.OPERATION_NAME + "
header is not set"), message);
+ assertTrue(message.contains("does not read the operationName header"),
message);
+ assertTrue(serverHeaders.isEmpty(), "server headers: " +
serverHeaders);
+ }
+
+ @Test
+ public void operationNameHeaderOfFormerNameIsNotSentAsHttpHeader() {
+ // proxy-based client API: a route that maps an application header
named operationName to CamelCxfOperationName
+ Exchange proxyReply = send(proxyUri("&synchronous=true"),
+ Map.of("operationName", "getCustomer",
CxfConstants.OPERATION_NAME, "getCustomer", "key", "value"), "123");
+ assertCustomer123(proxyReply);
+
+ // HTTP centric client API, which does not read the operation headers
+ Exchange httpReply = send(httpUri(), Map.of("operationName",
"getCustomer", Exchange.HTTP_METHOD, "GET",
+ Exchange.HTTP_PATH, "/customerservice/customers/123", "key",
"value"), null);
+ assertNull(httpReply.getException());
+ assertEquals(200,
httpReply.getMessage().getHeader(Exchange.HTTP_RESPONSE_CODE));
+
+ assertEquals(2, serverHeaders.size(), "server headers: " +
serverHeaders);
+ assertTrue(serverHeaders.stream().noneMatch(h ->
h.containsKey("operationName")), "server headers: " + serverHeaders);
+ // the other headers are still sent
+ assertTrue(serverHeaders.stream().allMatch(h ->
List.of("value").equals(h.get("key"))),
+ "server headers: " + serverHeaders);
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = { "&synchronous=true", "" })
+ public void operationNameHeaderSelectsTheMethod(String options) {
+ Exchange reply = send(proxyUri(options),
Map.of(CxfConstants.OPERATION_NAME, "getCustomer"), "123");
+
+ assertCustomer123(reply);
+ assertEquals(1, serverHeaders.size(), "server headers: " +
serverHeaders);
+
assertFalse(serverHeaders.get(0).containsKey(CxfConstants.OPERATION_NAME),
"server headers: " + serverHeaders);
+ }
+
+ @Test
+ public void operationNameHeaderWinsOverHeaderOfFormerName() {
+ Exchange reply = send(proxyUri("&synchronous=true"),
+ Map.of("operationName", "getCustomers",
CxfConstants.OPERATION_NAME, "getCustomer"), "123");
+
+ assertCustomer123(reply);
+ }
+
+ @Test
+ public void unknownMethodNameIsNamedInTheError() {
+ Exchange reply = send(proxyUri("&synchronous=true"),
Map.of(CxfConstants.OPERATION_NAME, "noSuchMethod"), "123");
+
+ NoSuchMethodException e =
assertInstanceOf(NoSuchMethodException.class, reply.getException());
+ assertEquals("Cannot find method with name: noSuchMethod having
parameters assignable from: [class java.lang.String]",
+ e.getMessage());
+ assertTrue(serverHeaders.isEmpty(), "server headers: " +
serverHeaders);
+ }
+}
diff --git
a/components/camel-cxf/camel-cxf-soap/src/main/docs/cxf-component.adoc
b/components/camel-cxf/camel-cxf-soap/src/main/docs/cxf-component.adoc
index b38260c666d1..7ab972d3050a 100644
--- a/components/camel-cxf/camel-cxf-soap/src/main/docs/cxf-component.adoc
+++ b/components/camel-cxf/camel-cxf-soap/src/main/docs/cxf-component.adoc
@@ -627,8 +627,13 @@ messageContentsList, you can get the result from that list.
If you don't specify the operation name in the message header,
`CxfProducer` will try to use the `defaultOperationName` from
`CxfEndpoint`, if there is no `defaultOperationName` set on
-`CxfEndpoint`, it will pick up the first operationName from the Operation
-list.
+`CxfEndpoint`, it invokes the first operation that CXF returns for the service,
+in an order that is not the order of the WSDL or of the service class.
+When the service has more than one operation, the producer logs a WARN once in
this case.
+
+The `CamelCxfOperationName` and `CamelCxfOperationNamespace` headers replaced
the `operationName` and
+`operationNamespace` headers. The producer does not read the former names: it
logs a WARN once when one of them
+is set without its replacement, and does not send them to the service as HTTP
headers.
If you want to get the object array from the message body, you can get
the body using `message.getBody(Object[].class)`, as shown in
https://github.com/apache/camel/blob/main/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfProducerRouterTest.java#L117[CxfProducerRouterTest.testInvokingSimpleServerWithParams]:
diff --git
a/components/camel-cxf/camel-cxf-soap/src/main/java/org/apache/camel/component/cxf/jaxws/CxfProducer.java
b/components/camel-cxf/camel-cxf-soap/src/main/java/org/apache/camel/component/cxf/jaxws/CxfProducer.java
index 63595d90da90..1ef65753965c 100644
---
a/components/camel-cxf/camel-cxf-soap/src/main/java/org/apache/camel/component/cxf/jaxws/CxfProducer.java
+++
b/components/camel-cxf/camel-cxf-soap/src/main/java/org/apache/camel/component/cxf/jaxws/CxfProducer.java
@@ -46,6 +46,7 @@ import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.jaxws.context.WrappedMessageContext;
import org.apache.cxf.message.ExchangeImpl;
import org.apache.cxf.message.Message;
+import org.apache.cxf.service.model.BindingInfo;
import org.apache.cxf.service.model.BindingMessageInfo;
import org.apache.cxf.service.model.BindingOperationInfo;
import org.slf4j.Logger;
@@ -59,8 +60,14 @@ public class CxfProducer extends DefaultAsyncProducer {
private static final Logger LOG =
LoggerFactory.getLogger(CxfProducer.class);
+ // the names of the operation headers before CxfConstants.OPERATION_NAME
and OPERATION_NAMESPACE replaced them
+ private static final String FORMER_OPERATION_NAME = "operationName";
+ private static final String FORMER_OPERATION_NAMESPACE =
"operationNamespace";
+
private Client client;
private CxfEndpoint endpoint;
+ private volatile boolean formerOperationHeadersWarned;
+ private volatile boolean operationNotSelectedWarned;
/**
* Constructor to create a CxfProducer. It will create a CXF client object.
@@ -412,12 +419,20 @@ public class CxfProducer extends DefaultAsyncProducer {
* <ul>
* <li>Using the in message header "CamelCxfOperationName".</li>
* <li>Using the defaultOperationName option value from the
CxfEndpoint.</li>
- * <li>Using the first operation which is find from the CxfEndpoint
Operations list.</li>
- * <ul>
+ * <li>Using the first operation that CXF returns for the service, in an
order that is not defined. A WARN is logged
+ * once when the service has more than one operation.</li>
+ * </ul>
+ * <p>
+ * The headers named operationName and operationNamespace, which
CamelCxfOperationName and
+ * CamelCxfOperationNamespace replaced, are not read. A WARN is logged
once when they are set without their
+ * replacement.
+ * </p>
*/
private BindingOperationInfo getBindingOperationInfo(Exchange ex) {
CxfEndpoint cxfEndpoint = (CxfEndpoint) this.getEndpoint();
+ BindingInfo binding =
client.getEndpoint().getEndpointInfo().getBinding();
BindingOperationInfo answer = null;
+ warnOnFormerOperationHeaders(ex);
String lp = ex.getIn().getHeader(CxfConstants.OPERATION_NAME,
String.class);
if (lp == null) {
LOG.debug("CxfProducer cannot find the {} from message header,
trying with defaultOperationName",
@@ -428,12 +443,20 @@ public class CxfProducer extends DefaultAsyncProducer {
LOG.debug(
"CxfProducer cannot find the {} from message header and
there is no DefaultOperationName setting, CxfProducer will pick up the first
available operation.",
CxfConstants.OPERATION_NAME);
- Collection<BindingOperationInfo> bois =
client.getEndpoint().getEndpointInfo().getBinding().getOperations();
+ Collection<BindingOperationInfo> bois = binding.getOperations();
Iterator<BindingOperationInfo> iter = bois.iterator();
if (iter.hasNext()) {
answer = iter.next();
}
+ if (bois.size() > 1 && !operationNotSelectedWarned) {
+ operationNotSelectedWarned = true;
+ LOG.warn("Neither the {} header nor the defaultOperationName
option selects the operation, and the service"
+ + " has {} operations: the producer of endpoint {}
invokes {}, the first one that CXF returns, in"
+ + " an order that is not the order of the WSDL or of
the service class. Set the {} header or the"
+ + " defaultOperationName option. This is logged
once.",
+ CxfConstants.OPERATION_NAME, bois.size(), endpoint,
answer.getName(), CxfConstants.OPERATION_NAME);
+ }
} else {
String ns = ex.getIn().getHeader(CxfConstants.OPERATION_NAMESPACE,
String.class);
@@ -449,16 +472,46 @@ public class CxfProducer extends DefaultAsyncProducer {
LOG.trace("Operation qname = {}", qname);
- answer =
client.getEndpoint().getEndpointInfo().getBinding().getOperation(qname);
+ answer = binding.getOperation(qname);
if (answer == null) {
throw new IllegalArgumentException(
"Can't find the BindingOperationInfo with operation
name " + qname
- + ". Please check the
message headers of operationName and operationNamespace.");
+ + ". Please check the " +
CxfConstants.OPERATION_NAME + " and "
+ +
CxfConstants.OPERATION_NAMESPACE
+ + " headers, or the
defaultOperationName and defaultOperationNamespace"
+ + " options. The operations
of the service are "
+ + operationNames(binding));
}
}
return answer;
}
+ private void warnOnFormerOperationHeaders(Exchange ex) {
+ if (formerOperationHeadersWarned) {
+ return;
+ }
+ String former = null;
+ if (ex.getIn().getHeader(CxfConstants.OPERATION_NAME) == null
+ && ex.getIn().getHeader(FORMER_OPERATION_NAME) != null) {
+ former = FORMER_OPERATION_NAME;
+ } else if (ex.getIn().getHeader(CxfConstants.OPERATION_NAMESPACE) ==
null
+ && ex.getIn().getHeader(FORMER_OPERATION_NAMESPACE) != null) {
+ former = FORMER_OPERATION_NAMESPACE;
+ }
+ if (former != null) {
+ formerOperationHeadersWarned = true;
+ LOG.warn("The producer of endpoint {} does not read the {} header:
the operation is selected by the {} and {}"
+ + " headers (CxfConstants.OPERATION_NAME and
CxfConstants.OPERATION_NAMESPACE), which replaced the {}"
+ + " and {} headers. This is logged once.",
+ endpoint, former, CxfConstants.OPERATION_NAME,
CxfConstants.OPERATION_NAMESPACE, FORMER_OPERATION_NAME,
+ FORMER_OPERATION_NAMESPACE);
+ }
+ }
+
+ private static List<String> operationNames(BindingInfo binding) {
+ return binding.getOperations().stream().map(boi ->
boi.getName().toString()).sorted().toList();
+ }
+
public Client getClient() {
return client;
}
diff --git
a/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfProducerOperationHeaderTest.java
b/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfProducerOperationHeaderTest.java
new file mode 100644
index 000000000000..6d3aff9157d3
--- /dev/null
+++
b/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfProducerOperationHeaderTest.java
@@ -0,0 +1,295 @@
+/*
+ * 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.jaxws;
+
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.component.cxf.common.message.CxfConstants;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.jaxws.EndpointImpl;
+import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.hello_world_soap_http.GreeterImpl;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.config.Property;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * How the producer selects the operation to invoke from the
CamelCxfOperationName and CamelCxfOperationNamespace
+ * headers, and what it reports when no header or an unknown operation selects
it.
+ */
+public class CxfProducerOperationHeaderTest extends CamelTestSupport {
+ private static final String NS = "http://apache.org/hello_world_soap_http";
+ private static final List<String> GREETER_OPERATIONS = List.of("sayHi",
"greetMe", "greetMeSometime", "greetMeLater");
+
+ private static AvailablePortFinder.Port greeterPort;
+ private static AvailablePortFinder.Port echoPort;
+
+ private final List<Map<String, List<String>>> serverHeaders = new
CopyOnWriteArrayList<>();
+ private final List<LogEvent> producerLogEvents = new
CopyOnWriteArrayList<>();
+ private EndpointImpl greeterServer;
+ private Server echoServer;
+ private AbstractAppender captor;
+ private Logger producerLogger;
+
+ @BeforeAll
+ static void allocatePorts() {
+ greeterPort = AvailablePortFinder.find();
+ echoPort = AvailablePortFinder.find();
+ }
+
+ @AfterAll
+ static void releasePorts() {
+ if (greeterPort != null) {
+ greeterPort.release();
+ }
+ if (echoPort != null) {
+ echoPort.release();
+ }
+ }
+
+ @BeforeEach
+ public void startServers() {
+ greeterServer = new EndpointImpl(BusFactory.getDefaultBus(), new
GreeterImpl());
+ greeterServer.getInInterceptors().add(new
AbstractPhaseInterceptor<Message>(Phase.RECEIVE) {
+ @Override
+ public void handleMessage(Message message) throws Fault {
+ Map<String, List<String>> received = new
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>)
message.get(Message.PROTOCOL_HEADERS));
+ if (headers != null) {
+ received.putAll(headers);
+ }
+ serverHeaders.add(received);
+ }
+ });
+ greeterServer.publish(greeterAddress());
+
+ JaxWsServerFactoryBean echo = new JaxWsServerFactoryBean();
+ echo.setBus(BusFactory.getDefaultBus());
+ echo.setAddress(echoAddress());
+ echo.setServiceClass(EchoService.class);
+ echo.setServiceBean(new EchoService() {
+ @Override
+ public String echo(String text) {
+ return "echo " + text;
+ }
+ });
+ echoServer = echo.create();
+
+ captor = new AbstractAppender("CxfProducerOperationHeaderTest", null,
null, false, Property.EMPTY_ARRAY) {
+ @Override
+ public void append(LogEvent event) {
+ producerLogEvents.add(event.toImmutable());
+ }
+ };
+ captor.start();
+ producerLogger = (Logger) LogManager.getLogger(CxfProducer.class);
+ producerLogger.addAppender(captor);
+ }
+
+ @AfterEach
+ public void stopServers() {
+ if (producerLogger != null) {
+ producerLogger.removeAppender(captor);
+ }
+ if (greeterServer != null) {
+ greeterServer.stop();
+ }
+ if (echoServer != null) {
+ echoServer.destroy();
+ }
+ }
+
+ private static String greeterAddress() {
+ return "http://localhost:" + greeterPort.getPort() +
"/CxfProducerOperationHeaderTest/Greeter";
+ }
+
+ private static String echoAddress() {
+ return "http://localhost:" + echoPort.getPort() +
"/CxfProducerOperationHeaderTest/Echo";
+ }
+
+ private static String greeterUri(String options) {
+ return "cxf://" + greeterAddress() +
"?serviceClass=org.apache.hello_world_soap_http.Greeter&synchronous=true"
+ + options;
+ }
+
+ private static Object paramsFor(String operation) {
+ return switch (operation) {
+ case "sayHi" -> null;
+ case "greetMeLater" -> List.of(0L);
+ default -> List.of("Willem");
+ };
+ }
+
+ private Exchange send(String uri, Map<String, Object> headers, Object
body) {
+ return template.send(uri, e -> {
+ e.setPattern(ExchangePattern.InOut);
+ e.getIn().getHeaders().putAll(headers);
+ e.getIn().setBody(body);
+ });
+ }
+
+ private static String invokedOperation(Exchange reply) {
+ BindingOperationInfo boi =
reply.getProperty(BindingOperationInfo.class.getName(),
BindingOperationInfo.class);
+ assertNotNull(boi, "the producer sets the BindingOperationInfo
property before it invokes the service");
+ return boi.getName().getLocalPart();
+ }
+
+ private List<String> producerWarnings() {
+ return producerLogEvents.stream()
+ .filter(e -> e.getLevel().isMoreSpecificThan(Level.WARN))
+ .map(e -> e.getMessage().getFormattedMessage())
+ .toList();
+ }
+
+ @Test
+ public void operationNameHeaderOfFormerNameIsReportedOnceAndNotSent() {
+ // the operation the producer invokes when no header selects one
+ String invoked = invokedOperation(send(greeterUri(""), Map.of(),
paramsFor("sayHi")));
+ producerLogEvents.clear();
+
+ for (int i = 0; i < 3; i++) {
+ Exchange reply = send(greeterUri(""), Map.of("operationName",
"greetMe", "operationNamespace", NS),
+ paramsFor(invoked));
+ // the header is not read: it does not select the operation
+ assertEquals(invoked, invokedOperation(reply));
+ }
+
+ List<String> warnings = producerWarnings();
+ assertEquals(1, warnings.size(), "warnings: " + warnings);
+ String warning = warnings.get(0);
+ assertTrue(warning.contains("operationName"), warning);
+ assertTrue(warning.contains(CxfConstants.OPERATION_NAME), warning);
+ assertTrue(warning.contains(CxfConstants.OPERATION_NAMESPACE),
warning);
+
+ // the headers are not sent to the service as HTTP headers
+ assertFalse(serverHeaders.isEmpty());
+ assertTrue(serverHeaders.stream().noneMatch(h ->
h.containsKey("operationName")), "server headers: " + serverHeaders);
+ assertTrue(serverHeaders.stream().noneMatch(h ->
h.containsKey("operationNamespace")),
+ "server headers: " + serverHeaders);
+ }
+
+ @Test
+ public void
operationNotSelectedOnServiceWithSeveralOperationsIsReportedOnce() {
+ String invoked = invokedOperation(send(greeterUri(""), Map.of(),
paramsFor("sayHi")));
+ invokedOperation(send(greeterUri(""), Map.of(), paramsFor(invoked)));
+
+ List<String> warnings = producerWarnings();
+ assertEquals(1, warnings.size(), "warnings: " + warnings);
+ String warning = warnings.get(0);
+ assertTrue(warning.contains(CxfConstants.OPERATION_NAME), warning);
+ assertTrue(warning.contains("defaultOperationName"), warning);
+ assertTrue(warning.contains("{" + NS + "}" + invoked), warning);
+ }
+
+ @Test
+ public void unknownOperationNamesTheHeadersAndTheOperationsOfTheService() {
+ Exchange reply = send(greeterUri(""),
+ Map.of(CxfConstants.OPERATION_NAME, "greetMe",
CxfConstants.OPERATION_NAMESPACE, "http://wrong/ns"),
+ List.of("Willem"));
+
+ IllegalArgumentException e =
assertInstanceOf(IllegalArgumentException.class, reply.getException());
+ String message = e.getMessage();
+ assertTrue(message.contains("{http://wrong/ns}greetMe"), message);
+ assertTrue(message.contains(CxfConstants.OPERATION_NAME), message);
+ assertTrue(message.contains(CxfConstants.OPERATION_NAMESPACE),
message);
+ assertTrue(message.contains("defaultOperationNamespace"), message);
+ for (String operation : GREETER_OPERATIONS) {
+ String listed = "{" + NS + "}" + operation;
+ assertTrue(message.contains(listed + ",") ||
message.contains(listed + "]"), message);
+ }
+ }
+
+ @Test
+ public void operationNameHeaderSelectsEachOperationWithoutWarning() {
+ for (String operation : GREETER_OPERATIONS) {
+ Exchange reply = send(greeterUri(""),
Map.of(CxfConstants.OPERATION_NAME, operation), paramsFor(operation));
+ assertNull(reply.getException(), operation);
+ assertEquals(operation, invokedOperation(reply));
+ }
+ Exchange reply = send(greeterUri(""),
+ Map.of(CxfConstants.OPERATION_NAME, "greetMe",
CxfConstants.OPERATION_NAMESPACE, NS), List.of("Willem"));
+ assertEquals("Hello Willem", reply.getMessage().getBody(String.class));
+
+ assertEquals(List.of(), producerWarnings());
+ // the operation headers are not sent to the service as HTTP headers
+ assertTrue(serverHeaders.stream().noneMatch(h ->
h.containsKey(CxfConstants.OPERATION_NAME)));
+ assertTrue(serverHeaders.stream().noneMatch(h ->
h.containsKey(CxfConstants.OPERATION_NAMESPACE)));
+ }
+
+ @Test
+ public void operationNameHeaderWinsOverHeaderOfFormerNameWithoutWarning() {
+ // a route that maps an application header named operationName to
CamelCxfOperationName
+ Exchange reply = send(greeterUri(""),
+ Map.of("operationName", "greetMe",
CxfConstants.OPERATION_NAME, "greetMe"), List.of("Willem"));
+
+ assertNull(reply.getException());
+ assertEquals("Hello Willem", reply.getMessage().getBody(String.class));
+ assertEquals(List.of(), producerWarnings());
+ }
+
+ @Test
+ public void defaultOperationNameSelectsTheOperationWithoutWarning() {
+ Exchange reply =
send(greeterUri("&defaultOperationName=greetMe&defaultOperationNamespace=" +
NS), Map.of(),
+ List.of("Willem"));
+
+ assertNull(reply.getException());
+ assertEquals("greetMe", invokedOperation(reply));
+ assertEquals("Hello Willem", reply.getMessage().getBody(String.class));
+ assertEquals(List.of(), producerWarnings());
+ }
+
+ @Test
+ public void serviceWithOneOperationIsInvokedWithoutWarning() {
+ String uri = "cxf://" + echoAddress() + "?serviceClass=" +
EchoService.class.getName() + "&synchronous=true";
+ for (int i = 0; i < 2; i++) {
+ Exchange reply = send(uri, Map.of(), List.of("Willem"));
+ assertNull(reply.getException());
+ assertEquals("echo", invokedOperation(reply));
+ assertEquals("echo Willem",
reply.getMessage().getBody(String.class));
+ }
+ assertEquals(List.of(), producerWarnings());
+ }
+}
diff --git
a/components/camel-cxf/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/header/CxfHeaderFilterStrategy.java
b/components/camel-cxf/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/header/CxfHeaderFilterStrategy.java
index 921c45f94b5f..c94c803c87f6 100644
---
a/components/camel-cxf/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/header/CxfHeaderFilterStrategy.java
+++
b/components/camel-cxf/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/header/CxfHeaderFilterStrategy.java
@@ -52,6 +52,9 @@ public class CxfHeaderFilterStrategy extends
DefaultHeaderFilterStrategy {
//filter the operationName and operationName
getOutFilter().add(CxfConstants.OPERATION_NAME.toLowerCase());
getOutFilter().add(CxfConstants.OPERATION_NAMESPACE.toLowerCase());
+ // and the former names of these headers, which the producer no longer
reads
+ getOutFilter().add("operationname");
+ getOutFilter().add("operationnamespace");
// Request and response context Maps will be passed to CXF Client APIs
getOutFilter().add(Client.REQUEST_CONTEXT.toLowerCase());