users@jersey.java.net

[Jersey] Re: Jersey Client 2.6 PUT request

From: Delm Schmidt <delm_at_gmx.net>
Date: Sat, 8 Mar 2014 15:57:59 +0100
Thanks! The correct mime type solved the problem :-)
By the way, is it possible to get the output stream?
I've to implement an interface which expects an outputstream, it is called during a file upload. The HTTPClient code looks like this:
 
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("PUT");
connection.setRequestProperty("Content-Type", MediaType.APPLICATION_OCTET_STREAM);
return connection.getOutputStream();
 
Is this also possible with jersey?
Gesendet: Mittwoch, 05. März 2014 um 22:03 Uhr
Von: "Craig McClanahan" <craigmcc@gmail.com>
An: users@jersey.java.net
Betreff: [Jersey] Re: Jersey Client 2.6 PUT request
I don't know if this is your whole problem, but "/xml" is not a valid MIME type.  It should be "application/xml" instead.
 
 
On Wed, Mar 5, 2014 at 9:26 AM, Delm Schmidt <delm@gmx.net> wrote:
I'm currently struggling with some Jersey 2 Client problems.
 
The following curl cmd is working:
curl --user user:pwd -H "Content-Type: /xml" -T data.xml -X PUT http://www.example.com/folder/file
 
Now I want to do the same with the Jersey API. But the following code produces a 400 response:
 
Client client = ClientBuilder.newClient();
HttpAuthenticationFeature authFeature = HttpAuthenticationFeature.universal("user","pwd");
client.register(authFeature);
WebTarget target = client.target("http://www.example.com/folder/file");
InputStream stream = new ByteArrayInputStream(xmlString.getBytes(StandardCharsets.UTF_8));
Response response = target.request().header("Content-Type:", "/xml")
                       .put(Entity.entity(stream, MediaType.APPLICATION_OCTET_STREAM));
 
Any idea whats wrong with this request?