Page 1 of 1
About Question enthuware.ocejws.v6.2.190 :
Posted: Thu Apr 17, 2014 3:18 pm
by himaiMinh
In Jersey, by default, Source, JAXBElement and any JAXB annotated objects can be serialized into application/xml media type by the standard entity provider.
However, the Jersey tutorial does not say org.w3c.dom.Document can be serialized into xml.
However, this option works fine and return XML output:
Code: Select all
@Produces("application/xml")
public Document postDocument(...){....}
The reason why it works, maybe because other dependency jar files on the classpath, like jdom.jar .
Any comments?
Re: About Question enthuware.ocejws.v6.2.190 :
Posted: Thu Apr 17, 2014 3:25 pm
by himaiMinh
To answer my own question, I just found out there is a DocumentProvider.class in com.sun.jersey.core.impl.provider.entity package. I searched for the code online :
Code: Select all
From : http://grepcode.com/file/repo1.maven.org/maven2/com.sun.jersey/jersey-core/1.1.4.1/com/sun/jersey/core/impl/provider/entity/DocumentProvider.java
@Produces({"application/xml", "text/xml", "*/*"})
@Consumes({"application/xml", "text/xml", "*/*"})
public final class DocumentProvider extends AbstractMessageReaderWriterProvider<Document> {...}
This is the entity provider that read/write Document to and from XML.
It is just this standard entity provider is not mentioned in the Jersey tutorial.
Re: About Question enthuware.ocejws.v6.2.190 :
Posted: Thu Apr 17, 2014 10:36 pm
by fjwalraven
Jersey tutorial v1.17 chapter 4.1 Low level XML support
Code: Select all
1 @Path("1")
2 @POST
3 public StreamSource get1(StreamSource streamSource) {
4 return streamSource;
5 }
6
7 @Path("2")
8 @POST
9 public SAXSource get2(SAXSource saxSource) {
10 return saxSource;
11 }
12
13 @Path("3")
14 @POST
15 public DOMSource get3(DOMSource domSource) {
16 return domSource;
17 }
18
19 @Path("4")
20 @POST
21 public Document get4(Document document) {
22 return document;
23 }