users@jersey.java.net

Force contenttype?

From: tarjei <tarjei_at_nu.no>
Date: Fri, 06 Feb 2009 10:56:26 +0100

-----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-----