Invoking a worklight adaptor from a stand alone ja

2019-08-18 01:57发布

I can invoke the worklight adaptor procedure in my machine by using the below URL.

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

Now, i want to invoke this from a java program.

Code goes like this,

    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");

 }

Somehow the above program is not working. Can you pls help ?

1条回答
Emotional °昔
2楼-- · 2019-08-18 02:44

First, you should probably remove the /dev from the URL; /dev should be used only in a development environment.

Second, I suggest looking at the solution provided to this question: Java URL doesn't seem to connect, but no exception thrown

From the comments: Missing line of code:

BufferedReader in = new BufferedReader(new InputStreamReader(myURLConnection.getInputStream())); 
查看更多
登录 后发表回答