domoinc / domo-java-sdk

Java - Domo API SDK
https://developer.domo.com/
MIT License
25 stars 18 forks source link

Use Proxy to connect DOMO API #8

Closed zoosm3 closed 7 years ago

zoosm3 commented 7 years ago

Hello,

I am using DOMO SDK version 0.2.0 with Maven.

I tried to specify proxy host and port, but couldn't find any good modification point. It would be nicer if we could specify proxy host and port like this:

        //Build an SDK configuration
        Config config = Config.with()
                .clientId("MY_CLIENT_ID")
                .clientSecret("MY_CLIENT_SECRET")
                .apiHost("api.domo.com")
                .useHttps(true)
                .proxyHost("myproxyhost")
                .proxyPort(myproxyport)
                .scope(USER, DATA)
                .httpLoggingLevel(HttpLoggingInterceptor.Level.BODY)
                .build();

Is proxy usage supported in DOMO SDK? Is there any good implementation way to specify proxy settings?

Thanks,

checketts commented 7 years ago

The config allows overriding the httpClient that is used. However I see that it will cause trouble with the logging and oauth interceptors that make the client useful. I'll fix that in the client

        configBuilder.httpClient(new OkHttpClient.Builder()
                .readTimeout(60, TimeUnit.SECONDS)
                .addInterceptor(new OAuthInterceptor(new UrlBuilder(this), this))
                .addInterceptor(logging)
                .proxy(new Proxy(Proxy.Type.HTTP,new InetSocketAddress("proxyHost", proxyPort)))
                .build())
zoosm3 commented 7 years ago

@checketts

Thank you very much for your confirmation, would it possible for you to let me know when this fix is release?

checketts commented 7 years ago

This is released now via v0.4.0

sarnshreya commented 6 years ago

Hello @checketts , I am using DOMO java sdk version 0.4.0, I wanted to use proxy as well, But couldn't. I tried:


        //Build an SDK configuration
        Config config = Config.with()
                .clientId(DOMO_CLIENT_ID)
                .clientSecret(DOMO_CLIENT_SECRET)
                .apiHost(DOMO_API_HOST)
                .useHttps(true)
                .httpLoggingLevel(HttpLoggingInterceptor.Level.BODY)
                .scope(USER, DATA)
                .httpClient(new OkHttpClient.Builder()
                        .readTimeout(60, TimeUnit.SECONDS)
                        .proxy(new Proxy(Proxy.Type.HTTP,new InetSocketAddress(PROXY_HOST, PROXY_PORT)))
                        .build())
                .build();

But it gives me UnauthorizedException. Yes, I got my DOMO_CLIENT_ID,DOMO_CLIENT_SECRET correct.I get this exception from domo :

Exception in thread "Timer-0" com.domo.sdk.request.RequestException: Error making request url:https://api.domo.com/v1/streams?fields=all&limit=500&offset=0 reponseBody:{"status":401,"statusReason":"Internal Server Error","path":"/v1/streams","message":"com.domo.bedrock.service.exception.UnauthorizedException: Full authentication is required to access this resource",

Thank you.

checketts commented 6 years ago

That error is coming from the API. So it appears that the call is hitting the API.

I wonder if this is tied to the OAuthInterceptor being lost. See the .addInterceptor(new OAuthInterceptor(new UrlBuilder(this), this)) line above