This is an automated email from the ASF dual-hosted git repository.
jlmonteiro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git
The following commit(s) were added to refs/heads/master by this push:
new 9a7d168 Add a bit more tests to make sure we don't have a bug
deploying and calling bother POJO and EJB webservices under different paths
9a7d168 is described below
commit 9a7d168e6b65e4947416fad34d568b2d4b155313
Author: Jean-Louis Monteiro <[email protected]>
AuthorDate: Thu Jan 20 11:11:08 2022 +0100
Add a bit more tests to make sure we don't have a bug deploying and calling
bother POJO and EJB webservices under different paths
---
.../tests/jaxws/WebServiceContextEJBTest.java | 117 ++++++++++++++++-----
.../src/test/resources/arquillian.xml | 1 +
.../src/test/resources/ejb-jar.xml | 43 ++++++++
.../src/test/resources/openejb-jar.xml | 31 ++++++
.../src/test/resources/webservices.xml | 42 ++++++++
5 files changed, 210 insertions(+), 24 deletions(-)
diff --git
a/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxws-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxws/WebServiceContextEJBTest.java
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxws-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxws/WebServiceContextEJBTest.java
index 96659f1..4b34493 100644
---
a/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxws-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxws/WebServiceContextEJBTest.java
+++
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxws-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxws/WebServiceContextEJBTest.java
@@ -20,24 +20,29 @@ 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.asset.ClassLoaderAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.descriptor.api.Descriptors;
import org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor;
import org.junit.Assert;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.annotation.Resource;
import javax.ejb.Stateless;
+import javax.inject.Inject;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.servlet.http.HttpServletRequest;
import javax.xml.namespace.QName;
-import javax.xml.transform.*;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.Dispatch;
@@ -51,7 +56,7 @@ import java.nio.charset.StandardCharsets;
@RunWith(Arquillian.class)
-@Ignore
+// @Ignore
public class WebServiceContextEJBTest {
@ArquillianResource
private URL url;
@@ -66,49 +71,76 @@ public class WebServiceContextEJBTest {
.createServletMapping()
.servletName("HelloService")
.urlPattern("/ws/Hello")
- .up();
+ .up()
+ .createServletMapping()
+ .servletName("HelloService")
+ .urlPattern("/internal/Hello")
+ .up()
+ ;
return ShrinkWrap.create(WebArchive.class, "ROOT.war")
- .addClasses(HelloService.class)
+ .addClasses(HelloService.class, HelloServicePort.class)
+ .addAsWebInfResource(new
ClassLoaderAsset("ejb-jar.xml"), "ejb-jar.xml")
+ .addAsWebInfResource(new
ClassLoaderAsset("openejb-jar.xml"), "openejb-jar.xml")
+ .addAsWebInfResource(new
ClassLoaderAsset("webservices.xml"), "webservices.xml")
.addAsWebInfResource(new
StringAsset(webAppDescriptor.exportAsString()), "web.xml");
}
@Test
- public void invoke() throws Exception {
+ public void invokePojo() throws Exception {
+ // System.out.println(IO.slurp(new URL(url.toExternalForm() +
"/ws/Hello?wsdl")));
final Service service = Service.create(new URL(url.toExternalForm() +
"/ws/Hello?wsdl"), new
QName("http://jaxws.tests.arquillian.openejb.apache.org/", "Hello"));
final QName portQName = new
QName("http://jaxws.tests.arquillian.openejb.apache.org/", "HelloService");
+ assertServiceInvocation(service, portQName);
+ }
- final Dispatch<Source> dispatch = service.createDispatch(portQName,
Source.class, Service.Mode.PAYLOAD);
- final String request =
- " <jax:sayHello
xmlns:jax=\"http://jaxws.tests.arquillian.openejb.apache.org/\">\n" +
- " <name>tomee</name>\n" +
- " </jax:sayHello>\n";
- final Source response = dispatch.invoke(new StreamSource(new
StringReader(request)));
+ @Test
+ public void invokePojoAlternate() throws Exception {
+ final Service service = Service.create(new URL(url.toExternalForm() +
"/internal/Hello?wsdl"), new
QName("http://jaxws.tests.arquillian.openejb.apache.org/", "Hello"));
+ final QName portQName = new
QName("http://jaxws.tests.arquillian.openejb.apache.org/", "HelloService");
+ assertServiceInvocation(service, portQName);
+ }
- final TransformerFactory factory = TransformerFactory.newInstance();
- final Transformer transformer = factory.newTransformer();
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
- transformer.setOutputProperty(OutputKeys.METHOD, "xml");
- final ByteArrayOutputStream os = new ByteArrayOutputStream();
- final StreamResult streamResult = new StreamResult();
- streamResult.setOutputStream(os);
- transformer.transform(response, streamResult);
+ /*
+ CAUTION: by default JAX-WS webservices are deployed under /webservices
subcontext
+ It's possible to override or change it to something else.
+ For instance if you don't want any prefix at all, go to arquillian.xml
+ and uncomment the following line
- final String result = new String(os.toByteArray(),
StandardCharsets.UTF_8);
- System.out.println(result);
- Assert.assertTrue(result.contains("<return>Hello, tomee, test header
is set to null</return>"));
+ # tomee.jaxws.subcontext = /
+
+ Of course, the URLs bellow need to be updated.
+ I'm not committing the change because it will cause other tests to fail
+ */
+ @Test
+ public void invokeEjb() throws Exception {
+ // System.out.println(IO.slurp(new URL(url.toExternalForm() +
"/webservices/ws/HelloEjb?wsdl")));
+ final Service service = Service.create(new URL(url.toExternalForm() +
"/webservices/ws/HelloEjb?wsdl"), new
QName("http://jaxws.tests.arquillian.openejb.apache.org/", "Hello"));
+ assertServiceInvocationWithPort(service);
+ }
+
+ @Test
+ public void invokeEjbAlternate() throws Exception {
+ final Service service = Service.create(new URL(url.toExternalForm() +
"/webservices/internal/HelloEjb?wsdl"), new
QName("http://jaxws.tests.arquillian.openejb.apache.org/", "Hello"));
+ assertServiceInvocationWithPort(service);
}
@WebService(name = "Hello", targetNamespace =
"http://jaxws.tests.arquillian.openejb.apache.org/", serviceName = "Hello",
portName = "HelloService")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, parameterStyle =
SOAPBinding.ParameterStyle.WRAPPED, use = SOAPBinding.Use.LITERAL)
@Stateless
- public static class HelloService {
+ public static class HelloService implements HelloServicePort {
@Resource
private WebServiceContext context;
+ @Inject
+ private HttpServletRequest httpServletRequest;
+
@WebMethod
public String sayHello(final @WebParam(name="name") String name) {
+
+ // new Throwable().printStackTrace();
+
final MessageContext messageContext = context.getMessageContext();
final HttpServletRequest request = (HttpServletRequest)
messageContext.get(MessageContext.SERVLET_REQUEST);
@@ -116,4 +148,41 @@ public class WebServiceContextEJBTest {
return "Hello, " + name + ", test header is set to " + testHeader;
}
}
+
+ @WebService(targetNamespace =
"http://jaxws.tests.arquillian.openejb.apache.org/")
+ public interface HelloServicePort {
+ String sayHello(final @WebParam(name="name") String name);
+ }
+
+ private void assertServiceInvocationWithPort(final Service service) {
+ final HelloServicePort hello = service.getPort(HelloServicePort.class);
+ final String result = hello.sayHello("tomee");
+ System.out.println(result);
+ Assert.assertTrue(result.contains("Hello, tomee, test header is set to
null"));
+ }
+
+ private void assertServiceInvocation(final Service service, final QName
portQName) throws TransformerException {
+ final Dispatch<Source> dispatch = service.createDispatch(portQName,
Source.class, Service.Mode.PAYLOAD);
+ final String request =
+ " <jax:sayHello
xmlns:jax=\"http://jaxws.tests.arquillian.openejb.apache.org/\">\n" +
+ " <name>tomee</name>\n" +
+ " </jax:sayHello>\n";
+ final Source response = dispatch.invoke(new StreamSource(new
StringReader(request)));
+ final String result = asString(response);
+ System.out.println(result);
+ Assert.assertTrue(result.contains("<return>Hello, tomee, test header
is set to null</return>"));
+ }
+
+ private String asString(final Source response) throws TransformerException
{
+ final TransformerFactory factory = TransformerFactory.newInstance();
+ final Transformer transformer = factory.newTransformer();
+ transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+ final ByteArrayOutputStream os = new ByteArrayOutputStream();
+ final StreamResult streamResult = new StreamResult();
+ streamResult.setOutputStream(os);
+ transformer.transform(response, streamResult);
+
+ return new String(os.toByteArray(), StandardCharsets.UTF_8);
+ }
}
diff --git
a/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxws-tests/src/test/resources/arquillian.xml
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxws-tests/src/test/resources/arquillian.xml
index d24f983..667b5d2 100644
---
a/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxws-tests/src/test/resources/arquillian.xml
+++
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxws-tests/src/test/resources/arquillian.xml
@@ -26,6 +26,7 @@
<property name="dir">target/apache-tomee-remote</property>
<property
name="appWorkingDir">target/arquillian-test-working-dir</property>
<property name="properties">
+ # tomee.jaxws.subcontext = /
My\ DataSource.JdbcUrl = jdbc:hsqldb:mem:hsqldb
My\ Unmanaged\ DataSource.JdbcUrl = jdbc:hsqldb:mem:hsqldb
openejb.classloader.forced-load=org.apache.openejb.arquillian.tests.
diff --git
a/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxws-tests/src/test/resources/ejb-jar.xml
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxws-tests/src/test/resources/ejb-jar.xml
new file mode 100644
index 0000000..d995843
--- /dev/null
+++
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxws-tests/src/test/resources/ejb-jar.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+-->
+<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
+ version="3.0" id="ejb-jar-descriptor" metadata-complete="false">
+
+ <enterprise-beans>
+
+ <session>
+ <ejb-name>HelloServiceEjb</ejb-name>
+
<service-endpoint>org.apache.openejb.arquillian.tests.jaxws.WebServiceContextEJBTest$HelloServicePort</service-endpoint>
+
<ejb-class>org.apache.openejb.arquillian.tests.jaxws.WebServiceContextEJBTest$HelloService</ejb-class>
+ <session-type>Stateless</session-type>
+ <transaction-type>Container</transaction-type>
+ </session>
+
+ <session>
+ <ejb-name>InternalHelloServiceEjb</ejb-name>
+
<service-endpoint>org.apache.openejb.arquillian.tests.jaxws.WebServiceContextEJBTest$HelloServicePort</service-endpoint>
+
<ejb-class>org.apache.openejb.arquillian.tests.jaxws.WebServiceContextEJBTest$HelloService</ejb-class>
+ <session-type>Stateless</session-type>
+ <transaction-type>Container</transaction-type>
+ </session>
+
+ </enterprise-beans>
+
+</ejb-jar>
diff --git
a/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxws-tests/src/test/resources/openejb-jar.xml
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxws-tests/src/test/resources/openejb-jar.xml
new file mode 100644
index 0000000..b2248ac
--- /dev/null
+++
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxws-tests/src/test/resources/openejb-jar.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+-->
+
+<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1">
+
+ <enterprise-beans>
+ <session>
+ <ejb-name>HelloServiceEjb</ejb-name>
+ <web-service-address>/ws/HelloEjb</web-service-address>
+ </session>
+ <session>
+ <ejb-name>InternalHelloServiceEjb</ejb-name>
+ <web-service-address>/internal/HelloEjb</web-service-address>
+ </session>
+ </enterprise-beans>
+
+</openejb-jar>
diff --git
a/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxws-tests/src/test/resources/webservices.xml
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxws-tests/src/test/resources/webservices.xml
new file mode 100644
index 0000000..6cb0ee6
--- /dev/null
+++
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxws-tests/src/test/resources/webservices.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+-->
+<webservices xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd"
+ version="1.1">
+
+ <webservice-description id="HelloServiceEjb">
+ <webservice-description-name>HelloServiceEjb</webservice-description-name>
+ <port-component>
+ <port-component-name>HelloServiceEjbPort</port-component-name>
+ <wsdl-port>HelloService</wsdl-port>
+
<service-endpoint-interface>org.apache.openejb.arquillian.tests.jaxws.WebServiceContextEJBTest$HelloServicePort</service-endpoint-interface>
+ <service-impl-bean>
+ <ejb-link>HelloServiceEjb</ejb-link>
+ </service-impl-bean>
+ </port-component>
+ <port-component>
+ <port-component-name>InternalHelloServiceEjbPort</port-component-name>
+ <wsdl-port>HelloService</wsdl-port>
+
<service-endpoint-interface>org.apache.openejb.arquillian.tests.jaxws.WebServiceContextEJBTest$HelloServicePort</service-endpoint-interface>
+ <service-impl-bean>
+ <ejb-link>InternalHelloServiceEjb</ejb-link>
+ </service-impl-bean>
+ </port-component>
+ </webservice-description>
+
+</webservices>