Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Apache Olingo behind a proxy

I can successfully reach following OData-service using different browsers and also using Postman even so I am behind a proxy: String SERVICE_ROOT = http://services.odata.org/V4/TripPinService/

However, using Apache Olingo in Java I am not able to access this service.

JVM parameters like -Dhttp.proxySet=true -Dhttp.proxyHost=http-proxy.example.com -Dhttp.proxyPort=8080 allow me to perform basic URL functions, like retrieving HTTP status codes (google returns 200). Nevertheless, access of the OData-Service using an ODataClient is not possible (code below). No errors are thrown.

ODataClient client = ODataClientFactory.getClient();
ODataServiceDocumentRequest request = client.getRetrieveRequestFactory().getServiceDocumentRequest(SERVICE_ROOT);
ODataRetrieveResponse<ClientServiceDocument> response = request.execute();

I tried using the proxy capabilities within Olingo, however without any success:

client.getConfiguration().setHttpClientFactory(new ProxyWrappingHttpClientFactory(URI.create("http://http-proxy.example.com:8080")));

What am I doing wrong, what options do I have left?

Thank you very much.

like image 786
Paul Graystone Avatar asked Dec 05 '25 10:12

Paul Graystone


2 Answers

If you are behind an NTLM proxy you can try with NTLMAuthHttpClientFactory.

NTLMAuthHttpClientFactory ntlm = new NTLMAuthHttpClientFactory(username, password, workstation, domain);
client.getConfiguration().setHttpClientFactory(ntlm);

In case that doesn't work, you can try with cntlm. Install it, change username, password, domain and proxy in C:\Program Files (x86)\Cntlm\cntlm.ini and then invoke net start cntlm. Use this for Olingo:

client.getConfiguration().setHttpClientFactory(new ProxyWrappingHttpClientFactory(URI.create("http://localhost:3128")));
like image 133
GeoK Avatar answered Dec 06 '25 22:12

GeoK


URI uri;
String scheme = "http";
        try {
            uri = new URI  (scheme,null,host,port,null,null,null);


        } catch (URISyntaxException e) {
            throw(e);
        }
        HttpClientFactory clientProxy = new ProxyWrappingHttpClientFactory(uri,userName,password );

        client.getConfiguration().setHttpClientFactory(clientProxy);
like image 41
Rajesh Patil Avatar answered Dec 07 '25 00:12

Rajesh Patil