Java Reference
In-Depth Information
Excluding a Public Method from a Service
Problem
You have a service implementation that uses the @WebService annotation, but this automatic-
ally makes all public methods available on a generated WSDL.
Solution
There are three ways to deal with this:
▪ Write the WSDL yourself. If you don't generate the WSDL, the method you want to leave
out won't be there.
▪ If you are generating the WSDL, you can annotate every method that you explicitly want
to appear in the WSDL with @WebMethod . Do not add the annotation to the method you
want to leave out.
▪ Explicitly indicate @WebMethod(exclude=true) on the method you want to leave out.
Discussion
There are a few reasons that you might encounter this situation. You might have a web service
that relies on a third-party application to run, such as credit processor software. You want to
make sure that the life cycle of the dependency matches that of the EJB that defines your ser-
vice. This EJB is a stateless session bean that also implements TimedObject . The EJB is set
up as a timer so that you can have a web-based context listener that gets a callback when your
application starts and invokes a method on the EJB to start the dependency. That setup may be
fine, but you definitely don't want to expose that life cycle method web service. Still, it needs
to be public so the context listener can find it.
NOTE
There are many ways to deal with the life cycle of a dependency. One obvious design choice here
is to have the context listener invoke a public method in another class in the same package as the
EJB, and have it invoke a package-private method in the EJB. This is simply a hypothetical. It could
very well be the case, however, as this alternate solution proposes, that you may want to reconsider a
design that appears to require using @WebMethod(exclude=true) .
Search WWH ::




Custom Search