You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by Paul Graystone <pa...@ymail.com> on 2017/01/13 10:15:28 UTC

Fw: How to use Olingo with a proxy?

 Dear Olingo users,
I am trying to access http://services.odata.org/V4/TripPinService/ (the SERVICE_ROOT) via Olingo from behind a proxy. I am able to reach this service using different browser and also with Postman. However, with Apache Olingo the connection fails.In order to make Java use the proxy I set following JVM parameters:-Dhttp.proxySet=true -Dhttp.proxyHost=http-proxy.example.com -Dhttp.proxyPort=8080With this parameters set I am able to perform basic URL functions, like retrieving the HTTP status code of a web page (google returns correctly "200"). However, it seems as Olingo still won't use the proxy. Following code for example does not execute (it seems to be stuck doing the execute), nor is any error 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 is the right way to use Olingo from behind a proxy?Thank you very much.Kind regards,Paul

   

RE: How to use Olingo with a proxy?

Posted by Rob Sessink | Kramp <Ro...@kramp.com>.
Hello Paul,

using Apache Olingo through a proxy is certainly possible, In my development setup, I use it in combination with Fiddler for debugging purposes. Please see the below code for wrapping the ODataClient with a ProxyWrappingHttpClientFactory.

Regards Rob

----
    private ODataClient client;

    private void initialize() {
        client = ODataClientFactory.getClient();
        HttpClientFactory factory = getNTLMAuthHttpClientFactory();
        factory = wrapProxy(factory, proxyURI);
        client.getConfiguration().setHttpClientFactory(factory);
    }

/**
 * Wrap the factory to tunnel through a proxy
 *
 * @param factory  HttpClientFactory
 * @param proxyUri String proxy url
 * @return HttpClientFactory
 */
private HttpClientFactory wrapProxy(HttpClientFactory factory, String proxyUri) {
    try {
        if (proxyUri == null || proxyUri.isEmpty()) {
            return factory;
        }
        return new ProxyWrappingHttpClientFactory(new URI(proxyUri),
                (DefaultHttpClientFactory) factory);
    } catch (URISyntaxException e) {
        LOG.error("Proxy URL: {} is invalid, proxy is not used", proxyUri, e);
        return factory;
    }
}
----

From: Paul Graystone [mailto:paul.graystone@ymail.com]
Sent: Friday, January 13, 2017 11:15 AM
To: user@olingo.apache.org
Subject: Fw: How to use Olingo with a proxy?

 Dear Olingo users,

I am trying to access http://services.odata.org/V4/TripPinService/ (the SERVICE_ROOT) via Olingo from behind a proxy. I am able to reach this service using different browser and also with Postman. However, with Apache Olingo the connection fails.
In order to make Java use the proxy I set following JVM parameters:
-Dhttp.proxySet=true -Dhttp.proxyHost=http-proxy.example.com -Dhttp.proxyPort=8080
With this parameters set I am able to perform basic URL functions, like retrieving the HTTP status code of a web page (google returns correctly "200"). However, it seems as Olingo still won't use the proxy. Following code for example does not execute (it seems to be stuck doing the execute), nor is any error 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 is the right way to use Olingo from behind a proxy?
Thank you very much.
Kind regards,
Paul


Met vriendelijke groeten - Best regards - Mit freundlichen Gr??en - Sinc?res salutations

Rob Sessink

Integration Engineer





[cid:1.jpg]


[cid:Kramp_Logo.jpg]<http://www.kramp.com>


[cid:2.jpg]


DISCLAIMER This e-mail message may contain confidential or privileged information and is intended solely for the individual to whom it is addressed. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. If you have received it in error, please notify us immediately by telephoning +31 315 254299, and destroy this e-mail and any attachments. E-mail transmission cannot be guaranteed to be secured or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission.


P  Save Paper - Do you really need to print this e-mail?