Quantcast

MessageBodyWriter Example for XML

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

MessageBodyWriter Example for XML

Jay_K
I am trying to generate and return an XML using below class

@Path("/portaldetails")
public class PortalResource {
        @GET
        @Produces({MediaType.APPLICATION_XML})
        public Document getLeaveDetails(@QueryParam("portalId") String portalId) {

                    Few steps to generate XML document using Dom4J
                    return portalXMLDoc;
            }
}
I am getting below exception

[3/23/10 15:52:19:982 EDT] 00000023 ContainerResp E   A message body writer for Java type, class org.dom4j.tree.DefaultDocument, and MIME media type, application/xml, was not found

Could anyone, please provide me either a sample class implementing MessageBodyWriter for above scenario or any material to get details about the same.
Thanks for the help.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: MessageBodyWriter Example for XML

Moises Lejter
The simplest thing for you to do might be to return a DocumentSource with your Document in it, rather than returning the Document itself ...  (I think JAX-RS knows about SAX sources, and I think that is what a DocumentSource is ...)

Moises

On Mar 23, 2010, at 2:58 PM, Jay_K wrote:

>
> I am trying to generate and return an XML using below class
>
> @Path("/portaldetails")
> public class PortalResource {
> @GET
> @Produces({MediaType.APPLICATION_XML})
> public Document getLeaveDetails(@QueryParam("portalId") String portalId) {
>
>                    Few steps to generate XML document using Dom4J
>                    return portalXMLDoc;
>            }
> }
> I am getting below exception
>
> [3/23/10 15:52:19:982 EDT] 00000023 ContainerResp E   A message body writer
> for Java type, class org.dom4j.tree.DefaultDocument, and MIME media type,
> application/xml, was not found
>
> Could anyone, please provide me either a sample class implementing
> MessageBodyWriter for above scenario or any material to get details about
> the same.
> Thanks for the help.
> --
> View this message in context: http://n2.nabble.com/MessageBodyWriter-Example-for-XML-tp4786769p4786769.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: MessageBodyWriter Example for XML

Marc Hadley
In reply to this post by Jay_K
Take a look at the entity-provider sample for an example of a MessageBodyWriter:

https://jersey.dev.java.net/source/browse/jersey/trunk/jersey/samples/entity-provider/

You'll need work out how to write the portalXMLDoc to an OutputStream in your writeTo method.

Marc

On Mar 23, 2010, at 3:58 PM, Jay_K wrote:

>
> I am trying to generate and return an XML using below class
>
> @Path("/portaldetails")
> public class PortalResource {
> @GET
> @Produces({MediaType.APPLICATION_XML})
> public Document getLeaveDetails(@QueryParam("portalId") String portalId) {
>
>                    Few steps to generate XML document using Dom4J
>                    return portalXMLDoc;
>            }
> }
> I am getting below exception
>
> [3/23/10 15:52:19:982 EDT] 00000023 ContainerResp E   A message body writer
> for Java type, class org.dom4j.tree.DefaultDocument, and MIME media type,
> application/xml, was not found
>
> Could anyone, please provide me either a sample class implementing
> MessageBodyWriter for above scenario or any material to get details about
> the same.
> Thanks for the help.
> --
> View this message in context: http://n2.nabble.com/MessageBodyWriter-Example-for-XML-tp4786769p4786769.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...