Unified Information Access Blog
Welcome to Attivio's Unified Information Access Blog. Join us for discussions on topics ranging from enterprise search solutions, information access insights, Agile software development methodology to programming with Java. We hope you'll find the articles informative and participate in the discussions by leaving a comment.
Attivio uses Jetty and Apache CXF to provide Web Services. We use javax XML bind annotations on our Java objects for automatic generation of WSDL types and serialization of our objects. Overall this configuration has worked very well for us. But recently we encountered a few problems when using interfaces for the first time, implemented in multiple modules. Initially we got the exceptions IllegalAnnotationsException and MarshalException, while attempting this, but finally found the right combination of annotations to solve our problem.
Even though all the pieces to this puzzle can already be found on the web, this article provides a summary and attached example of everything working together in a single JUnit test.
Classes and Web Service API Declarations
The MyObject and MyApi interfaces below are simple representations of the POJO and web service API calls that our code uses.@XmlRootElement
public interface MyObject {
public String getName();
public void setName(String name);
}
@WebService
public interface MyApi {
public List<MyObject> getMyObjects();
public void setMyObjects(List<MyObject> objects);
}
Our objective was to have multiple modules, each with its own implementations of MyObject and MyApi, for separate Web Service calls.
IllegalAnnotationsException Encountered
The first attempt at starting web services with these objects and API calls resulted in an IllegalAnnotationsException error during startup.Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:Adding the "@XmlJavaTypeAdapter(AnyTypeAdapter.class)" annotation to the object interface solved this problem by telling JAXB to use a special type adapter needed for interfaces.
2 counts of IllegalAnnotationExceptions com.attivio.webservice.WebServiceTest$MyObject
is an interface, and JAXB can't handle interfaces.
@XmlJavaTypeAdapter(AnyTypeAdapter.class)
@XmlRootElement
public interface MyObject {
...
}
Note: The AnyTypeAdapter.java source code is very simple and can be readily found online.
Marshalling Error Encountered
It turns out that adding the AnyTypeAdapter annotation was only part of the solution. Although this annotation lets the web service start successfully, the first call to getMyObjects() resulted in a marshalling error.
INFO: Interceptor has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Marshalling Error:
class com.attivio.webservice.WebServiceTest$MyObjectImpl1
nor any of its super class is known to this context.
Caused by: javax.xml.bind.MarshalException - with linked exception:
[javax.xml.bind.JAXBException:
class com.attivio.webservice.WebServiceTest$MyObjectImpl1 nor any of its
super class is known to this context.]
The final piece of the puzzle was solved by creating a per-module interface, MyApi1, which extends MyApi and has the “@XmlSeeAlso({MyObjectImpl1.class, MyObjectImpl2.class})” annotation. By extending this interface and registering it as the endpoint class, JAXB was able to find the appropriate implementations of the MyObject interface for serialization. By putting the annotation on a module specific interface, instead of the base interface, different modules can have different objects and APIs without the need to know details of the other modules.
@WebService
@XmlSeeAlso({MyObjectImpl1.class, MyObjectImpl2.class})
public interface MyApi1 extends MyApi {
}
public static class MyApiImpl implements MyApi1 {
...
}
Attachments
Sample Code: WebServiceTest.java
Maven Dependencies: pom.xml
References
Thanks to these two posts for their helpful information:
http://jaxb.dev.java.net/guide/Mapping_interfaces.html
http://littlesquare.com/2009/11/25/using-interfaces-with-jaxb/
And thanks to SoapUI for putting out a great free tool for testing web services.

Frank
said:
|
... thanks for the suggestion. it worked for my project.I can now deploy but the service still has a problem. |
Articles by Date
Recent Posts
Thinking Like a Tester
What AIE and unified information access mean for developers
The (Real) Semantic Web Requires Machine Learning
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8

