user1711472
user1711472

Reputation: 15

IBM Watson Not Working In Corporate Network

I have written a code snippet in java which connects to IBM Watson Assistant API. The code runs fine in my home network but gives below error while trying to run in the corporate network. I have set the proxy before invoking the API:

System.getProperties().put("https.proxyHost", ip);
System.getProperties().put("https.proxyPort", port);
System.getProperties().put("https.proxyUser", user);
System.getProperties().put("https.proxyPassword", pwd);

When I printed the endpoint, I get below data:

URL-->https://gateway.watsonplatform.net/assistant/api

Error :

java.lang.RuntimeException: java.io.IOException: Failed to authenticate with proxy
    at com.ibm.watson.developer_cloud.service.WatsonService$WatsonServiceCall.execute(WatsonService.java:478)
    at com.fca.pd.chatbot.WatsonConversationApi.watsonService(WatsonConversationApi.java:162)
    at com.fca.pd.chatbot.WatsonConversationApi.doPost(WatsonConversationApi.java:73)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)

Upvotes: 0

Views: 124

Answers (1)

German Attanasio
German Attanasio

Reputation: 23663

You need to use the OkHttp client configuration

Here is a full example using the Assistant service:

Assistant service = new Assistant("2018-02-16") {
  @Override
  protected OkHttpClient configureHttpClient() {
    Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyHost", "proxyPort"));
    return super.configureHttpClient().newBuilder().proxy(proxy).build();
  }
};

service.setUsernameAndPassword("<username>", "<password>");

WorkspaceCollection workspaces = service.listWorkspaces().execute();
System.out.println(workspaces);

Make sure you replace "proxyHost" and "proxyPort"

For more information on how to setup the proxy, take a look at OkHTTPClient Proxy authentication how to?

Upvotes: 1

Related Questions