users@jersey.java.net

Re: [Jersey] Force contenttype?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 06 Feb 2009 11:52:57 +0100

Hi,

It seems you PHP server is not sending XML. The error:

   javax.ws.rs.WebApplicationException:
javax.xml.bind.UnmarshalException
   - with linked exception:
   [org.xml.sax.SAXParseException: Content is not allowed in prolog.]

is an SAX XML parsing error.

I recommend adding the Client side logging filter:

   Client c = ...
   c.addFilter(new com.sun.jersey.api.client.filter.LoggingFilter());

which will log the request produce by the client (before it gets sent
to the HTTP URL connection) and the response (after it has been
received by the HTTP URL connection).

Paul.

On Feb 6, 2009, at 10:56 AM, tarjei wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>
> I'm trying to use the Client Api to post a class to a PHP page. One
> thing i do not completely understand is how I can make the client
> post XML.
>
> Right now I am doing:
>
> Client client = Client.create();
> WebResource resource = client.resource(url);
> Builder r2 = resource.path("/").accept(MediaType.APPLICATION_XML)
> .type("application/xml");
> r2.post(MyDocument.class, document);
>
> And get:
> com.sun.jersey.api.client.ClientHandlerException: A message body
> reader
> for Java type, class com.scanmine.indexPlugin.IndexerDocument, and
> MIME
> media type, text/html;charset=UTF-8, was not found
>
> Now, I changed my PHP server and added
> header ('Content-type: application/xml');
>
> Which resolved that issue, but the server responds with just an "OK"
> and
> that gives me:
>
> javax.ws.rs.WebApplicationException: javax.xml.bind.UnmarshalException
> - with linked exception:
> [org.xml.sax.SAXParseException: Content is not allowed in prolog.]
>
> In the end, my questions are:
> * How can I force the Client to send marshaled XML regardless of the
> servers content-type?
>
> * How can I make the client accept a simple string, while posting the
> marshalled document to the server?
>
>
>
> Regards,
> Tarjei
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFJjAlKYVRKCnSvzfIRAiDdAKCS+xqt6rjJBmTx2k2PH8GKNE3oJACfRy8I
> n20HJ2mYemLOYSHh9sej7GU=
> =jKek
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>