1

Using @WebService annotation it is possible to publish a stateless EJB bean as a web-service. However, is there a way to publish several web-services all having the same implementing class without going through the way of defining its child classes for this purpose?

I.e. it is achievable if we define blank classes A1, A2, A3, A4 all having @WebService annotation and being the descendants of A which actually implements the logic. Then JAX-WS will publish exactly 4 web-services all having different names but practically having the same implementation.

However, what I want is having JAX-WS register several web-services with the same implementation and inside the implementation be able to get the name of the web-service through which this implementation is invoked.

EDIT: Currently trying to achieve the result by using JAX-WS Endpoint class (runtime publisher).

azerIO
  • 519
  • 1
  • 9
  • 19
  • When creating Web services, there are two development styles: _Contract Last_ and _Contract First_. When using a contract-last approach, you start with the Java code, and let the Web service contract (WSDL) be generated from that. When using contract-first, you start with the WSDL contract, and use Java to implement said contract. http://briansjavablog.blogspot.mx/2013/01/spring-web-services-tutorial.html – Paul Vargas Apr 02 '13 at 18:33
  • Is this similar to [this question](http://stackoverflow.com/q/39346061/476716)? As @PaulVargas hinted, I can't work out if you're doing contract-first or contract-last? – OrangeDog Sep 08 '16 at 14:16

1 Answers1

0

I used such a solution:

@Startup
@Singleton
@LocalBean
public class WSPublisher
{
    @PostConstruct
    void publishAll()
    {
         Reflections reflections = new Reflections("abc.de.f");
         Set<Class<? extends MyBean>> myBeans = reflections.getSubTypesOf(MyBean.class);

         for(Class<? extends MyBean> myBean: myBeans)
             Endpoint.publish("http://localhost:9090/project/" + myBean.getSimpleName() + "WS", new MyBean());
    }
}

Now all web-service front-ends are registered dynamically and method invocations from any of them are redirected to a common implementing class.

azerIO
  • 519
  • 1
  • 9
  • 19