This is an automated email from the ASF dual-hosted git repository.
pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 4d6d32682cef chore(components): clear cxf-jaxrs compilation warnings
4d6d32682cef is described below
commit 4d6d32682cef06ad565bc594f818e40ecfed3f61
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Tue Jan 20 17:11:03 2026 +0100
chore(components): clear cxf-jaxrs compilation warnings
Ref CAMEL-22549
---
.../camel/component/cxf/jaxrs/CxfRsEndpoint.java | 3 +-
.../cxf/jaxrs/CxfRsConsumerWithBeanTest.java | 12 ++--
.../cxf/jaxrs/CxfRsConvertBodyToTest.java | 39 ++++++-----
.../component/cxf/jaxrs/CxfRsEndpointTest.java | 80 ++++++++++++----------
.../cxf/jaxrs/CxfRsProducerStreamCacheTest.java | 6 +-
.../cxf/jaxrs/CxfRsResponseWithHeadersTest.java | 12 ++--
.../component/cxf/jaxrs/CxfRsStreamCacheTest.java | 12 ++--
.../EchoService.java => response/MyResponse.java} | 27 ++------
.../CxfRsConsumerSimpleBindingImplTest.java | 16 +++--
.../CxfRsConsumerSimpleBindingTest.java | 54 ++++++++-------
.../component/cxf/jaxrs/testbean/EchoService.java | 10 ++-
11 files changed, 141 insertions(+), 130 deletions(-)
diff --git
a/components/camel-cxf/camel-cxf-rest/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java
b/components/camel-cxf/camel-cxf-rest/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java
index 8da6e9f6cda6..1b3dadd8a27e 100644
---
a/components/camel-cxf/camel-cxf-rest/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java
+++
b/components/camel-cxf/camel-cxf-rest/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java
@@ -32,7 +32,6 @@ import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.Service;
import org.apache.camel.component.cxf.common.NullFaultListener;
import org.apache.camel.component.cxf.common.message.CxfConstants;
import org.apache.camel.http.base.cookie.CookieHandler;
@@ -76,7 +75,7 @@ import static
org.apache.camel.component.cxf.common.message.CxfConstants.SCHEME_
@Metadata(annotations = {
"protocol=http",
})
-public class CxfRsEndpoint extends DefaultEndpoint implements
HeaderFilterStrategyAware, Service {
+public class CxfRsEndpoint extends DefaultEndpoint implements
HeaderFilterStrategyAware {
private static final Logger LOG =
LoggerFactory.getLogger(CxfRsEndpoint.class);
diff --git
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java
index 3c1d62d42898..e352ef36887f 100644
---
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java
+++
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java
@@ -18,13 +18,13 @@ package org.apache.camel.component.cxf.jaxrs;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.cxf.common.CXFTestSupport;
+import org.apache.camel.component.cxf.jaxrs.response.MyResponse;
import org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceResource;
import org.apache.camel.component.cxf.jaxrs.testbean.ServiceUtil;
import org.apache.camel.spi.Registry;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.apache.hc.client5.http.classic.methods.HttpPut;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.io.entity.EntityUtils;
@@ -76,10 +76,12 @@ public class CxfRsConsumerWithBeanTest extends
CamelTestSupport {
StringEntity entity = new StringEntity("string",
ContentType.TEXT_PLAIN);
put.setEntity(entity);
- try (CloseableHttpClient httpclient =
HttpClientBuilder.create().build();
- CloseableHttpResponse response = httpclient.execute(put)) {
- assertEquals(200, response.getCode());
- assertEquals("c20string",
EntityUtils.toString(response.getEntity()));
+ try (CloseableHttpClient httpclient =
HttpClientBuilder.create().build()) {
+ MyResponse httpResponse = httpclient.execute(put, response -> {
+ return new MyResponse(response.getCode(),
EntityUtils.toString(response.getEntity()));
+ });
+ assertEquals(200, httpResponse.status());
+ assertEquals("c20string", httpResponse.content());
}
}
}
diff --git
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConvertBodyToTest.java
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConvertBodyToTest.java
index a6402f350c1c..4903cec51b5f 100644
---
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConvertBodyToTest.java
+++
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConvertBodyToTest.java
@@ -20,20 +20,22 @@ import jakarta.ws.rs.core.Response;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.cxf.common.CXFTestSupport;
+import org.apache.camel.component.cxf.jaxrs.response.MyResponse;
import org.apache.camel.component.cxf.jaxrs.testbean.Customer;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.apache.hc.client5.http.classic.methods.HttpPut;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
public class CxfRsConvertBodyToTest extends CamelTestSupport {
private static final String PUT_REQUEST =
"<Customer><name>Mary</name><id>123</id></Customer>";
@@ -108,10 +110,12 @@ public class CxfRsConvertBodyToTest extends
CamelTestSupport {
put.addHeader("test", "header1;header2");
put.setEntity(entity);
- try (CloseableHttpClient httpclient =
HttpClientBuilder.create().build();
- CloseableHttpResponse response = httpclient.execute(put)) {
- assertEquals(200, response.getCode());
- assertEquals("", EntityUtils.toString(response.getEntity()));
+ try (CloseableHttpClient httpclient =
HttpClientBuilder.create().build()) {
+ MyResponse httpResponse = httpclient.execute(put, response -> {
+ return new MyResponse(response.getCode(),
EntityUtils.toString(response.getEntity()));
+ });
+ assertEquals(200, httpResponse.status());
+ assertEquals("", httpResponse.content());
}
mock.assertIsSatisfied();
@@ -128,13 +132,14 @@ public class CxfRsConvertBodyToTest extends
CamelTestSupport {
int expectedStatus = 202;
- try (CloseableHttpClient httpclient =
HttpClientBuilder.create().build();
- CloseableHttpResponse response = httpclient.execute(put)) {
-
- assertEquals(expectedStatus, response.getCode(),
+ try (CloseableHttpClient httpclient =
HttpClientBuilder.create().build()) {
+ MyResponse httpResponse = httpclient.execute(put, response -> {
+ return new MyResponse(response.getCode(),
EntityUtils.toString(response.getEntity()));
+ });
+ assertEquals(expectedStatus, httpResponse.status(),
"The HTTP status code should be 202");
- String responseBody = EntityUtils.toString(response.getEntity());
+ String responseBody = httpResponse.content();
assertNotNull(responseBody);
assertEquals("", responseBody);
}
@@ -151,16 +156,16 @@ public class CxfRsConvertBodyToTest extends
CamelTestSupport {
StringEntity entity = new StringEntity(PUT_REQUEST,
ContentType.parse("text/xml; charset=ISO-8859-1"));
put.setEntity(entity);
- try (CloseableHttpClient httpclient =
HttpClientBuilder.create().build();
- CloseableHttpResponse response = httpclient.execute(put)) {
-
+ try (CloseableHttpClient httpclient =
HttpClientBuilder.create().build()) {
+ MyResponse httpResponse = httpclient.execute(put, response -> {
+ HttpEntity et = response.getEntity();
+ return new MyResponse(response.getCode(), et == null ? null :
EntityUtils.toString(response.getEntity()));
+ });
// Verify status 204 is preserved even with no entity body
- assertEquals(204, response.getCode(), "Status 204 should be
preserved for empty response");
+ assertEquals(204, httpResponse.status(), "Status 204 should be
preserved for empty response");
// Entity should be null or empty
- if (response.getEntity() != null) {
- assertEquals("", EntityUtils.toString(response.getEntity()));
- }
+ assertNull(httpResponse.content());
}
mock.assertIsSatisfied();
diff --git
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointTest.java
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointTest.java
index e2307d0c6488..fbbbe2b70e2e 100644
---
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointTest.java
+++
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointTest.java
@@ -39,30 +39,32 @@ public class CxfRsEndpointTest extends CamelTestSupport {
+
"&resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService,"
+
"java.lang.String,org.apache.camel.component.cxf.jaxrs.testbean.Order";
- CxfRsComponent component = new CxfRsComponent(context);
- CxfRsEndpoint endpoint = (CxfRsEndpoint)
component.createEndpoint(endpointUri);
-
- assertNotNull(endpoint, "The endpoint should not be null");
- assertEquals(endpointUri, endpoint.getEndpointUri(), "Get a wrong
address");
- assertEquals(3, endpoint.getResourceClasses().size(), "Get a wrong
size of resouces classes");
- assertEquals(CustomerService.class,
endpoint.getResourceClasses().get(0), "Get a wrong resources class");
- assertEquals(true, endpoint.isLoggingFeatureEnabled(), "Get a wrong
loggingFeatureEnabled setting");
- assertEquals(200, endpoint.getLoggingSizeLimit(), "Get a wrong
loggingSizeLimit setting");
+ try (CxfRsComponent component = new CxfRsComponent(context)) {
+ CxfRsEndpoint endpoint = (CxfRsEndpoint)
component.createEndpoint(endpointUri);
+
+ assertNotNull(endpoint, "The endpoint should not be null");
+ assertEquals(endpointUri, endpoint.getEndpointUri(), "Get a wrong
address");
+ assertEquals(3, endpoint.getResourceClasses().size(), "Get a wrong
size of resouces classes");
+ assertEquals(CustomerService.class,
endpoint.getResourceClasses().get(0), "Get a wrong resources class");
+ assertEquals(true, endpoint.isLoggingFeatureEnabled(), "Get a
wrong loggingFeatureEnabled setting");
+ assertEquals(200, endpoint.getLoggingSizeLimit(), "Get a wrong
loggingSizeLimit setting");
+ }
}
@Test
public void testCxfRsEndpointParameters() throws Exception {
- CxfRsComponent component = new CxfRsComponent(context);
- String endpointUri = "cxfrs://http://localhost:" + CTX +
"/templatetest/TID/ranges/start=0;end=1?"
- +
"continuationTimeout=80000&httpClientAPI=true&loggingFeatureEnabled=true&loggingSizeLimit=200&q1=11&q2=12";
-
- CxfRsEndpoint endpoint = (CxfRsEndpoint)
component.createEndpoint(endpointUri);
-
- assertEquals(endpointUri, endpoint.getEndpointUri(), "Get a wrong
URI");
- assertEquals(true, endpoint.isHttpClientAPI(), "Get a wrong
usingClientAPI option");
- assertNotNull(endpoint.getParameters(), "The Parameter should not be
null");
- assertEquals("{q1=11, q2=12}", endpoint.getParameters().toString(),
"Get a wrong parameter map");
- assertEquals(80000, endpoint.getContinuationTimeout(), "Get a wrong
continucationTimeout");
+ try (CxfRsComponent component = new CxfRsComponent(context)) {
+ String endpointUri = "cxfrs://http://localhost:" + CTX +
"/templatetest/TID/ranges/start=0;end=1?"
+ +
"continuationTimeout=80000&httpClientAPI=true&loggingFeatureEnabled=true&loggingSizeLimit=200&q1=11&q2=12";
+
+ CxfRsEndpoint endpoint = (CxfRsEndpoint)
component.createEndpoint(endpointUri);
+
+ assertEquals(endpointUri, endpoint.getEndpointUri(), "Get a wrong
URI");
+ assertEquals(true, endpoint.isHttpClientAPI(), "Get a wrong
usingClientAPI option");
+ assertNotNull(endpoint.getParameters(), "The Parameter should not
be null");
+ assertEquals("{q1=11, q2=12}",
endpoint.getParameters().toString(), "Get a wrong parameter map");
+ assertEquals(80000, endpoint.getContinuationTimeout(), "Get a
wrong continucationTimeout");
+ }
}
@Test
@@ -70,15 +72,16 @@ public class CxfRsEndpointTest extends CamelTestSupport {
String endpointUri = "cxfrs://http://localhost:" + CTX + ""
+
"?resourceClass=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService";
- CxfRsComponent component = new CxfRsComponent(context);
- CxfRsEndpoint endpoint = (CxfRsEndpoint)
component.createEndpoint(endpointUri);
+ try (CxfRsComponent component = new CxfRsComponent(context)) {
+ CxfRsEndpoint endpoint = (CxfRsEndpoint)
component.createEndpoint(endpointUri);
- assertNotNull(endpoint, "The endpoint should not be null");
- assertEquals(endpointUri, endpoint.getEndpointUri(), "Get a wrong
address");
- assertEquals(1, endpoint.getResourceClasses().size(), "Get a wrong
size of resouces classes");
- assertEquals(CustomerService.class,
endpoint.getResourceClasses().get(0), "Get a wrong resources class");
- // check the default continuation value
- assertEquals(30000, endpoint.getContinuationTimeout(), "Get a wrong
continucationTimeout");
+ assertNotNull(endpoint, "The endpoint should not be null");
+ assertEquals(endpointUri, endpoint.getEndpointUri(), "Get a wrong
address");
+ assertEquals(1, endpoint.getResourceClasses().size(), "Get a wrong
size of resouces classes");
+ assertEquals(CustomerService.class,
endpoint.getResourceClasses().get(0), "Get a wrong resources class");
+ // check the default continuation value
+ assertEquals(30000, endpoint.getContinuationTimeout(), "Get a
wrong continucationTimeout");
+ }
}
@Test
@@ -87,16 +90,17 @@ public class CxfRsEndpointTest extends CamelTestSupport {
String endpointUri = "cxfrs://http://localhost:" + CTX + ""
+
"?resourceClass=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService";
- CxfRsComponent component = new CxfRsComponent(context);
- CxfRsEndpoint endpoint = (CxfRsEndpoint)
component.createEndpoint(endpointUri);
- JSONProvider<?> jsonProvider = new JSONProvider<>();
- jsonProvider.setDropRootElement(true);
- jsonProvider.setSupportUnwrapped(true);
- endpoint.setProvider(jsonProvider);
- JAXRSServerFactoryBean sfb = endpoint.createJAXRSServerFactoryBean();
- assertEquals(1, sfb.getProviders().size(), "Get a wrong proider size");
- JAXRSClientFactoryBean cfb = endpoint.createJAXRSClientFactoryBean();
- assertEquals(1, cfb.getProviders().size(), "Get a wrong proider size");
+ try (CxfRsComponent component = new CxfRsComponent(context)) {
+ CxfRsEndpoint endpoint = (CxfRsEndpoint)
component.createEndpoint(endpointUri);
+ JSONProvider<?> jsonProvider = new JSONProvider<>();
+ jsonProvider.setDropRootElement(true);
+ jsonProvider.setSupportUnwrapped(true);
+ endpoint.setProvider(jsonProvider);
+ JAXRSServerFactoryBean sfb =
endpoint.createJAXRSServerFactoryBean();
+ assertEquals(1, sfb.getProviders().size(), "Get a wrong proider
size");
+ JAXRSClientFactoryBean cfb =
endpoint.createJAXRSClientFactoryBean();
+ assertEquals(1, cfb.getProviders().size(), "Get a wrong proider
size");
+ }
}
@Test
diff --git
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerStreamCacheTest.java
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerStreamCacheTest.java
index 576acd849d34..befc4c66fefd 100644
---
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerStreamCacheTest.java
+++
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerStreamCacheTest.java
@@ -46,15 +46,16 @@ public class CxfRsProducerStreamCacheTest extends
CamelTestSupport {
private Server rsServer;
@Override
+ @Deprecated
protected boolean useJmx() {
return false;
}
@Override
+ @Deprecated
protected void doPreSetup() throws Exception {
port = AvailablePortFinder.getNextAvailable();
startRsEchoServer();
-
}
@AfterEach
@@ -107,8 +108,7 @@ public class CxfRsProducerStreamCacheTest extends
CamelTestSupport {
.to(cxfrsUri)
// 2) read response after cxfrs call multiple times
.process(e -> {
- String body = e.getIn().getBody(String.class);
-
+ e.getIn().getBody(String.class);
})
.log("The body is ===> ${body}");
diff --git
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsResponseWithHeadersTest.java
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsResponseWithHeadersTest.java
index 818646360da2..8dda73c3d267 100644
---
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsResponseWithHeadersTest.java
+++
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsResponseWithHeadersTest.java
@@ -19,10 +19,10 @@ package org.apache.camel.component.cxf.jaxrs;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.cxf.common.CXFTestSupport;
+import org.apache.camel.component.cxf.jaxrs.response.MyResponse;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.apache.hc.client5.http.classic.methods.HttpPut;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.io.entity.EntityUtils;
@@ -58,10 +58,12 @@ public class CxfRsResponseWithHeadersTest extends
CamelTestSupport {
StringEntity entity = new StringEntity(PUT_REQUEST,
ContentType.parse("text/xml; charset=ISO-8859-1"));
put.setEntity(entity);
- try (CloseableHttpClient httpclient =
HttpClientBuilder.create().build();
- CloseableHttpResponse response = httpclient.execute(put)) {
- assertEquals(404, response.getCode());
- assertEquals("Cannot find customer",
EntityUtils.toString(response.getEntity()));
+ try (CloseableHttpClient httpclient =
HttpClientBuilder.create().build()) {
+ MyResponse httpResponse = httpclient.execute(put, response -> {
+ return new MyResponse(response.getCode(),
EntityUtils.toString(response.getEntity()));
+ });
+ assertEquals(404, httpResponse.status());
+ assertEquals("Cannot find customer", httpResponse.content());
}
}
diff --git
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsStreamCacheTest.java
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsStreamCacheTest.java
index 2ecd882bc459..848a6bf2b739 100644
---
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsStreamCacheTest.java
+++
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsStreamCacheTest.java
@@ -21,6 +21,7 @@ import java.nio.charset.StandardCharsets;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.cxf.common.CXFTestSupport;
+import org.apache.camel.component.cxf.jaxrs.response.MyResponse;
import org.apache.camel.component.cxf.jaxrs.testbean.Customer;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.converter.stream.CachedOutputStream;
@@ -28,7 +29,6 @@ import org.apache.camel.spi.Synchronization;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.apache.hc.client5.http.classic.methods.HttpPut;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.io.entity.EntityUtils;
@@ -99,10 +99,12 @@ public class CxfRsStreamCacheTest extends CamelTestSupport {
put.setEntity(entity);
CloseableHttpClient httpclient = HttpClientBuilder.create().build();
- try (CloseableHttpResponse response = httpclient.execute(put)) {
- assertEquals(200, response.getCode());
- assertEquals(RESPONSE, EntityUtils.toString(response.getEntity()));
- }
+ MyResponse httpResponse = httpclient.execute(put, response -> {
+ return new MyResponse(response.getCode(),
EntityUtils.toString(response.getEntity()));
+ });
+
+ assertEquals(200, httpResponse.status());
+ assertEquals(RESPONSE, httpResponse.content());
mock.assertIsSatisfied();
onComplete.assertIsSatisfied();
diff --git
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/EchoService.java
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/response/MyResponse.java
similarity index 50%
copy from
components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/EchoService.java
copy to
components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/response/MyResponse.java
index 5aac219f4690..496da5fdf389 100644
---
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/EchoService.java
+++
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/response/MyResponse.java
@@ -14,28 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.cxf.jaxrs.testbean;
+package org.apache.camel.component.cxf.jaxrs.response;
-import jakarta.ws.rs.POST;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.core.Context;
-import jakarta.ws.rs.core.Cookie;
-import jakarta.ws.rs.core.HttpHeaders;
-import jakarta.ws.rs.core.NewCookie;
-import jakarta.ws.rs.core.Response;
-
-@Path("/echoservice/")
-public class EchoService {
- @Context
- private HttpHeaders headers;
-
- @POST
- @Path("/echo/")
- public Response echo(String string) {
- Cookie fooCookie = headers.getCookies().get("foo");
- if (fooCookie != null && "bar".equals(fooCookie.getValue())) {
- return Response.ok("Old " + string).build();
- }
- return Response.ok("New " + string).cookie(new NewCookie("foo", "bar",
"/", null, 1, null, -1, false)).build();
- }
+// A record using exclusively for testing purposes: used to hold status,
content and eventually any other
+// response required for testing.
+public record MyResponse(int status, String content) {
}
diff --git
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingImplTest.java
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingImplTest.java
index becba92d8a57..82dfc58da6ab 100644
---
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingImplTest.java
+++
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingImplTest.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.cxf.jaxrs.simplebinding;
+import java.io.StringReader;
import java.io.StringWriter;
import jakarta.xml.bind.JAXBContext;
@@ -24,6 +25,7 @@ import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.cxf.common.CXFTestSupport;
+import org.apache.camel.component.cxf.jaxrs.response.MyResponse;
import org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Customer;
import
org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.CustomerList;
import org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Order;
@@ -32,8 +34,8 @@ import org.apache.camel.test.junit5.CamelTestSupport;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.junit.jupiter.api.Test;
@@ -97,9 +99,11 @@ public class CxfRsConsumerSimpleBindingImplTest extends
CamelTestSupport {
public void testGetCustomerOnlyHeaders() throws Exception {
HttpGet get = new HttpGet("http://localhost:" + PORT_PATH +
"/rest/customerservice/customers/123");
get.addHeader("Accept", "text/xml");
- CloseableHttpResponse response = httpclient.execute(get);
- assertEquals(200, response.getCode());
- Customer entity = (Customer)
jaxb.createUnmarshaller().unmarshal(response.getEntity().getContent());
+ MyResponse httpResponse = httpclient.execute(get, response -> {
+ return new MyResponse(response.getCode(),
EntityUtils.toString(response.getEntity()));
+ });
+ assertEquals(200, httpResponse.status());
+ Customer entity = (Customer) jaxb.createUnmarshaller().unmarshal(new
StringReader(httpResponse.content()));
assertEquals(123, entity.getId());
}
@@ -111,7 +115,7 @@ public class CxfRsConsumerSimpleBindingImplTest extends
CamelTestSupport {
post.setEntity(new StringEntity(sw.toString()));
post.addHeader("Content-Type", "text/xml");
post.addHeader("Accept", "text/xml");
- CloseableHttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getCode());
+ Integer status = httpclient.execute(post, response ->
response.getCode());
+ assertEquals(200, status);
}
}
diff --git
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingTest.java
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingTest.java
index dd3473c9a2b6..22c1b87c7a2b 100644
---
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingTest.java
+++
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingTest.java
@@ -31,6 +31,7 @@ import org.apache.camel.Processor;
import org.apache.camel.attachment.AttachmentMessage;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.cxf.common.CXFTestSupport;
+import org.apache.camel.component.cxf.jaxrs.response.MyResponse;
import org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Customer;
import
org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.CustomerList;
import org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Order;
@@ -44,7 +45,6 @@ import org.apache.hc.client5.http.classic.methods.HttpPut;
import org.apache.hc.client5.http.entity.mime.HttpMultipartMode;
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.io.entity.EntityUtils;
@@ -206,9 +206,11 @@ public class CxfRsConsumerSimpleBindingTest extends
CamelTestSupport {
public void testGetCustomerOnlyHeaders() throws Exception {
HttpGet get = new HttpGet("http://localhost:" + PORT_PATH +
"/rest/customerservice/customers/123");
get.addHeader("Accept", "text/xml");
- CloseableHttpResponse response = httpclient.execute(get);
- assertEquals(200, response.getCode());
- Customer entity = (Customer)
jaxb.createUnmarshaller().unmarshal(response.getEntity().getContent());
+ MyResponse httpResponse = httpclient.execute(get, response -> {
+ return new MyResponse(response.getCode(),
EntityUtils.toString(response.getEntity()));
+ });
+ assertEquals(200, httpResponse.status());
+ Customer entity = (Customer) jaxb.createUnmarshaller().unmarshal(new
StringReader(httpResponse.content()));
assertEquals(123, entity.getId());
}
@@ -216,8 +218,8 @@ public class CxfRsConsumerSimpleBindingTest extends
CamelTestSupport {
public void testGetCustomerHttp404CustomStatus() throws Exception {
HttpGet get = new HttpGet("http://localhost:" + PORT_PATH +
"/rest/customerservice/customers/456");
get.addHeader("Accept", "text/xml");
- CloseableHttpResponse response = httpclient.execute(get);
- assertEquals(404, response.getCode());
+ Integer status = httpclient.execute(get, response ->
response.getCode());
+ assertEquals(404, status);
}
@Test
@@ -228,8 +230,8 @@ public class CxfRsConsumerSimpleBindingTest extends
CamelTestSupport {
put.setEntity(new StringEntity(sw.toString()));
put.addHeader("Content-Type", "text/xml");
put.addHeader("Accept", "text/xml");
- CloseableHttpResponse response = httpclient.execute(put);
- assertEquals(200, response.getCode());
+ Integer status = httpclient.execute(put, response ->
response.getCode());
+ assertEquals(200, status);
}
@Test
@@ -240,8 +242,8 @@ public class CxfRsConsumerSimpleBindingTest extends
CamelTestSupport {
post.setEntity(new StringEntity(sw.toString()));
post.addHeader("Content-Type", "text/xml");
post.addHeader("Accept", "text/xml");
- CloseableHttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getCode());
+ Integer status = httpclient.execute(post, response ->
response.getCode());
+ assertEquals(200, status);
}
@Test
@@ -249,10 +251,12 @@ public class CxfRsConsumerSimpleBindingTest extends
CamelTestSupport {
HttpGet get = new HttpGet("http://localhost:" + PORT_PATH +
"/rest/customerservice/customers/vip/gold");
get.addHeader("Content-Type", "text/xml");
get.addHeader("Accept", "text/xml");
- CloseableHttpResponse response = httpclient.execute(get);
- assertEquals(200, response.getCode());
+ MyResponse httpResponse = httpclient.execute(get, response -> {
+ return new MyResponse(response.getCode(),
EntityUtils.toString(response.getEntity()));
+ });
+ assertEquals(200, httpResponse.status());
CustomerList cl = (CustomerList) jaxb.createUnmarshaller()
- .unmarshal(new
StringReader(EntityUtils.toString(response.getEntity())));
+ .unmarshal(new StringReader(httpResponse.content()));
List<Customer> vips = cl.getCustomers();
assertEquals(2, vips.size());
assertEquals(123, vips.get(0).getId());
@@ -267,16 +271,16 @@ public class CxfRsConsumerSimpleBindingTest extends
CamelTestSupport {
put.setEntity(new StringEntity(sw.toString()));
put.addHeader("Content-Type", "text/xml");
put.addHeader("Accept", "text/xml");
- CloseableHttpResponse response = httpclient.execute(put);
- assertEquals(200, response.getCode());
+ Integer status = httpclient.execute(put, response ->
response.getCode());
+ assertEquals(200, status);
}
@Test
public void testDeleteVipCustomer() throws Exception {
HttpDelete delete = new HttpDelete("http://localhost:" + PORT_PATH +
"/rest/customerservice/customers/vip/gold/123");
delete.addHeader("Accept", "text/xml");
- CloseableHttpResponse response = httpclient.execute(delete);
- assertEquals(200, response.getCode());
+ Integer status = httpclient.execute(delete, response ->
response.getCode());
+ assertEquals(200, status);
}
@Test
@@ -285,8 +289,8 @@ public class CxfRsConsumerSimpleBindingTest extends
CamelTestSupport {
post.addHeader("Content-Type", "image/jpeg");
post.addHeader("Accept", "text/xml");
post.setEntity(new
InputStreamEntity(this.getClass().getClassLoader().getResourceAsStream("java.jpg"),
100, null));
- CloseableHttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getCode());
+ Integer status = httpclient.execute(post, response ->
response.getCode());
+ assertEquals(200, status);
}
@Test
@@ -295,8 +299,8 @@ public class CxfRsConsumerSimpleBindingTest extends
CamelTestSupport {
post.addHeader("Content-Type", "image/jpeg");
post.addHeader("Accept", "text/xml");
post.setEntity(new
InputStreamEntity(this.getClass().getClassLoader().getResourceAsStream("java.jpg"),
100, null));
- CloseableHttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getCode());
+ Integer status = httpclient.execute(post, response ->
response.getCode());
+ assertEquals(200, status);
}
@Test
@@ -312,8 +316,8 @@ public class CxfRsConsumerSimpleBindingTest extends
CamelTestSupport {
jaxb.createMarshaller().marshal(new Customer(123, "Raul"), sw);
builder.addTextBody("body", sw.toString(), ContentType.TEXT_XML);
post.setEntity(builder.build());
- CloseableHttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getCode());
+ Integer status = httpclient.execute(post, response ->
response.getCode());
+ assertEquals(200, status);
}
@Test
@@ -329,8 +333,8 @@ public class CxfRsConsumerSimpleBindingTest extends
CamelTestSupport {
jaxb.createMarshaller().marshal(new Customer(123, "Raul"), sw);
builder.addTextBody("body", sw.toString(), ContentType.TEXT_XML);
post.setEntity(builder.build());
- CloseableHttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getCode());
+ Integer status = httpclient.execute(post, response ->
response.getCode());
+ assertEquals(200, status);
}
}
diff --git
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/EchoService.java
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/EchoService.java
index 5aac219f4690..1e6fd3aeff2c 100644
---
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/EchoService.java
+++
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/EchoService.java
@@ -36,6 +36,14 @@ public class EchoService {
if (fooCookie != null && "bar".equals(fooCookie.getValue())) {
return Response.ok("Old " + string).build();
}
- return Response.ok("New " + string).cookie(new NewCookie("foo", "bar",
"/", null, 1, null, -1, false)).build();
+ return Response.ok("New " + string).cookie(
+ new NewCookie.Builder("foo")
+ .value("bar")
+ .path("/")
+ .version(1)
+ .maxAge(-1)
+ .secure(false)
+ .build())
+ .build();
}
}