users@jersey.java.net

[Jersey] Re: what is the Document type in low level XML support example

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Thu, 02 Jun 2011 14:16:45 +0200

Hello,

yes, its org.w3c.dom.Document.

Can you please try following resource?:

import org.w3c.dom.Document;
import org.xml.sax.InputSource;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.StringReader;

// The Java class will be hosted at the URI path "/helloworld"
@Path("/helloworld")
public class HelloWorldResource {

     private final static String XML_DOCUMENT = "<n:x
xmlns:n=\"urn:n\"><n:e>CONTNET</n:e></n:x>";

     @GET
     @Path("1")
     public Document getDoc() throws Exception {
         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
         Document d = dbf.newDocumentBuilder().parse(new InputSource(new
StringReader(XML_DOCUMENT)));
         return d;
     }
}

GET /helloworld/1 returns
<?xml version="1.0" encoding="UTF-8" standalone="no"?><n:x
xmlns:n="urn:n"><n:e>CONTNET</n:e></n:x>

which looks ok to me.

Regards,
Pavel

On 6/2/11 1:32 PM, Sushant Kumar Prasad wrote:
> What is the Document type (fully qualified name) in example 4 below?
> http://jersey.java.net/nonav/documentation/latest/user-guide.html#d4e812
>
> I tried org.w3c.dom.Document and get the following exception:
> A message body writer for Java type, class com.sun.org.apache.xerces.internal.dom.DocumentImpl, and MIME media type, application/xml;charset=UTF-8, was not found.
>
> Much appreciated!
>
> Thanks,
> Sushant
>