Click here to Skip to main content
15,887,246 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I tried to upload a document to a document server with Jersey. But curiously I can't set a header value. If I set the value as query param(server supports it) all works fine. But I wan't set it in the header. Here is my Java Code:
Java
Client client =ClientBuilder.newClient()
                    .register(JacksonFeature.class)
                    .register(MultiPartFeature.class);
            WebTarget webTarget=client.target("http://.../documents").queryParam("Token",token);//works
            FileDataBodyPart fileDataBodyPart = new FileDataBodyPart("filedata", file, MediaType.APPLICATION_OCTET_STREAM_TYPE);
            MultiPart multiPart = new MultiPart();
            multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
            multiPart.bodyPart(fileDataBodyPart);
            Response response=webTarget.request(MediaType.APPLICATION_JSON_TYPE)
.header("Token",token)//header don't works
                    .post(Entity.entity(multiPart,multiPart.getMediaType()));


I tried the same in Ruby and it works for the same URL with the same values and the Token param in the header:

Ruby
require 'rest-client'
...
resp=RestClient.post url, JSON.generate(conversion_options), {content_type: :json,
                                                              accept: :json,
                                                              Token: token}
#Third param is header values
...


Is there a bug in Jersey for setting headers? My version is 2.22.2.

Thanks for helpful comments.

What I have tried:

Tried it with Ruby, in upper and lower and diverse possible solutions with Jersey.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900