从独立的Java程序调用worklight适配器

时间:2015-02-07 16:42:48

标签: java ibm-mobilefirst worklight-adapters

我可以使用以下URL在我的机器中调用worklight适配器程序。

http://192.168.1.101:10080/AdaptorUI/dev/invoke?adapter=MySQLAdaptor&procedure=procedure1&parameters=[]

现在,我想从java程序中调用它。

代码就是这样,

    try {

   URL myURL = new URL("http://192.168.1.101:10080/AdaptorUI  /dev/invoke?adapter=MySQLAdaptor&procedure=procedure1&parameters=[]");
    URLConnection myURLConnection = myURL.openConnection();
    myURLConnection.connect();

 } 
 catch (MalformedURLException e) { 
    // new URL() failed
    // ...

 System.out.println("Inside the MalformedURLException");

 } 
 catch (IOException e) {   
    // openConnection() failed
    // ...
 System.out.println("IOException");

 }

不知何故上述程序无效。你能帮忙吗?

1 个答案:

答案 0 :(得分:0)

首先,您应该从URL中删除/ dev; / dev应仅在开发环境中使用。

其次,我建议查看为此问题提供的解决方案:Java URL doesn't seem to connect, but no exception thrown

来自评论:缺少代码行:

BufferedReader in = new BufferedReader(new InputStreamReader(myURLConnection.getInputStream()));