This is an automated email from the ASF dual-hosted git repository.
reta pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/main by this push:
new afa9b3aea8 CXF-8666: JSR 250 annotations aren't disabled for
jakarta.xml.ws.WebServiceContext for Spring Framework 6 (#1227)
afa9b3aea8 is described below
commit afa9b3aea81c9dbfe27809ed4bdcccc9bd405067
Author: Andriy Redko <[email protected]>
AuthorDate: Tue Apr 11 15:57:51 2023 -0400
CXF-8666: JSR 250 annotations aren't disabled for
jakarta.xml.ws.WebServiceContext for Spring Framework 6 (#1227)
---
.../jaxws/CxfJaxwsAutoConfiguration.java | 47 +++++++++
...rk.boot.autoconfigure.AutoConfiguration.imports | 1 +
.../spring/boot/SpringClientOnlyJaxrsTest.java | 3 -
.../spring/boot/SpringJaxrsApplicationTest.java | 3 -
.../boot/SpringJaxrsClassesScanningTest.java | 3 -
.../boot/SpringJaxrsComponentScanningTest.java | 3 -
.../systest/jaxrs/spring/boot/SpringJaxrsTest.java | 3 -
.../jaxrs/spring/boot/SpringSseEmitterTest.java | 3 -
.../resources/HelloServiceWithContextImpl.java | 39 ++++++++
.../spring/boot/SpringJaxwsInjectionTest.java | 111 +++++++++++++++++++++
.../systest/jaxws/spring/boot/SpringJaxwsTest.java | 3 -
11 files changed, 198 insertions(+), 21 deletions(-)
diff --git
a/integration/spring-boot/autoconfigure/src/main/java/org/apache/cxf/spring/boot/autoconfigure/jaxws/CxfJaxwsAutoConfiguration.java
b/integration/spring-boot/autoconfigure/src/main/java/org/apache/cxf/spring/boot/autoconfigure/jaxws/CxfJaxwsAutoConfiguration.java
new file mode 100644
index 0000000000..5f785b0400
--- /dev/null
+++
b/integration/spring-boot/autoconfigure/src/main/java/org/apache/cxf/spring/boot/autoconfigure/jaxws/CxfJaxwsAutoConfiguration.java
@@ -0,0 +1,47 @@
+/**
+ * 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.cxf.spring.boot.autoconfigure.jaxws;
+
+import jakarta.annotation.Resource;
+import jakarta.xml.ws.WebServiceContext;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
+import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.context.annotation.Bean;
+import
org.springframework.context.annotation.CommonAnnotationBeanPostProcessor;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@ConditionalOnClass({ Resource.class, WebServiceContext.class })
+public class CxfJaxwsAutoConfiguration {
+ @Bean
+ static BeanFactoryPostProcessor jaxwsBeanFactoryPostProcessor() {
+ return new BeanFactoryPostProcessor() {
+ @Override
+ public void postProcessBeanFactory(ConfigurableListableBeanFactory
beanFactory) throws BeansException {
+ final var beans =
beanFactory.getBeansOfType(CommonAnnotationBeanPostProcessor.class);
+ // The {@code javax.xml.ws.WebServiceContext} interface should
be ignored since it will
+ // be resolved by the CXF's JAX-WS runtime.
+ beans.forEach((name, bean) ->
bean.ignoreResourceType(WebServiceContext.class.getName()));
+ }
+ };
+ }
+}
diff --git
a/integration/spring-boot/autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
b/integration/spring-boot/autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
index 6f20cc12ef..1d5db5ed73 100644
---
a/integration/spring-boot/autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
+++
b/integration/spring-boot/autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -1,3 +1,4 @@
org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration
org.apache.cxf.spring.boot.autoconfigure.openapi.OpenApiAutoConfiguration
org.apache.cxf.spring.boot.autoconfigure.micrometer.MicrometerMetricsAutoConfiguration
+org.apache.cxf.spring.boot.autoconfigure.jaxws.CxfJaxwsAutoConfiguration
diff --git
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringClientOnlyJaxrsTest.java
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringClientOnlyJaxrsTest.java
index 4a60ef750a..d901468e52 100644
---
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringClientOnlyJaxrsTest.java
+++
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringClientOnlyJaxrsTest.java
@@ -40,7 +40,6 @@ import
org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.web.servlet.function.RequestPredicates;
import org.springframework.web.servlet.function.RouterFunction;
import org.springframework.web.servlet.function.RouterFunctions;
@@ -52,14 +51,12 @@ import io.micrometer.core.instrument.search.RequiredSearch;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
import static java.util.stream.Collectors.toMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.entry;
-@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes =
SpringClientOnlyJaxrsTest.TestConfig.class)
@ActiveProfiles("client")
public class SpringClientOnlyJaxrsTest {
diff --git
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsApplicationTest.java
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsApplicationTest.java
index 105ae3eada..880d435457 100644
---
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsApplicationTest.java
+++
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsApplicationTest.java
@@ -48,7 +48,6 @@ import
org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
@@ -57,7 +56,6 @@ import io.micrometer.core.instrument.search.RequiredSearch;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
import static java.util.stream.Collectors.toMap;
import static org.assertj.core.api.Assertions.assertThat;
@@ -67,7 +65,6 @@ import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.Matchers.empty;
-@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes =
SpringJaxrsApplicationTest.TestConfig.class)
@ActiveProfiles("jaxrs")
public class SpringJaxrsApplicationTest {
diff --git
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsClassesScanningTest.java
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsClassesScanningTest.java
index 6063fe528a..4f75a84048 100644
---
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsClassesScanningTest.java
+++
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsClassesScanningTest.java
@@ -25,14 +25,11 @@ import
org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
import static org.assertj.core.api.Assertions.assertThat;
-@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
classes = SpringJaxrsClassesScanningTest.TestConfig.class)
@ActiveProfiles("jaxrs-classes-scan")
diff --git
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsComponentScanningTest.java
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsComponentScanningTest.java
index afc7927684..de2523e9e0 100644
---
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsComponentScanningTest.java
+++
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsComponentScanningTest.java
@@ -29,14 +29,11 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
import static org.assertj.core.api.Assertions.assertThat;
-@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
classes = SpringJaxrsComponentScanningTest.TestConfig.class)
@ActiveProfiles("jaxrs-component-scan")
diff --git
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsTest.java
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsTest.java
index 85d4e61bae..84bb59bb7d 100644
---
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsTest.java
+++
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsTest.java
@@ -51,7 +51,6 @@ import
org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
@@ -60,7 +59,6 @@ import io.micrometer.core.instrument.search.RequiredSearch;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
import static java.util.stream.Collectors.toMap;
import static org.assertj.core.api.Assertions.assertThat;
@@ -70,7 +68,6 @@ import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.Matchers.empty;
-@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes =
SpringJaxrsTest.TestConfig.class)
@ActiveProfiles("jaxrs")
public class SpringJaxrsTest {
diff --git
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringSseEmitterTest.java
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringSseEmitterTest.java
index 04cfa9cec8..721b3b285c 100644
---
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringSseEmitterTest.java
+++
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringSseEmitterTest.java
@@ -35,20 +35,17 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.http.MediaType;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import
org.springframework.web.servlet.mvc.method.annotation.SseEmitter.SseEventBuilder;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
-@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes =
SpringSseEmitterTest.LibraryController.class)
public class SpringSseEmitterTest {
private static final int CNT = 5;
diff --git
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxws/resources/HelloServiceWithContextImpl.java
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxws/resources/HelloServiceWithContextImpl.java
new file mode 100644
index 0000000000..4b7220be2e
--- /dev/null
+++
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxws/resources/HelloServiceWithContextImpl.java
@@ -0,0 +1,39 @@
+/**
+ * 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.cxf.systest.jaxws.resources;
+
+import jakarta.annotation.Resource;
+import jakarta.jws.WebService;
+import jakarta.xml.ws.WebServiceContext;
+
+import static java.util.Objects.requireNonNull;
+
+@WebService(serviceName = "HelloService", portName = "HelloPort",
+ targetNamespace = "http://service.ws.sample/",
+ endpointInterface =
"org.apache.cxf.systest.jaxws.resources.HelloService")
+public class HelloServiceWithContextImpl implements HelloService {
+ @Resource
+ private WebServiceContext context;
+
+ public String sayHello(String name) {
+ requireNonNull(name);
+ return "Hello, " + name;
+ }
+
+}
diff --git
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxws/spring/boot/SpringJaxwsInjectionTest.java
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxws/spring/boot/SpringJaxwsInjectionTest.java
new file mode 100644
index 0000000000..a2ab168c33
--- /dev/null
+++
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxws/spring/boot/SpringJaxwsInjectionTest.java
@@ -0,0 +1,111 @@
+/**
+ * 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.cxf.systest.jaxws.spring.boot;
+
+import java.io.StringReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import jakarta.xml.ws.Dispatch;
+import jakarta.xml.ws.Endpoint;
+import jakarta.xml.ws.Service;
+import jakarta.xml.ws.Service.Mode;
+import jakarta.xml.ws.WebServiceFeature;
+import org.apache.cxf.Bus;
+import org.apache.cxf.jaxws.EndpointImpl;
+import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.systest.jaxws.resources.HelloService;
+import org.apache.cxf.systest.jaxws.resources.HelloServiceWithContextImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.boot.test.web.server.LocalServerPort;
+import org.springframework.context.annotation.Bean;
+import org.springframework.test.context.ActiveProfiles;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@SpringBootTest(
+ webEnvironment = WebEnvironment.RANDOM_PORT,
+ classes = SpringJaxwsInjectionTest.TestConfig.class)
+@ActiveProfiles("jaxws")
+public class SpringJaxwsInjectionTest {
+
+ private static final String DUMMY_REQUEST_BODY = "<q0:sayHello
xmlns:q0=\"http://service.ws.sample/\">"
+ + "<name>Elan</name>"
+ + "</q0:sayHello>";
+ private static final String HELLO_SERVICE_NAME = "Hello";
+
+ @LocalServerPort
+ private int port;
+
+ @EnableAutoConfiguration
+ static class TestConfig {
+ @Autowired
+ private Bus bus;
+
+ @Bean
+ public HelloService helloService() {
+ return new HelloServiceWithContextImpl();
+ }
+
+ @Bean
+ public Endpoint helloEndpoint(HelloService helloService) {
+ EndpointImpl endpoint = new EndpointImpl(bus, helloService, null,
null, new WebServiceFeature[0]);
+ endpoint.publish("/" + HELLO_SERVICE_NAME);
+ return endpoint;
+ }
+ }
+
+ @Test
+ public void testJaxwsWebServiceContext() throws MalformedURLException {
+ // given in setUp
+
+ // when
+ String actual = sendSoapRequest(DUMMY_REQUEST_BODY,
HELLO_SERVICE_NAME);
+
+ // then
+ assertThat(actual)
+ .isEqualTo("<ns2:sayHelloResponse
xmlns:ns2=\"http://service.ws.sample/\">"
+ + "<return>Hello, Elan</return>"
+ + "</ns2:sayHelloResponse>");
+ }
+
+ private String sendSoapRequest(String requestBody, final String
serviceName) throws MalformedURLException {
+ String address = "http://localhost:" + port + "/Service/" +
serviceName;
+
+ StreamSource source = new StreamSource(new StringReader(requestBody));
+ Service service = Service.create(new URL(address + "?wsdl"),
+ new QName("http://service.ws.sample/", "HelloService"));
+
+ Dispatch<Source> dispatch = service.createDispatch(new
QName("http://service.ws.sample/", "HelloPort"),
+ Source.class, Mode.PAYLOAD);
+
+ Source result = dispatch.invoke(source);
+ return StaxUtils.toString(result);
+ }
+}
diff --git
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxws/spring/boot/SpringJaxwsTest.java
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxws/spring/boot/SpringJaxwsTest.java
index 6b29adffc8..0bddbb12e4 100644
---
a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxws/spring/boot/SpringJaxwsTest.java
+++
b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxws/spring/boot/SpringJaxwsTest.java
@@ -54,7 +54,6 @@ import
org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
@@ -65,7 +64,6 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
-
import static java.util.stream.Collectors.toMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -75,7 +73,6 @@ import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.Matchers.empty;
-@ExtendWith(SpringExtension.class)
@SpringBootTest(
webEnvironment = WebEnvironment.RANDOM_PORT,
classes = SpringJaxwsTest.TestConfig.class,