users@jersey.java.net

[Jersey] Re: Jersey Client 2.6 PUT request

From: Ted M. Young [_at_jitterted] <tedyoung_at_gmail.com>
Date: Sun, 9 Mar 2014 10:55:37 -0700

Can you explain what you're trying to do? I recommend starting a new thread
if this is a totally new question.

;ted



On Sat, Mar 8, 2014 at 6:57 AM, Delm Schmidt <delm_at_gmx.net> wrote:

> 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_at_gmail.com>
> *An:* users_at_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_at_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?
>>
>