Hi
This code is fundamentally different - here you request that a given
InputStream is represented as an individual multipart part.
In the earlier code, even though you do set a multipart media type, you
actually have InputStream simply copied to the output stream without any
multipart related wrapping.
The original code you provided is equivalent to
InputStream is = new FileInputStream(theFile);
Response = client.post(is);
If you do plan to send an input stream as an individual part then
prepare the attachment object as you did below and post it using the 2.0
Client API
Cheers, Sergey
On 27/02/15 21:20, lcasapu wrote:
Sergey,
As you suggested, I switched to pre-2.0 API WebClient and I was able to get
it to work, with no changes on the server side. The timeout does not seem
to have any impact, the code works with or without it. Here is the relevant
section:
List providers = new ArrayList();
providers.add(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider.class);
WebClient client = WebClient.create(targetUrl, providers);
client.accept(MediaType.APPLICATION_JSON);
client.type(MediaType.MULTIPART_FORM_DATA);
// -- client config --
HTTPConduit conduit = WebClient.getConfig(client).getHttpConduit();
//conduit.getClient().setReceiveTimeout(1000000000L);
//conduit.getClient().setConnectionTimeout(1000000000L);
TLSClientParameters params = conduit.getTlsClientParameters();
if (params == null) {
params = new TLSClientParameters();
}
// -- 2-way HTTPS --
TrustManagerFactory tmf = initTrustManagerFactory();
KeyManagerFactory keyManagerFactory = initKeyManagerFactory();
params.setTrustManagers(tmf.getTrustManagers());
params.setKeyManagers(keyManagerFactory.getKeyManagers());
params.setHostnameVerifier(getHostnameVerifier());
conduit.setTlsClientParameters(params);
// -- upload code --
InputStream is = new FileInputStream(theFile);
ContentDisposition cd = new ContentDisposition("attachment;
name=\"fieldName\"; filename=\"rpm\"")'
Attachment att = new Attachment("file", is, cd);
response = client.post(att);
If there is a way to get it working with 2.0 API, please let me know.
Cheers,
Liviu
--
View this message in context:
http://cxf.547215.n5.nabble.com/Unable-to-upload-file-content-using-CXF-3-0-0-and-Jackson-2-2-0-tp5754611p5754687.html
Sent from the cxf-user mailing list archive at Nabble.com.