[CAMEL-18509]use servlet transport for camel-cxf spring boot test
diff --git a/components-starter/camel-cxf-rest-starter/pom.xml b/components-starter/camel-cxf-rest-starter/pom.xml
index 2eb1ae3..8ae5c80 100644
--- a/components-starter/camel-cxf-rest-starter/pom.xml
+++ b/components-starter/camel-cxf-rest-starter/pom.xml
@@ -63,6 +63,28 @@
<version>${cglib-version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-tomcat</artifactId>
+ </exclusion>
+ </exclusions>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-undertow</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-spring-boot-starter-jaxrs</artifactId>
+ <scope>test</scope>
+ <version>${cxf-version}</version>
+ </dependency>
<!--START OF GENERATED CODE-->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
diff --git a/components-starter/camel-cxf-rest-starter/src/test/java/org/apache/camel/component/cxf/rest/springboot/CxfRsConsumerWithBeanTest.java b/components-starter/camel-cxf-rest-starter/src/test/java/org/apache/camel/component/cxf/rest/springboot/CxfRsConsumerWithBeanTest.java
index 58b63dc..5fd7a59 100644
--- a/components-starter/camel-cxf-rest-starter/src/test/java/org/apache/camel/component/cxf/rest/springboot/CxfRsConsumerWithBeanTest.java
+++ b/components-starter/camel-cxf-rest-starter/src/test/java/org/apache/camel/component/cxf/rest/springboot/CxfRsConsumerWithBeanTest.java
@@ -18,7 +18,6 @@
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.cxf.common.CXFTestSupport;
import org.apache.camel.component.cxf.jaxrs.testbean.ServiceUtil;
import org.apache.camel.spring.boot.CamelAutoConfiguration;
@@ -28,10 +27,14 @@
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
+import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
@@ -40,23 +43,24 @@
import org.apache.http.util.EntityUtils;
-@DirtiesContext
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@CamelSpringBootTest
@SpringBootTest(
classes = {
CamelAutoConfiguration.class,
CxfRsConsumerWithBeanTest.class,
- CxfRsConsumerWithBeanTest.TestConfiguration.class
- }
+ CxfRsConsumerWithBeanTest.TestConfiguration.class,
+ CxfAutoConfiguration.class
+ }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
public class CxfRsConsumerWithBeanTest {
- private static final String CXT = CXFTestSupport.getPort1() + "/CxfRsConsumerWithBeanTest";
+ private static final String CXT = "/CxfRsConsumerWithBeanTest";
private static final String CXF_RS_ENDPOINT_URI
- = "cxfrs://http://localhost:" + CXT
+ = "cxfrs://" + CXT
+ "/rest?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceResource";
private static final String CXF_RS_ENDPOINT_URI_2
- = "cxfrs://http://localhost:" + CXT
+ = "cxfrs://" + CXT
+ "/rest2?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceResource";
@Bean("service")
@@ -64,10 +68,15 @@
return new ServiceUtil();
}
+ @Bean
+ public ServletWebServerFactory servletWebServerFactory() {
+ return new UndertowServletWebServerFactory();
+ }
+
@Test
public void testPutConsumer() throws Exception {
- sendPutRequest("http://localhost:" + CXT + "/rest/customerservice/c20");
- sendPutRequest("http://localhost:" + CXT + "/rest2/customerservice/c20");
+ sendPutRequest("http://localhost:8080/services" + CXT + "/rest/customerservice/c20");
+ sendPutRequest("http://localhost:8080/services" + CXT + "/rest2/customerservice/c20");
}
private void sendPutRequest(String uri) throws Exception {
diff --git a/components-starter/camel-cxf-rest-starter/src/test/java/org/apache/camel/component/cxf/rest/springboot/CxfRsProducerSessionTest.java b/components-starter/camel-cxf-rest-starter/src/test/java/org/apache/camel/component/cxf/rest/springboot/CxfRsProducerSessionTest.java
index d44fcb7..e01db82 100644
--- a/components-starter/camel-cxf-rest-starter/src/test/java/org/apache/camel/component/cxf/rest/springboot/CxfRsProducerSessionTest.java
+++ b/components-starter/camel-cxf-rest-starter/src/test/java/org/apache/camel/component/cxf/rest/springboot/CxfRsProducerSessionTest.java
@@ -31,16 +31,22 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
+import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration;
-@DirtiesContext
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@CamelSpringBootTest
@SpringBootTest(classes = {
CamelAutoConfiguration.class,
- CxfRsProducerSessionTest.class
- },
+ CxfRsProducerSessionTest.class,
+ CxfAutoConfiguration.class
+}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {
"camel.springboot.routes-include-pattern=file:src/test/resources/routes/CxfRsSpringProducerSessionRoute.xml"}
)
@@ -50,17 +56,11 @@
})
public class CxfRsProducerSessionTest {
- private static int port1 = 12261;
- private static int port2 = 12262;
-
- public int getPort1() {
- return port1;
+ @Bean
+ public ServletWebServerFactory servletWebServerFactory() {
+ return new UndertowServletWebServerFactory();
}
-
- public int getPort2() {
- return port2;
- }
-
+
@Test
public void testNoSessionProxy() {
String response = sendMessage("direct://proxy", "World", Boolean.FALSE).getMessage().getBody(String.class);
diff --git a/components-starter/camel-cxf-rest-starter/src/test/java/org/apache/camel/component/cxf/rest/springboot/CxfRsStreamCacheTest.java b/components-starter/camel-cxf-rest-starter/src/test/java/org/apache/camel/component/cxf/rest/springboot/CxfRsStreamCacheTest.java
index e6e6cbe..b0d30fa 100644
--- a/components-starter/camel-cxf-rest-starter/src/test/java/org/apache/camel/component/cxf/rest/springboot/CxfRsStreamCacheTest.java
+++ b/components-starter/camel-cxf-rest-starter/src/test/java/org/apache/camel/component/cxf/rest/springboot/CxfRsStreamCacheTest.java
@@ -23,7 +23,6 @@
import org.apache.camel.ExtendedExchange;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.cxf.common.CXFTestSupport;
import org.apache.camel.component.cxf.jaxrs.testbean.Customer;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.converter.stream.CachedOutputStream;
@@ -37,10 +36,15 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
+import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
@@ -49,23 +53,24 @@
import org.apache.http.util.EntityUtils;
-@DirtiesContext
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@CamelSpringBootTest
@SpringBootTest(
classes = {
CamelAutoConfiguration.class,
CxfRsStreamCacheTest.class,
- CxfRsStreamCacheTest.TestConfiguration.class
- }
+ CxfRsStreamCacheTest.TestConfiguration.class,
+ CxfAutoConfiguration.class
+ }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
public class CxfRsStreamCacheTest {
private static final String PUT_REQUEST = "<Customer><name>Mary</name><id>123</id></Customer>";
private static final String CONTEXT = "/CxfRsStreamCacheTest";
- private static final String CXT = CXFTestSupport.getPort1() + CONTEXT;
+ private static final String CXT = "8080/services" + CONTEXT;
private static final String RESPONSE = "<pong xmlns=\"test/service\"/>";
- private String cxfRsEndpointUri = "cxfrs://http://localhost:" + CXT + "/rest?synchronous=" + isSynchronous()
+ private String cxfRsEndpointUri = "cxfrs://" + CONTEXT + "?synchronous=" + isSynchronous()
+ "&dataFormat=PAYLOAD&resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService";
@Autowired
@@ -77,6 +82,12 @@
@EndpointInject("mock:onComplete")
MockEndpoint onComplete;
+ @Bean
+ public ServletWebServerFactory servletWebServerFactory() {
+ return new UndertowServletWebServerFactory();
+ }
+
+
@Test
public void testPutConsumer() throws Exception {
@@ -86,7 +97,7 @@
onComplete.expectedMessageCount(1);
- HttpPut put = new HttpPut("http://localhost:" + CXT + "/rest/customerservice/customers");
+ HttpPut put = new HttpPut("http://localhost:" + CXT + "/customerservice/customers");
StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
entity.setContentType("text/xml; charset=ISO-8859-1");
put.addHeader("test", "header1;header2");
diff --git a/components-starter/camel-cxf-rest-starter/src/test/resources/routes/CxfRsSpringProducerSession.xml b/components-starter/camel-cxf-rest-starter/src/test/resources/routes/CxfRsSpringProducerSession.xml
index 92c38fe..db00a27 100644
--- a/components-starter/camel-cxf-rest-starter/src/test/resources/routes/CxfRsSpringProducerSession.xml
+++ b/components-starter/camel-cxf-rest-starter/src/test/resources/routes/CxfRsSpringProducerSession.xml
@@ -32,7 +32,7 @@
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
<jaxrs:server id="restService"
- address="http://127.0.0.1:12261/CxfRsProducerSessionTest/"
+ address="/CxfRsProducerSessionTest/"
staticSubresourceResolution="true">
<jaxrs:serviceBeans>
<ref bean="echoService"/>
@@ -41,11 +41,11 @@
<bean id="echoService" class="org.apache.camel.component.cxf.jaxrs.testbean.EchoService" />
- <cxf:rsClient id="rsClientProxy" address="http://127.0.0.1:12261/CxfRsProducerSessionTest/"
+ <cxf:rsClient id="rsClientProxy" address="http://localhost:8080/services/CxfRsProducerSessionTest/"
serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.EchoService"
loggingFeatureEnabled="true" />
- <cxf:rsClient id="rsClientHttp" address="http://127.0.0.1:12261/CxfRsProducerSessionTest/"/>
+ <cxf:rsClient id="rsClientHttp" address="http://localhost:8080/services/CxfRsProducerSessionTest/"/>
<bean id="instanceCookieHandler" class="org.apache.camel.http.base.cookie.InstanceCookieHandler"/>
diff --git a/components-starter/camel-cxf-soap-starter/pom.xml b/components-starter/camel-cxf-soap-starter/pom.xml
index 34ffa42..a4947b4 100644
--- a/components-starter/camel-cxf-soap-starter/pom.xml
+++ b/components-starter/camel-cxf-soap-starter/pom.xml
@@ -63,6 +63,28 @@
<version>${camel-version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-tomcat</artifactId>
+ </exclusion>
+ </exclusions>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-undertow</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
+ <scope>test</scope>
+ <version>${cxf-version}</version>
+ </dependency>
<!--START OF GENERATED CODE-->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
diff --git a/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CXFMultiPartTest.java b/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CXFMultiPartTest.java
index 1b1cd9f..de5e711 100644
--- a/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CXFMultiPartTest.java
+++ b/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CXFMultiPartTest.java
@@ -31,16 +31,21 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
+import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
import org.springframework.test.annotation.DirtiesContext;
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration;
@DirtiesContext
@CamelSpringBootTest
@SpringBootTest(classes = {
CamelAutoConfiguration.class,
- CXFMultiPartTest.class
- },
+ CXFMultiPartTest.class,
+ CxfAutoConfiguration.class
+ }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {
"camel.springboot.routes-include-pattern=file:src/test/resources/routes/multipartRoute.xml"}
)
@@ -57,6 +62,10 @@
"MultiPartInvokePort");
protected static Endpoint endpoint;
+ @Bean
+ public ServletWebServerFactory servletWebServerFactory() {
+ return new UndertowServletWebServerFactory();
+ }
public void startService() {
Object implementor = new MultiPartInvokeImpl();
@@ -76,8 +85,7 @@
@Test
public void testInvokingServiceFromCXFClient() throws Exception {
startService();
- String reply = invokeMultiPartService("http://localhost:16233"
- + "/CXFMultiPartTest/CamelContext/RouterPort", "in0", "in1");
+ String reply = invokeMultiPartService("http://localhost:8080/services/CXFMultiPartTest/CamelContext/RouterPort", "in0", "in1");
assertNotNull(reply, "No response received from service");
assertEquals("in0 in1", reply);
diff --git a/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CxfConsumerMessageTest.java b/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CxfConsumerMessageTest.java
index 45a423b..71c130b 100644
--- a/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CxfConsumerMessageTest.java
+++ b/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CxfConsumerMessageTest.java
@@ -23,7 +23,6 @@
import org.apache.camel.Processor;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.cxf.common.CXFTestSupport;
import org.apache.camel.component.cxf.jaxws.HelloService;
import org.apache.camel.spring.boot.CamelAutoConfiguration;
@@ -36,6 +35,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
+import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
@@ -43,6 +44,7 @@
import org.apache.cxf.BusFactory;
import org.apache.cxf.frontend.ClientFactoryBean;
import org.apache.cxf.frontend.ClientProxyFactoryBean;
+import org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration;
@DirtiesContext
@@ -51,8 +53,10 @@
classes = {
CamelAutoConfiguration.class,
CxfConsumerMessageTest.class,
- CxfConsumerMessageTest.TestConfiguration.class
- }
+ CxfConsumerMessageTest.TestConfiguration.class,
+ CxfAutoConfiguration.class
+ }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
+
)
public class CxfConsumerMessageTest {
@@ -70,8 +74,7 @@
+ "<return xmlns=\"http://jaxws.cxf.component.camel.apache.org/\">true</return>"
+ "</ns1:echoBooleanResponse></soap:Body></soap:Envelope>";
- protected final String simpleEndpointAddress = "http://localhost:"
- + CXFTestSupport.getPort1() + "/" + getClass().getSimpleName() + "/test";
+ protected final String simpleEndpointAddress = "/" + getClass().getSimpleName() + "-test";
protected final String simpleEndpointURI = "cxf://" + simpleEndpointAddress
+ "?serviceClass=org.apache.camel.component.cxf.jaxws.HelloService";
@@ -79,11 +82,16 @@
@Autowired
ProducerTemplate template;
+ @Bean
+ public ServletWebServerFactory servletWebServerFactory() {
+ return new UndertowServletWebServerFactory();
+ }
+
@Test
public void testInvokingServiceFromClient() throws Exception {
ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
- clientBean.setAddress(simpleEndpointAddress);
+ clientBean.setAddress("http://localhost:8080/services" + simpleEndpointAddress);
clientBean.setServiceClass(HelloService.class);
clientBean.setBus(BusFactory.getDefaultBus());
diff --git a/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CxfConsumerPayLoadConverterTest.java b/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CxfConsumerPayLoadConverterTest.java
index 45eec68..4a4f6ce 100644
--- a/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CxfConsumerPayLoadConverterTest.java
+++ b/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CxfConsumerPayLoadConverterTest.java
@@ -32,11 +32,14 @@
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
+import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
import org.apache.cxf.binding.soap.SoapHeader;
+import org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration;
@DirtiesContext
@@ -45,12 +48,17 @@
classes = {
CamelAutoConfiguration.class,
CxfConsumerPayLoadConverterTest.class,
- CxfConsumerPayLoadConverterTest.TestConfiguration.class
- }
+ CxfConsumerPayLoadConverterTest.TestConfiguration.class,
+ CxfAutoConfiguration.class
+ }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
public class CxfConsumerPayLoadConverterTest extends CxfConsumerPayloadTest {
+ @Bean
+ public ServletWebServerFactory servletWebServerFactory() {
+ return new UndertowServletWebServerFactory();
+ }
// *************************************
// Config
diff --git a/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CxfConsumerPayloadTest.java b/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CxfConsumerPayloadTest.java
index 5cd4405..b5a8d89 100644
--- a/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CxfConsumerPayloadTest.java
+++ b/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CxfConsumerPayloadTest.java
@@ -16,7 +16,6 @@
*/
package org.apache.camel.component.cxf.soap.springboot;
-
import java.util.ArrayList;
import java.util.List;
@@ -33,57 +32,56 @@
import org.apache.camel.converter.jaxp.XmlConverter;
import org.apache.camel.spring.boot.CamelAutoConfiguration;
-
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
+import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
import org.apache.cxf.binding.soap.SoapHeader;
-
+import org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration;
@DirtiesContext
@CamelSpringBootTest
-@SpringBootTest(
- classes = {
- CamelAutoConfiguration.class,
- CxfConsumerPayloadTest.class,
- CxfConsumerPayloadTest.TestConfiguration.class
- }
-)
-public class CxfConsumerPayloadTest extends CxfConsumerMessageTest{
+@SpringBootTest(classes = {
+ CamelAutoConfiguration.class, CxfConsumerPayloadTest.class,
+ CxfConsumerPayloadTest.TestConfiguration.class,
+ CxfAutoConfiguration.class
+}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+public class CxfConsumerPayloadTest extends CxfConsumerMessageTest {
protected static final String ECHO_RESPONSE = "<ns1:echoResponse xmlns:ns1=\"http://jaxws.cxf.component.camel.apache.org/\">"
- + "<return xmlns=\"http://jaxws.cxf.component.camel.apache.org/\">echo Hello World!</return>"
- + "</ns1:echoResponse>";
-protected static final String ECHO_BOOLEAN_RESPONSE
-= "<ns1:echoBooleanResponse xmlns:ns1=\"http://jaxws.cxf.component.camel.apache.org/\">"
-+ "<return xmlns=\"http://jaxws.cxf.component.camel.apache.org/\">true</return>"
-+ "</ns1:echoBooleanResponse>";
-protected static final String ECHO_REQUEST = "<ns1:echo xmlns:ns1=\"http://jaxws.cxf.component.camel.apache.org/\">"
- + "<arg0 xmlns=\"http://jaxws.cxf.component.camel.apache.org/\">Hello World!</arg0></ns1:echo>";
-protected static final String ECHO_BOOLEAN_REQUEST
-= "<ns1:echoBoolean xmlns:ns1=\"http://jaxws.cxf.component.camel.apache.org/\">"
-+ "<arg0 xmlns=\"http://jaxws.cxf.component.camel.apache.org/\">true</arg0></ns1:echoBoolean>";
+ + "<return xmlns=\"http://jaxws.cxf.component.camel.apache.org/\">echo Hello World!</return>"
+ + "</ns1:echoResponse>";
+ protected static final String ECHO_BOOLEAN_RESPONSE = "<ns1:echoBooleanResponse xmlns:ns1=\"http://jaxws.cxf.component.camel.apache.org/\">"
+ + "<return xmlns=\"http://jaxws.cxf.component.camel.apache.org/\">true</return>"
+ + "</ns1:echoBooleanResponse>";
+ protected static final String ECHO_REQUEST = "<ns1:echo xmlns:ns1=\"http://jaxws.cxf.component.camel.apache.org/\">"
+ + "<arg0 xmlns=\"http://jaxws.cxf.component.camel.apache.org/\">Hello World!</arg0></ns1:echo>";
+ protected static final String ECHO_BOOLEAN_REQUEST = "<ns1:echoBoolean xmlns:ns1=\"http://jaxws.cxf.component.camel.apache.org/\">"
+ + "<arg0 xmlns=\"http://jaxws.cxf.component.camel.apache.org/\">true</arg0></ns1:echoBoolean>";
-protected static final String ELEMENT_NAMESPACE = "http://jaxws.cxf.component.camel.apache.org/";
+ protected static final String ELEMENT_NAMESPACE = "http://jaxws.cxf.component.camel.apache.org/";
+
+ @Bean
+ public ServletWebServerFactory servletWebServerFactory() {
+ return new UndertowServletWebServerFactory();
+ }
-protected void checkRequest(String expect, String request) {
-//REVIST use a more reliable comparison to tolerate some namespaces being added to the root element
-if (expect.equals("ECHO_REQUEST")) {
-assertTrue(request.startsWith(ECHO_REQUEST.substring(0, 66))
-&& request.endsWith(ECHO_REQUEST.substring(67)), "Get a wrong request");
-} else {
-assertTrue(request.startsWith(ECHO_BOOLEAN_REQUEST.substring(0, 73))
-&& request.endsWith(ECHO_BOOLEAN_REQUEST.substring(74)), "Get a wrong request");
-}
-}
+ protected void checkRequest(String expect, String request) {
-
-
-
+ if (expect.equals("ECHO_REQUEST")) {
+ assertTrue(request.startsWith(ECHO_REQUEST.substring(0, 66))
+ && request.endsWith(ECHO_REQUEST.substring(67)), "Get a wrong request");
+ } else {
+ assertTrue(request.startsWith(ECHO_BOOLEAN_REQUEST.substring(0, 73))
+ && request.endsWith(ECHO_BOOLEAN_REQUEST.substring(74)), "Get a wrong request");
+ }
+ }
+
// *************************************
// Config
// *************************************
@@ -99,10 +97,12 @@
from(simpleEndpointURI + "&dataFormat=PAYLOAD").to("log:info").process(new Processor() {
@SuppressWarnings("unchecked")
public void process(final Exchange exchange) throws Exception {
- CxfPayload<SoapHeader> requestPayload = exchange.getIn().getBody(CxfPayload.class);
+ CxfPayload<SoapHeader> requestPayload = exchange.getIn()
+ .getBody(CxfPayload.class);
List<Source> inElements = requestPayload.getBodySources();
List<Source> outElements = new ArrayList<>();
- // You can use a customer toStringConverter to turn a CxfPayLoad message into String as you want
+ // You can use a customer toStringConverter to turn a CxfPayLoad message into
+ // String as you want
String request = exchange.getIn().getBody(String.class);
XmlConverter converter = new XmlConverter();
String documentString = ECHO_RESPONSE;
@@ -122,7 +122,8 @@
Document outDocument = converter.toDOMDocument(documentString, exchange);
outElements.add(new DOMSource(outDocument.getDocumentElement()));
// set the payload header with null
- CxfPayload<SoapHeader> responsePayload = new CxfPayload<>(null, outElements, null);
+ CxfPayload<SoapHeader> responsePayload = new CxfPayload<>(null, outElements,
+ null);
exchange.getMessage().setBody(responsePayload);
}
});
@@ -130,6 +131,5 @@
};
}
}
-
-
+
}
diff --git a/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CxfConsumerProviderTest.java b/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CxfConsumerProviderTest.java
index 0a98eff..c601b66 100644
--- a/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CxfConsumerProviderTest.java
+++ b/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/CxfConsumerProviderTest.java
@@ -24,7 +24,6 @@
import org.apache.camel.Processor;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.cxf.common.CXFTestSupport;
import org.apache.camel.converter.jaxp.XmlConverter;
import org.apache.camel.spring.boot.CamelAutoConfiguration;
@@ -36,10 +35,13 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
+import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration;
@DirtiesContext
@@ -48,8 +50,9 @@
classes = {
CamelAutoConfiguration.class,
CxfConsumerProviderTest.class,
- CxfConsumerProviderTest.TestConfiguration.class
- }
+ CxfConsumerProviderTest.TestConfiguration.class,
+ CxfAutoConfiguration.class
+ }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
public class CxfConsumerProviderTest {
@@ -64,15 +67,22 @@
protected static final String RESPONSE = "<pong xmlns=\"test/service\"/>";
- protected final String simpleEndpointAddress = "http://localhost:"
- + CXFTestSupport.getPort1() + "/" + getClass().getSimpleName() + "/test";
- protected final String simpleEndpointURI = "cxf://" + simpleEndpointAddress
+ protected final String relativeAddress = "/" + getClass().getSimpleName() + "/test";
+
+ protected final String simpleEndpointAddress = "http://localhost:8080/services"
+ + relativeAddress;
+ protected final String simpleEndpointURI = "cxf://" + relativeAddress
+ "?serviceClass=org.apache.camel.component.cxf.soap.springboot.ServiceProvider";
@Autowired
ProducerTemplate template;
+ @Bean
+ public ServletWebServerFactory servletWebServerFactory() {
+ return new UndertowServletWebServerFactory();
+ }
+
@Test
public void testInvokingServiceFromHttpCompnent() throws Exception {
// call the service with right post message
diff --git a/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/WSSUsernameTokenTest.java b/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/WSSUsernameTokenTest.java
index ab3c41e..cd7fc12 100644
--- a/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/WSSUsernameTokenTest.java
+++ b/components-starter/camel-cxf-soap-starter/src/test/java/org/apache/camel/component/cxf/soap/springboot/WSSUsernameTokenTest.java
@@ -20,13 +20,15 @@
import org.apache.camel.component.cxf.security.jaas.SimpleLoginModule;
import org.apache.camel.spring.boot.CamelAutoConfiguration;
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
+import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
import org.springframework.test.annotation.DirtiesContext;
@@ -46,22 +48,22 @@
@SpringBootTest(classes = {
CamelAutoConfiguration.class,
WSSUsernameTokenTest.class,
- SimpleLoginModule.class
-}
+ SimpleLoginModule.class,
+ CxfAutoConfiguration.class
+}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
@ImportResource({
"classpath:routes/soap-security.xml"
})
public class WSSUsernameTokenTest {
- private static final Logger LOG = LoggerFactory.getLogger(WSSUsernameTokenTest.class);
-
+
private static final String BAD_PASSWORD = "123";
private static final URL WSDL_URL;
static {
try {
- WSDL_URL = new URL("http://localhost:16232/cxf/ws/greeting-service?wsdl");
+ WSDL_URL = new URL("http://localhost:8080/services/greeting-service?wsdl");
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
@@ -69,6 +71,11 @@
private static final QName SERVICE_NAME = new QName("http://security.cxf.component.camel.apache.org/",
"GreetingServiceImplService");
+
+ @Bean
+ public ServletWebServerFactory servletWebServerFactory() {
+ return new UndertowServletWebServerFactory();
+ }
private void addWSSUsernameTokenHandler(Service service, final String username, final String password) {
// set a handler resolver providing WSSUsernameTokenHandler in the handler chain
diff --git a/components-starter/camel-cxf-soap-starter/src/test/resources/routes/MultiPartTest.xml b/components-starter/camel-cxf-soap-starter/src/test/resources/routes/MultiPartTest.xml
index 0a712a1..55ab8cf9 100644
--- a/components-starter/camel-cxf-soap-starter/src/test/resources/routes/MultiPartTest.xml
+++ b/components-starter/camel-cxf-soap-starter/src/test/resources/routes/MultiPartTest.xml
@@ -30,7 +30,7 @@
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<cxf:cxfEndpoint id="routerEndpoint"
- address="http://localhost:16233/CXFMultiPartTest/CamelContext/RouterPort"
+ address="/CXFMultiPartTest/CamelContext/RouterPort"
wsdlURL="classpath:/MultiPartTest.wsdl"
endpointName="s:MultiPartInvokePort"
serviceName="s:MultiPartInvokeService"
diff --git a/components-starter/camel-cxf-soap-starter/src/test/resources/routes/soap-security.xml b/components-starter/camel-cxf-soap-starter/src/test/resources/routes/soap-security.xml
index a125fe6..57b1c40 100644
--- a/components-starter/camel-cxf-soap-starter/src/test/resources/routes/soap-security.xml
+++ b/components-starter/camel-cxf-soap-starter/src/test/resources/routes/soap-security.xml
@@ -26,7 +26,7 @@
http://camel.apache.org/schema/cxf/jaxws http://camel.apache.org/schema/cxf/jaxws/camel-cxf.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
- <jaxws:endpoint id="greetingService" address="http://localhost:16232/cxf/ws/greeting-service" implementor="org.apache.camel.component.cxf.security.GreetingServiceImpl">
+ <jaxws:endpoint id="greetingService" address="/greeting-service" implementor="org.apache.camel.component.cxf.security.GreetingServiceImpl">
<jaxws:inInterceptors>
<bean class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">