I am trying to add proxy support to my Jersey Client. I use org.glassfish.jersey.core:jersey-client:2.11 but I can switch to any Jersey Client 2 version. Currently the client uses the default Jersey connector which does not support proxy AFAIK.
I have tried solution described here How to add a http proxy for Jersey2 Client but then when sending a multipart content I get:
org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
and the WARNING in the client:
Aug 10, 2015 5:10:32 PM org.glassfish.jersey.message.internal.HeaderUtils checkHeaderChanges
WARNING: There are some request headers that have not been sent by connector [org.glassfish.jersey.apache.connector.ApacheConnector]. Probably you added those headers in WriterInterceptor or MessageBodyWriter. That feature is not supported by the connector. Please, do not modify headers in WriterInterceptor or MessageBodyWriter or use default HttpUrlConnector instead.
Unsent header changes: [MIME-Version, Content-Type]
Also Jersey Client 2 documentation mentioned the issue (https://jersey.java.net/documentation/latest/user-guide.html#d0e9179)
Warning
Do not use ApacheConnectorProvider nor GrizzlyConnectorProvider neither JettyConnectorProvider connector implementations with Jersey Multipart features. See Header modification issue warning for more details.
What is the way of configuring Jersey Client 2 to support both:
?
PS. Maybe there is a way of adding proxy support to the default jersey connector implementation?
I figured out a way to work with apache connector(connectors other than default httpurl connector) as well as multipart feature. If I add boundary to content-type when build the request with Invocation.Builder, it works.
My code is as follows.
MediaType contentType = MediaType.MULTIPART_FORM_DATA_TYPE;
contentType = Boundary.addBoundary(contentType); // import org.glassfish.jersey.media.multipart.Boundary;
Response response = builder.post(Entity.entity(requestPayload, contentType), Response.class);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With