Figured out the complete logic. Actually nothing happens on JVM startup. It's all based on lazy loading, eg the real JAX-WS/whatever provider is only loaded/instantiated the first time it's needed.
In the case of loading the JAX-WS implementation:
Assume we want to call a web service, using code like:
MyService service = new MyService_Service();
MyServiceSoap port = service.getMyServiceSoap();
port.mymethod();
then the following happens to initialize the JAX-WS implementation:
- Any JAX-WS webservice extends javax.xml.ws.Service, so MyService_Service extends Service
- When you create an instance of your web service, its superclass (javax.xml.ws.Service) is also initialized (constructor)
- The constructor for "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.
Assume we want to publish a web service using code like:
@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 following happens to initialize the JAX-WS implementation:
- Endpoint.create() runs Provider.provider().createEndpoint()
- Provider.provider() is a static method that uses javax.xml.ws.spi.FactoryFinder.find() to find and instantiate the implementation as configured.
The following links helped me understand this: