How do you invoke a Java Web service constructor. Ideally when does constructor invocation happen while you consume the service from a client
1 Answer
You do not explicitly invoke a constructor from the client. From a Web services perspective, you are invoking an operation. You have no knowledge in the client of how that operation is implemented.
The life-cycle of your server-side object is in the hands of your specific implementation of JAX-WS. Possibly, at the time your server starts, it will instantiate one or more copies of your service object, and so that's when your constructor is called.
In Web services, each operation is usually a "stateless" action. If you have some standard processing you need to do, you would just include that processing in your implementation.
operationAaa(final String exampleParam) {
auditLog(exampleParam);
doAaaWork(exampleParam);
}
operationBbb(final String exampleParam) {
auditLog(exampleParam);
doBbbWork(exampleParam);
}
Now, possibly, you may have the kind of processing that could be implemented in a Handler. See this article.