1

i am trying to run the sample java application as described on

https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/getting_started/gs-full-java.shtml

i have been able to set up my liberty server properly and i have been able to create an app on the bluemix server with my account. When i try to run the sample code in Eclipse, i can see the watson q&a app interface. But when i hit the Ask button, i get

Error: Connect to gateway.watsonplatform.net:443 [gateway.watsonplatform.net/23.246.237.54] failed: Connection timed out: connect

i have not made any changes to the code except putting in the values for the url of my service and the username and password.

Is there another system property i need to set?

Edit: manifest.yaml

applications:
 - services:
  - question_and_answer
  name: myDumbApp
  path: webApp.war
  memory: 512M

also, when i run the command

cf marketplace -s question_and_answer

i see

service plan                    description   free or paid
question_and_answer_free_plan   Beta          free

is that correct?

Edit: Trying out the QuestionAndAnswer api

import java.util.HashMap;
import java.util.Map;

import com.ibm.watson.developer_cloud.personality_insights.v2.PersonalityInsights;
import com.ibm.watson.developer_cloud.personality_insights.v2.model.Profile;
import com.ibm.watson.developer_cloud.question_and_answer.*;
import com.ibm.watson.developer_cloud.question_and_answer.v1.QuestionAndAnswer;
import com.ibm.watson.developer_cloud.question_and_answer.v1.model.QuestionAndAnswerDataset;

public class PersonalityInsightsExample {
public static void main(String[] args) {

    QuestionAndAnswer qas = new QuestionAndAnswer();
    qas.setUsernameAndPassword("uName", "Pass");
    QuestionAndAnswerDataset qd = new QuestionAndAnswerDataset("TRAVEL");

    /*
    PersonalityInsights service = new PersonalityInsights();
    service.setUsernameAndPassword("uName", "Pass");

    String myProfile = "Call me Ishmael. Some years ago-never mind how long "
            + "precisely-having little or no money in my purse, and nothing "
            + "particular to interest me on shore, I thought I would sail about "
            + "a little and see the watery part of the world. It is a way "
            + "I have of driving off the spleen and regulating the circulation. "
            + "Whenever I find myself growing grim about the mouth; whenever it "
            + "is a damp, drizzly November in my soul; whenever I find myself "
            + "involuntarily pausing before coffin warehouses, and bringing up "
            + "the rear of every funeral I meet; and especially whenever my "
            + "hypos get such an upper hand of me, that it requires a strong "
            + "moral principle to prevent me from deliberately stepping into "
            + "the street, and methodically knocking people's hats off-then, "
            + "I account it high time to get to sea as soon as I can.";


    Profile profile = service.getProfile(myProfile);
      */

    qas.setDataset(qd);

    System.out.println( qas.ask("How to get cold?"));
   }
}

but i still get

SEVERE: IOException
org.apache.http.conn.HttpHostConnectException: Connection to https://gateway.watsonplatform.net refused

note that when i run

 System.out.println(qas.getEndPoint());

i get

https://gateway.watsonplatform.net/question-and-answer-beta/api

is that consistent with the imports in my code?

AbtPst
  • 7,778
  • 17
  • 91
  • 172
  • 1
    do you want to run a web app or just call the services and see the results? – German Attanasio Oct 20 '15 at 13:25
  • so, my end goal is to feed a custom corpus to the watson q&a service and then ask questions. is that feasible? i was hoping that i can do that through java. hence i first created an app on the bluemix server. next i want to be able to call the services in my app through java. finally, i would like to feed my own corpus/dataset and see the results. – AbtPst Oct 20 '15 at 13:28
  • You can't train QA with your own corpus yet. You will have to do it by combining the document conversion + retrieve and rank service. – German Attanasio Oct 20 '15 at 13:29
  • oh, thats a bummer. i will look into the document conversion and retrieve and rank. are these watson services as well? thanks. but in the meantime, how do i resolve the connection timeout? any idea what might be causing this? – AbtPst Oct 20 '15 at 13:31
  • maybe my manifest.yaml is not set up properly – AbtPst Oct 20 '15 at 13:32

2 Answers2

2

Make sure you have service credentials and you are not using your Bluemix username and password.

Since you want to use Personality-Insights I would suggest you to first start with a Main class and try to see that you have valid credentials

Running Personality Insights locally

  1. Download the Watson Developer Cloud Java SDK v1.1.1.
  2. In eclipse, create a java project(no web, plain java).
  3. Create a file and call it PersonalityInsightsExample.java.
  4. Copy the code below.

    import java.util.HashMap; import java.util.Map; import com.ibm.watson.developer_cloud.personality_insights.v2.model.Profile;

    public class PersonalityInsightsExample {

    public static void main(String[] args) {
        PersonalityInsights service = new PersonalityInsights();
        service.setUsernameAndPassword("<username>", "<password>");
    
        String myProfile = "Call me Ishmael. Some years ago-never mind how long "
                + "precisely-having little or no money in my purse, and nothing "
                + "particular to interest me on shore, I thought I would sail about "
                + "a little and see the watery part of the world. It is a way "
                + "I have of driving off the spleen and regulating the circulation. "
                + "Whenever I find myself growing grim about the mouth; whenever it "
                + "is a damp, drizzly November in my soul; whenever I find myself "
                + "involuntarily pausing before coffin warehouses, and bringing up "
                + "the rear of every funeral I meet; and especially whenever my "
                + "hypos get such an upper hand of me, that it requires a strong "
                + "moral principle to prevent me from deliberately stepping into "
                + "the street, and methodically knocking people's hats off-then, "
                + "I account it high time to get to sea as soon as I can.";
    
        Profile profile = service.getProfile(myProfile);
        System.out.println(profile);
    }
    

    }

  5. Replace username and password.

  6. Run it as a Java Application.


If you still get an error following the steps above then try opening a browser and going to: https://gateway.watsonplatform.net/personality-insights/api/v2/profile, you should get a password prompt.

enter image description here

German Attanasio
  • 22,217
  • 7
  • 47
  • 63
  • thanks, but i do not have the personality insights service bound to my app on bluemix. would the credentials for my app still work here? – AbtPst Oct 20 '15 at 13:54
  • 1
    Create a Personality Insights service in Bluemix and get the `username` and `passoword` from it – German Attanasio Oct 20 '15 at 13:59
  • that could be a problem as the personality insights service is not free in my plan. hence i am not allowed to use it in my apps. can i try to connect to the question and answer service this way? – AbtPst Oct 20 '15 at 14:02
  • i tried the above code, not having the personality insights service in my app and i get Exception in thread "main" java.lang.RuntimeException: org.apache.http.conn.HttpHostConnectException: Connection to https://gateway.watsonplatform.net refused – AbtPst Oct 20 '15 at 14:03
  • 1
    You can use the Personality Insights service for free the first 200 API call – German Attanasio Oct 20 '15 at 14:04
  • i can see that there is a QuestionAndAnswer class as well. i wrote some code for it. please see the edit. i still get the same error – AbtPst Oct 20 '15 at 14:13
  • thanks. i still get the same error. note that i am behind a proxy but i have set the http_proxy https_proxy environment variables properly. – AbtPst Oct 20 '15 at 14:40
  • what do you get when you try System.out.println(qas.getEndPoint()); – AbtPst Oct 20 '15 at 14:41
  • 1
    The problem is that you can't reach to the watson service. I can't help you with that :( – German Attanasio Oct 20 '15 at 14:42
  • hmm makes sense. must have something to do with how my bluemix account is set up. i guess i'll have to call the support! thanks for your help :) by the way, what do you get as your EndPoint? can you please check for me? – AbtPst Oct 20 '15 at 14:45
0

I had the same error tried using PersonalityInsightsExample suggested above, but seemed too complicated since, I found out that the problem was my network having to have proxy to be able to connect to foreign endpoints. So, just adding my proxy details fixed the problem:

System.setProperty("http.proxyHost",HOST);
System.setProperty("http.proxyPort",PORT);
System.setProperty("https.proxyHost",HOST);
System.setProperty("https.proxyPort",PORT);
Sayaninja
  • 11
  • 1