3

Suppose I have such exceptions hierarchy:

public class A extends RuntimeException {
...
}

public class B extends A {
...
}

In the web service interface there is a method:

public void aa() throws A;

Implementation of this method can throw either exception A or exception B, but while deploying to tomcat cxf publishes wsdl only with A exception declaration.

I have tried to use @XmlRootElement on both classes, @XmlType on both classes, @XmlRootElement on parent class, @XmlRootElement with @XmlSeeAlso on parent class, but published wsdl doesn't have B exception declaration. Also I have written a test that uses that wsdl and test gets only A exception however I've emulated both types of exceptions. How can I get child exception in wsdl declaration?

maks
  • 5,911
  • 17
  • 79
  • 123

1 Answers1

2

I think you need to list both A and B as possible exceptions thrown from aa, otherwise jaxb has no means to know that you might throw exceptions of derived classes. Try:

public void aa() throws A, B;
Attila
  • 28,265
  • 3
  • 46
  • 55
  • It is not very comfortable way to declare the hierarchy of exception in `throws`. Maybe it can be done by writing some interceptor? I mean, if method has declaration of exception `A`(for example) then interceptor has to add all exception that extends exception `A` – maks May 27 '12 at 21:45
  • You could certainly write an inceptor, but JAXBContext should already do that for you as long as it knows about the derived classes as well (which @XmlSeeAlso should have done for you). You might want to take a look at some other techniques as well: [1](http://stackoverflow.com/questions/6469599/using-derived-classes-when-marshelling-with-jaxb), [2](http://stackoverflow.com/questions/8318231/xmlseealso-alternative), [3](http://blog.bdoughan.com/2010/11/jaxb-and-inheritance-using-substitution.html), [4](http://blog.bdoughan.com/2010/11/jaxb-and-inheritance-moxy-extension.html) – Attila May 27 '12 at 23:22