Skip to main content

Configure HTTP client to work with Sabre Red 360 proxy settings

Problem

  • When trying to access external services you need to use some HTTP API. Two of the most popular options are: Apache HTTP Components or is java.net.*.

  • Large numbers of Sabre Red 360 users are behind corporate proxies and need to configure the proxy settings. The same settings need to be retrieved by your Red App.

  • If you use Apache HTTP Components in your Red App and this is started behind a proxy you will probably be presented the UnknownHostException exception even if the URL you tried to access and proxy details you provided were correct. This occurs because Apache API is unaware of Sabre Red 360 proxy settings until you explicitly force it to be aware of it.

  • If you decide to use java.net.* you don’t need to make any exceptional configuration.

Solution

To instantiate the HTTP clients working with SR360 proxy settings you need to use the following piece of code:

For Apache library version 4.3.x:
CloseableHttpClient httpclient = HttpClients.createSystem()

Or, if you would like to use builder, then the alternative approach is:

CredentialsProvider credsProvider = new SystemDefaultCredentialsProvider();

CloseableHttpClient httpclient = HttpClients.custom().useSystemProperties().setDefaultCredentialsProvider(credsProvider).build();
For java.net.*:
URL url = new URL("http://someurl.com");
HttpURLConnection
connection = (HttpURLConnection) url.openConnection();

Discussion

Unfortunately, there is no possibility to use older version of Apache HTTP Components library because of lack of support of the NTLM proxy protocol, which is the most popular among the others. The NTLM protocol is also used in Sabre. Older versions of the library have also pure API which does not allow reading proxy settings from system properties implicitly, and so there is no chance to authorize requests without knowing the user/password but SR360 does not provide it publicly - so if for some reasons you cannot use the library in version 4.3, then we recommend using java.net API.

References

For any questions on consuming external services from Java Red Apps please contact Sabre Red App support at redappssupport@sabre.com