Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.0.1
-
None
-
Unknown
Description
I'm migrating App to CXF3.0.1 from wink. There will be ClassCastException if I using JAXBElement List (e.g. List<JAXBElement<Book>>) in the resource method.
e.g.
@Path("booklistjaxbelement")
@Produces(MediaType.APPLICATION_XML)
@Consumes(MediaType.APPLICATION_XML)
@POST
public List<JAXBElement<Book>> echoJAXBElementBookList(List<JAXBElement<Book>> bookElements) {
List<JAXBElement<Book>> ret = new ArrayList<JAXBElement<Book>>();
Author author = null;
Author retAuthor = null;
Book retBook = null;
for (JAXBElement<Book> bookElement : bookElements)
return ret;
}
Book is an JAXB bean like this:
@XmlRootElement
public class Book {
private Author author;
private String title;
public Author getAuthor()
{ return author; }public void setAuthor(Author author)
{ this.author = author; }public String getTitle()
{ return title; }....
Test client is like this:
List<Book> source = getBookSource();
Resource resource = client.resource(JAXB_BASE_URI + "/booklistjaxbelement");
ClientResponse response =
resource.accept(MediaType.APPLICATION_XML).contentType(MediaType.APPLICATION_XML)
.post(new GenericEntity<List<Book>>(source) {
});
List<Book> responseEntity = response.getEntity(new EntityType<List<Book>>() {
});
-------------------
Debugged CXF code and find in AbstractInvoker. performInvocation, it will invoke the method.invoke. The value of paramArray here is Book ArrayList and caused this issue.
This scenario is working in wink, but doesn't work here...
protected Object performInvocation(Exchange exchange, final Object serviceObject, Method m,
Object[] paramArray) throws Exception {
paramArray = insertExchange(m, paramArray, exchange);
if (LOG.isLoggable(Level.FINER)) {
LOG.log(Level.FINER, "INVOKING_METHOD", new Object[]
);
}
return m.invoke(serviceObject, paramArray);
}