Consume a calm web service through a web proxy

I am trying to use a soothing web service in java using the Apache Wink framework through my web proxy requiring authentication

ClientConfig clientConfig = new ClientConfig(); clientConfig.proxyHost("proxy.school.com"); clientConfig.proxyPort(3128); //nothing to set username and password :( RestClient client = new RestClient(clientConfig); Resource resource = client.resource("http://vimeo.com/api/v2/artist/videos.xml"); String response = resource.accept("text/plain").get(String.class); 

I also tried using BasicAuthSecurityHandler , but it seems to be used to authenticate directly to the web server, not the web proxy

 BasicAuthSecurityHandler basicAuthHandler = new BasicAuthSecurityHandler(); basicAuthHandler.setUserName("username"); basicAuthHandler.setPassword("password"); config.handlers(basicAuthHandler); 

It still does not work with HTTP 407 error code: Proxy authentication required.

I was looking for the best I could, nothing improved to consume the web service from the Java client via web proxies, if anyone has another idea, feel free to answer

+4
source share
2 answers

Well, that was pretty hard, but I found it! I logged the HTTP requests that were made from my browser with Fiddler and found out that Proxy-Connection and Proxy-Authorization were what I was looking after reading extensive documentation like RFC 2616 about HTTP / 1.1

So, I copied the values ​​that were sent to my Java code:

 resource.header("Proxy-Connection", "Keep-Alive"); resource.header("Proxy-Authorization", "Basic encodedString"); 

where encodedString is what my browser sends: username:password base64 encoded

And now it works great :)

+3
source

This problem was raised as [1] and has since been resolved with the addition of the ProxyAuthSecurityHandler, available for Apache Wink client software developers.

[1]: https://issues.apache.org/jira/browse/WINK-292 Apache Wink JIRA issue WINK-292

+1
source

Source: https://habr.com/ru/post/1312563/


All Articles