Jersey Client 2 proxy support and multi-user support

I am trying to add proxy support to my jersey client. I am using org.glassfish.jersey.core: jersey-client: 2.11, but I can switch to any version of Jersey Client 2. Currently, the client uses the default jersey connector, which does not support the AFAIK proxy.

I tried the solution described here How to add an HTTP proxy for the Jersey2 client, but then when sending multi-page content I get:

org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found 

and 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] 

The Jersey Client 2 documentation also mentioned a problem ( 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 to configure Jersey Client 2 to support both:

  • Sending multi-page content (for uploading files to the server)
  • Proxy support

?

PS. Maybe there is a way to add proxy support to implement the default default jersey connector?

+4
source share
1 answer

I figured out a way to work with the Apache connector (connectors other than the default httpurl connector), as well as a multi-page function. If I add a border to the content type when creating a 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); 
+6
source

All Articles