views:

72

answers:

1

I am trying to build a java ee webservice that has a common base class, but the child classes are the actual @webservice classes (and expose the parent class methods as @webmethod's)

Like this:

public abstract class Parent {
 @WebMethod
 public void doSomething(){//...does stuff}
}

@WebService
public class Child extends Parent {}

I've tried (and have failed):
- annotating the parent class as a webservice as well
- making sure all parent methods are annotated with @WebMethod

Is this possible, if so, how?

+2  A: 

Annotations don't inherit on methods like that, so it isn't technically possible. The subclass will have to override, call super and have the webmethod annotation.

Another option (probably the better option) is to put the annotations on an interface, and use the endpointInterface method of the @WebService annotation to reference the methods, and have the superclass implement that interface (just to make everything clear).

Yishai
With the 2nd option, I would still have to have the child class explicitly override the parents methods in order to get it to work, right?
javamonkey79
@javamonkey: No, as long as the method signatures match, the container will figure it out. You don't even need to implement the interface.
Yishai
I'll give this a try tomorrow, thanks!
javamonkey79
I'd like to note that users should annotate both the interface and the implementor web services with the same namespace. Failure to do so will inhibit client generation (at least with Axis).
javamonkey79