1

How do you invoke a Java Web service constructor. Ideally when does constructor invocation happen while you consume the service from a client

1
  • 2
    Please include which WS framework you are using. Commented Aug 24, 2009 at 8:56

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the Reply. So if i have a set of statements to be executed each time a web method is executed rather than executing once when the server starts, where should it be put. I assumed, putting this code in the constructor and creating a new Service at the client would invoke the constructor to get this job done;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.