From 74a6fe649c032b1679dbead5e2cd43df65cbf707 Mon Sep 17 00:00:00 2001 From: Jonathan Gallimore Date: Wed, 23 Oct 2024 14:30:49 +0100 Subject: [PATCH] TOMEE-4332 --- arquillian/functional-tests/pom.xml | 47 ++++++ .../spring-cxf-tomee-4332/pom.xml | 147 ++++++++++++++++++ .../example/spring/AlternativeGreeter.java | 38 +++++ .../org/example/spring/DemoApplication.java | 29 ++++ .../example/spring/GreetingController.java | 35 +++++ .../example/spring/ServletInitializer.java | 29 ++++ .../src/main/resources/application.properties | 1 + .../org/example/spring/SpringWebappTest.java | 69 ++++++++ .../src/test/resources/arquillian.xml | 32 ++++ arquillian/pom.xml | 1 + .../openejb/server/cxf/rs/CxfRSService.java | 6 + 11 files changed, 434 insertions(+) create mode 100644 arquillian/functional-tests/pom.xml create mode 100644 arquillian/functional-tests/spring-cxf-tomee-4332/pom.xml create mode 100644 arquillian/functional-tests/spring-cxf-tomee-4332/src/main/java/org/example/spring/AlternativeGreeter.java create mode 100644 arquillian/functional-tests/spring-cxf-tomee-4332/src/main/java/org/example/spring/DemoApplication.java create mode 100644 arquillian/functional-tests/spring-cxf-tomee-4332/src/main/java/org/example/spring/GreetingController.java create mode 100644 arquillian/functional-tests/spring-cxf-tomee-4332/src/main/java/org/example/spring/ServletInitializer.java create mode 100644 arquillian/functional-tests/spring-cxf-tomee-4332/src/main/resources/application.properties create mode 100644 arquillian/functional-tests/spring-cxf-tomee-4332/src/test/java/org/example/spring/SpringWebappTest.java create mode 100644 arquillian/functional-tests/spring-cxf-tomee-4332/src/test/resources/arquillian.xml diff --git a/arquillian/functional-tests/pom.xml b/arquillian/functional-tests/pom.xml new file mode 100644 index 00000000000..f6a3ead037c --- /dev/null +++ b/arquillian/functional-tests/pom.xml @@ -0,0 +1,47 @@ + + + + 4.0.0 + + + arquillian + org.apache.tomee + 9.1.4-SNAPSHOT + + + functional-tests + 9.1.4-SNAPSHOT + pom + TomEE :: Arquillian :: Functional Tests + + + + + + skip-tests-on-old-jdk + + + [17,) + + + spring-cxf-tomee-4332 + + + + diff --git a/arquillian/functional-tests/spring-cxf-tomee-4332/pom.xml b/arquillian/functional-tests/spring-cxf-tomee-4332/pom.xml new file mode 100644 index 00000000000..c4e51dc1c3b --- /dev/null +++ b/arquillian/functional-tests/spring-cxf-tomee-4332/pom.xml @@ -0,0 +1,147 @@ + + + + 4.0.0 + + + functional-tests + org.apache.tomee + 9.1.4-SNAPSHOT + + + spring-cxf-tomee-4332 + 9.1.4-SNAPSHOT + war + TomEE :: Arquillian :: Functional Tests :: Spring CXF Test + + + 2.0.0 + + + + + org.springframework.boot + spring-boot-starter-web + 3.1.11 + + + + org.springframework.boot + spring-boot-starter-tomcat + 3.1.11 + provided + + + org.springframework.boot + spring-boot-starter-test + 3.1.11 + test + + + org.junit.jupiter + junit-jupiter + + + org.junit.jupiter + junit-jupiter-api + + + + + org.apache.tomee + jakartaee-api + 9.1.1 + provided + + + org.jboss.arquillian.junit + arquillian-junit-container + 1.9.1.Final + test + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-depchain + pom + test + + + org.apache.tomee + arquillian-tomee-remote + test + + + + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-bom + ${version.shrinkwrap.resolver} + import + pom + + + org.jboss.arquillian + arquillian-bom + 1.9.1.Final + import + pom + + + org.apache.tomee + arquillian-tomee-remote + ${project.version} + test + + + + + + + demo + + + org.apache.maven.plugins + maven-war-plugin + + false + + + + org.springframework.boot + spring-boot-maven-plugin + + + paketobuildpacks/builder-jammy-base:latest + + + + + org.apache.tomee.maven + tomee-maven-plugin + ${project.version} + + ROOT + ${project.artifactId} + + + + + + diff --git a/arquillian/functional-tests/spring-cxf-tomee-4332/src/main/java/org/example/spring/AlternativeGreeter.java b/arquillian/functional-tests/spring-cxf-tomee-4332/src/main/java/org/example/spring/AlternativeGreeter.java new file mode 100644 index 00000000000..dbc1208deb4 --- /dev/null +++ b/arquillian/functional-tests/spring-cxf-tomee-4332/src/main/java/org/example/spring/AlternativeGreeter.java @@ -0,0 +1,38 @@ +/* + * 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.example.spring; + +import jakarta.ejb.Lock; +import jakarta.ejb.LockType; +import jakarta.ejb.Singleton; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Singleton +@Lock(LockType.READ) +public class AlternativeGreeter { + + @Path("hello") + @GET + @Produces(MediaType.TEXT_PLAIN) + public String sayHello() { + return "Hello World!"; + } + +} diff --git a/arquillian/functional-tests/spring-cxf-tomee-4332/src/main/java/org/example/spring/DemoApplication.java b/arquillian/functional-tests/spring-cxf-tomee-4332/src/main/java/org/example/spring/DemoApplication.java new file mode 100644 index 00000000000..a93a48e22d5 --- /dev/null +++ b/arquillian/functional-tests/spring-cxf-tomee-4332/src/main/java/org/example/spring/DemoApplication.java @@ -0,0 +1,29 @@ +/* + * 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.example.spring; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DemoApplication { + + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } + +} diff --git a/arquillian/functional-tests/spring-cxf-tomee-4332/src/main/java/org/example/spring/GreetingController.java b/arquillian/functional-tests/spring-cxf-tomee-4332/src/main/java/org/example/spring/GreetingController.java new file mode 100644 index 00000000000..67033a12555 --- /dev/null +++ b/arquillian/functional-tests/spring-cxf-tomee-4332/src/main/java/org/example/spring/GreetingController.java @@ -0,0 +1,35 @@ +/* + * 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.example.spring; + +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@RequestMapping("/greet") +public class GreetingController { + + @GetMapping(produces = MediaType.TEXT_PLAIN_VALUE) + @ResponseBody + public String sayHello() { + return "Hello World!"; + } + +} \ No newline at end of file diff --git a/arquillian/functional-tests/spring-cxf-tomee-4332/src/main/java/org/example/spring/ServletInitializer.java b/arquillian/functional-tests/spring-cxf-tomee-4332/src/main/java/org/example/spring/ServletInitializer.java new file mode 100644 index 00000000000..4280e307cd9 --- /dev/null +++ b/arquillian/functional-tests/spring-cxf-tomee-4332/src/main/java/org/example/spring/ServletInitializer.java @@ -0,0 +1,29 @@ +/* + * 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.example.spring; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +public class ServletInitializer extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(DemoApplication.class); + } + +} diff --git a/arquillian/functional-tests/spring-cxf-tomee-4332/src/main/resources/application.properties b/arquillian/functional-tests/spring-cxf-tomee-4332/src/main/resources/application.properties new file mode 100644 index 00000000000..9b5b0cbca7c --- /dev/null +++ b/arquillian/functional-tests/spring-cxf-tomee-4332/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.mvc.servlet.path=/mvc \ No newline at end of file diff --git a/arquillian/functional-tests/spring-cxf-tomee-4332/src/test/java/org/example/spring/SpringWebappTest.java b/arquillian/functional-tests/spring-cxf-tomee-4332/src/test/java/org/example/spring/SpringWebappTest.java new file mode 100644 index 00000000000..aa4775c15e4 --- /dev/null +++ b/arquillian/functional-tests/spring-cxf-tomee-4332/src/test/java/org/example/spring/SpringWebappTest.java @@ -0,0 +1,69 @@ +/** + * 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.example.spring; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.resolver.api.maven.archive.importer.MavenImporter; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +@RunWith(Arquillian.class) +public class SpringWebappTest { + + @ArquillianResource + private URL url; + + @Deployment(testable = false) + public static WebArchive createDeployment() { + return ShrinkWrap.create(MavenImporter.class).loadPomFromFile("pom.xml").importBuildOutput() + .as(WebArchive.class); + } + + @Test + public void validate() throws Exception { + assertContains(this.url.toExternalForm() + "hello", "Hello World!"); + assertContains(this.url.toExternalForm() + "mvc/greet", "Hello World!"); + } + + private static void assertContains(String url, String expectedOutput) throws IOException { + final InputStream is = new URL(url).openStream(); + final ByteArrayOutputStream os = new ByteArrayOutputStream(); + + int bytesRead; + byte[] buffer = new byte[8192]; + while ((bytesRead = is.read(buffer)) > -1) { + os.write(buffer, 0, bytesRead); + } + + is.close(); + os.close(); + + final String output = new String(os.toByteArray(), "UTF-8"); + Assert.assertNotNull("Response shouldn't be null", output); + Assert.assertTrue("Output should contain: " + expectedOutput + "\n" + output, output.contains(expectedOutput)); + } +} diff --git a/arquillian/functional-tests/spring-cxf-tomee-4332/src/test/resources/arquillian.xml b/arquillian/functional-tests/spring-cxf-tomee-4332/src/test/resources/arquillian.xml new file mode 100644 index 00000000000..9ecfccfb2cc --- /dev/null +++ b/arquillian/functional-tests/spring-cxf-tomee-4332/src/test/resources/arquillian.xml @@ -0,0 +1,32 @@ + + + + + + -1 + -1 + -1 + target/apache-tomee-remote + target/arquillian-test-working-dir + true + + + diff --git a/arquillian/pom.xml b/arquillian/pom.xml index bc317ffeb28..4934a15b90f 100644 --- a/arquillian/pom.xml +++ b/arquillian/pom.xml @@ -42,5 +42,6 @@ arquillian-openejb-embedded ziplock arquillian-tck + functional-tests diff --git a/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRSService.java b/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRSService.java index b2eea0bac9b..6d9b8a6956b 100644 --- a/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRSService.java +++ b/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRSService.java @@ -167,6 +167,12 @@ public void init(final Properties properties) throws Exception { config = properties; factoryByListener = "true".equalsIgnoreCase(properties.getProperty("openejb.cxf-rs.factoryByListener", "false")); + try { + Class.forName("org.apache.cxf.jaxrs.springmvc.SpringWebUtils"); + } catch (Throwable t) { + // ignore + } + System.setProperty("org.apache.johnzon.max-string-length", SystemInstance.get().getProperty("org.apache.johnzon.max-string-length", properties.getProperty("org.apache.johnzon.max-string-length", "8192")));