Figured out the full logic. Nothing actually happens when the JVM starts. All this is based on lazy loading, for example, real JAX-WS / any provider is loaded / created only for the first time.
In case of loading the JAX-WS implementation:
Suppose we want to call a web service using the following code:
MyService service = new MyService_Service(); MyServiceSoap port = service.getMyServiceSoap(); port.mymethod();
then the JAX-WS implementation is initialized:
- Any JAX-WS web service extends javax.xml.ws.Service, so MyService_Service extends the service
- When you instantiate your web service, its superclass (javax.xml.ws.Service) is also initialized (constructor)
- The constructor for the "Service" calls javax.xml.ws.spi.Provider.provider (), which is a static method that uses javax.xml.ws.spi.FactoryFinder.find () to find and instantiate the implementation as configured.
Suppose we want to publish a web service using the following code:
@WebService(endpointInterface = "my.package.MyService") public class MyServiceImp implements MyService { ... } MyServiceImp service = new MyServiceImp(); InetSocketAddress addr = new InetSocketAddress(8080); Executor executor = Executors.newFixedThreadPool(16); HttpServer server = new HttpServer(addr); server.setExecutor(executor); HttpContext context = server.createContext("/MyService"); Endpoint endpoint = Endpoint.create(service); endpoint.publish(context); server.start();
then the JAX-WS implementation is initialized:
- Endpoint.create () runs Provider.provider (). createEndpoint ()
- Provider.provider () is a static method that uses javax.xml.ws.spi.FactoryFinder.find () to search and instantiate an implementation as it is configured.
The following links helped me figure this out:
source share