I would like to configure a proxy server to my Jersey client.
I don't want to configure the proxy to the whole application (using JVM arguments such as http.proxyHost), and Id'e rather not use Apache client.
I read here that there is an option to do it by providing HttpUrlConnection
via HttpUrlConnectionFactory, but I couldn't find any code example.
Does anyone know how can I do it?
Thanks!
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Try
With the help of Luca, I got it done:
Implement
HttpURLConnectionFactory
, and override the methodgetHttpURLConnection
, my implementation is (thanks to Luca):Before instantiating the Jersey Client, create a new
URLConnectionClientHandler
, and provide yourHttpURLConnectionFactory
in its constructor. Then create a newClient
, and provide yourClientHandler
in theClient
constructor. My code:Hope that's help.
First of all I created this class
then I also create another class called SecureTrustManager
then after creation this class i'm calling the client like this
replace webProxy.getWeserviceHost by your proxyHost and webProxy.getWebserviceProxyPort() by the proxy port.
This worked for me and it should work also for you. Note that i'm using Jersey 1.8 but it should also work for Jersey 2