From: Abhijit S. <for...@gm...> - 2011-07-10 02:12:54
|
I am getting the following error in a custom MessageBodyReader. Client code, MessageBodyReader.readFrom() and the server response are give below. Any ideas? Is this a Client Framework bug? I am using RESTEasy 2.2.1.GA. javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"collection"). Expected elements are (none) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:631) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:236) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:231) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:105) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1038) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:467) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:448) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:137) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:626) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3103) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:922) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205) at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:200) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:173) at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137) at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:184) at name.app.abhi.movieservice.jaxrs.client.contenthandling.MovieSetMessageBodyReader.readFrom(MovieSetMessageBodyReader.java:66) ==================================================================================== Client: @GET @Consumes("text/xml") public SortedSet<Movie> sendRequest() { ResteasyProviderFactory instance = ResteasyProviderFactory .getInstance(); RegisterBuiltin.register(instance); instance.registerProvider(MovieSetMessageBodyReader.class); Map<String, Object> requestAttributes = new HashMap<String, Object>(); requestAttributes.put("path", path); MovieServiceJaxRs proxy = ProxyFactory.create(MovieServiceJaxRs.class, ENDPOINT, requestAttributes); ClientResponse<TreeSet<Movie>> response = (ClientResponse<TreeSet<Movie>>) proxy .getMovieSet(path); return response.getEntity(TreeSet.class, new MovieParameterizedType()); } ======================================================================================= MessageBodyReader.readFrom(): @Override public TreeSet<Movie> readFrom(Class<TreeSet<Movie>> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { try { JAXBContext ctx = JAXBContext.newInstance(type); return (TreeSet<Movie>) ctx.createUnmarshaller().unmarshal( entityStream); } catch (JAXBException e) { e.printStackTrace(); } return null; } ======================================================================================= Server response: ?xml version="1.0" encoding="UTF-8" standalone="yes"?> <collection> <movie> <genre>Unknown</genre> <name>4.3.2.1</name> <year>2010</year> </movie> <movie> <genre>Unknown</genre> <name>Battlestar Galactica The Plan</name> <year>2009</year> </movie> </collection> |