Hi All,
Has anyone tried to use the JAX-RS Jersey client to upload a file to a REST Web Service?
I'm doing the following:
HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter(userName, password);
Client.client = Client.create();
client.addFilter(authFilter);
client.setFollowRedirects(true);
final WebResource uriResource = client.resource(uri);
final ClientResponse response = uriResource.entity(new File("/home/ronak/test.tif"), "image/tif").post(ClientResponse.class);
I'm getting an exception uploading the file as so:
Root Exception stack trace:
java.io.IOException: Error writing request body to server
at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.che
ckError(HttpURLConnection.java:2637)
at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.wri
te(HttpURLConnection.java:2620)
at com.sun.jersey.api.client.CommittingOutputStream.write(CommittingOutp
utStream.java:87)
at com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider.writ
eTo(AbstractMessageReaderWriterProvider.java:73)
at com.sun.jersey.core.impl.provider.entity.FileProvider.writeTo(FilePro
vider.java:99)
at com.sun.jersey.core.impl.provider.entity.FileProvider.writeTo(FilePro
vider.java:62)
at com.sun.jersey.api.client.TerminatingClientHandler.writeRequestEntity
(TerminatingClientHandler.java:317)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invok
e(URLConnectionClientHandler.java:179)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle
(URLConnectionClientHandler.java:126)
at com.sun.jersey.api.client.filter.HTTPBasicAuthFilter.handle(HTTPBasic
AuthFilter.java:69)
at com.sun.jersey.api.client.Client.handle(Client.java:397)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:557)
at com.sun.jersey.api.client.WebResource.access$300(WebResource.java:69)
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:4
91)
Am I doing something wrong?
Thanks for your help!!
Ronak