3

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.

3 Answers3

1

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")));
GeoK
  • 96
  • 5
  • Thanks for the input. I solved the problem by myself. Nevertheless I accepted your answer, because I really appreciated your input. Thank you! :) – Paul Graystone Jan 23 '17 at 14:36
  • Thanks! I had a similar issue and while looking for a solution I stumbled on your question. The approach suggested above solved the issue in my case. – GeoK Jan 23 '17 at 15:09
1
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);
0

I somehow solved the problem by myself. Within VM arguments I now only have

-Djava.net.preferIPv4Stack=true

Further I defined a proxy config only within the application:

    client = ODataClientFactory.getClient();
    client.getConfiguration().setHttpClientFactory(
            new ProxyWrappingHttpClientFactory(URI.create("http-prox.example.com:8080")));

This worked for me. :)