Thursday, March 4, 2010

JSR181 Web Service Annotations With Java 1.6 - Use of "@WebMethod"

We were recently testing the new JSR181 Web Service annotation with Java 1.6 and encountered some behavior that was inconsistent with the JSR 181 specification. The spec says:

2.6 Web Services Metadata:
JSR-181 metadata describes declaratively how the logic of a service implementation bean is exposed over networking protocols as a Web Service. The @WebService tag marks a Java class as implementing a Web Service. @WebMethod tags identify the individual methods of the Java class that are exposed externally as Web Service operations
In plain English it says that "@WebService" isn't enough - you need to use "@WebMethod" tags to say which public methods are to be exposed. But this isn't what happened when we ran our tests against the 1.6 JVM. What we saw was this:

You must have an "@WebService" annotation. This is expected.

But if you have a simple "@WebService" annotation all public methods appear in the service whether or not they have "@WebMethod".

The Workaround is to create an Interface that only contains those methods you want to publish and use the following syntax for the "@WebService" annotation:

@WebService(endpointInterface = 


If you use @WebService.endpointInterface all the methods in it will be exposed regardless of whether they have "@WebMethod" annotations or not. So while "@WebMethod" is useful for changing the behavior of a method it doesn't seem to control whether it's part of a Web Service or not.

We have fixed this in OrindaBuild, our web service generator, but we think this is useful for anyone working with JSR181. We have also zipped and uploaded the sample web service we created,

Note: On May 17th 2010 OrindaBuild was renamed to JDBCWizard

No comments: