JAX-WS Webservice enpoint conflict between different virtual hosts
stoty2 Nov 19, 2016 2:53 PMHello,
I am trying to deploy a WAR that has a POJO Jax-WS webservice defined into two different virtual hosts with the same context, but I get
org.jboss.msc.service.DuplicateServiceException on the deployment of the second webapp.
My test webapp consists of two files:
jboss-web.xml: (with the the virtual-host element in the other webapp defined as "tb")
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_10_0.xsd" version="10.0"> <context-root>/</context-root> <virtual-host>testa</virtual-host> </jboss-web>
and the service definition Hello.java
package helloservice.endpoint; import javax.jws.WebService; import javax.jws.WebMethod; @WebService public class Hello { private String message = new String("Hello, "); public Hello() { } @WebMethod public String sayHello(String name) { return message + name + "."; } }
standalone.xml has two hosts defined, which both point to 127.0.0.1 via the /etc/hosts file (the default-web-module entries are there to work around an unrelated bug in WF11 Alpha):
<server name="default-server"> <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/> <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/> <host name="default-host" alias="localhost"> <location name="/" handler="welcome-content"/> <filter-ref name="server-header"/> <filter-ref name="x-powered-by-header"/> </host> <host name="testa" default-web-module="bug-workaround-1"/> <host name="testb" default-web-module="bug-workaround-2"/> </server>
When I start Wildfly, and deploy the webapp to "hosta", everything works fine. When I deploy the second webapp to "hostb" I get the following exception:
20:01:12,306 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC000001: Failed to start service jboss.deployment.unit."ws-virtualhost-testcase2.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."ws-virtualhost-testcase2.war".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of deployment "ws-virtualhost-testcase2.war" at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:154) at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1963) at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1896) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: org.jboss.msc.service.DuplicateServiceException: Service jboss.ws.endpoint.context=."helloservice.endpoint.Hello" is already registered at org.jboss.msc.service.ServiceRegistrationImpl.setInstance(ServiceRegistrationImpl.java:158) at org.jboss.msc.service.ServiceControllerImpl.startInstallation(ServiceControllerImpl.java:239) at org.jboss.msc.service.ServiceContainerImpl.install(ServiceContainerImpl.java:768) at org.jboss.msc.service.ServiceTargetImpl.install(ServiceTargetImpl.java:223) at org.jboss.msc.service.ServiceControllerImpl$ChildServiceTarget.install(ServiceControllerImpl.java:2416) at org.jboss.msc.service.ServiceTargetImpl.install(ServiceTargetImpl.java:223) at org.jboss.msc.service.ServiceControllerImpl$ChildServiceTarget.install(ServiceControllerImpl.java:2416) at org.jboss.msc.service.ServiceBuilderImpl.install(ServiceBuilderImpl.java:317) at org.jboss.as.webservices.service.EndpointService.install(EndpointService.java:228) at org.jboss.as.webservices.deployers.EndpointServiceDeploymentAspect.start(EndpointServiceDeploymentAspect.java:50) at org.jboss.as.webservices.deployers.AspectDeploymentProcessor.deploy(AspectDeploymentProcessor.java:73) at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:147) ... 5 more
Since these are different webapps and run in different virtual hosts, there should be no conflicts between them at all.
I poked around the code a bit, and found that if I remove the
builder.addAliases(alias);
line in the org.jboss.as.webservices.service.EndpointService.install(..) function, both webapps deploy and start without error, though, unsurprisingly, the web services are not actually available.
I think that using something like jboss.ws.endpoint.vhost="hosta".context=."helloservice.endpoint.Hello" as the service alias could fix this.
For now I have worked around by defining the Services as servlets, and giving them different <servlet-name> s, in each deployment, but it shouldn't be neccessary:
<servlet> <servlet-name>globallyuniquename-a</servlet-name> <servlet-class>helloservice.endpoint.Hello</servlet-class> </servlet> <servlet-mapping> <servlet-name>globallyuniquename-a</servlet-name> <url-pattern>/services/Hello</url-pattern> </servlet-mapping>