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.
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")));
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With