I cannot manage to upload a file via the Jersey client via a PUT request from an InputStream (also see StackOverflow issue:
http://stackoverflow.com/questions/25708377/jersey-client-restful-file-upload-throws-clienthandlerexception-in-java-io-filed )
I keep getting the following error (with version 1.18.1 of Jersey-client/core/json and version 2.4.1.1 of Jackson-core, 2.4.1.3 of Jackson-bind and version 2.4.1 of Jackson-annotations):
com.sun.jersey.api.client.ClientHandlerException:
org.codehaus.jackson.map.JsonMappingException: No serializer found for
class java.io.FileDescriptor and no properties discovered to create
BeanSerializer (to avoid exception, disable
SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference
chain: java.io.FileInputStream["fd"])
To my knowledge this happens because it cannot serialize the InputStream somehow? I looked for examples on the Internet and the few examples
I did find show me that it should be possible with an Inputstream.
My problem happens with the following code:
WebResource webResource = client.resource("
http://someserver.com/restful");
try {
File file = new File("c:\\test.txt");
InputStream fileInStream = new FileInputStream(file);
ClientResponse clientResponse = webResource.type(MediaType.APPLICATION_JSON).put(ClientResponse.class, fileInStream);
} catch (Exception e) {
System.out.println("Cannot upload file");
e.printStackTrace();
}
What am I doing wrong or how should I solve my problem to upload a file (preferrably via an Inputstream)?
Thanks in advance.