Author Message
chukiatdenkongpon
Joined: Nov 7, 2013
Messages: 97
Offline
Hi sir,

I would like to know how to write the servlet in DD to connect the API which provide by customer.

Could you give me sample code to connect to the API ?
Could you give me sample code to connect to the HTTP (*.jsp) ?

Please give any advice.
THank you.

Best Regards,
Chukiat D.
WilsonYu
Joined: Nov 6, 2013
Messages: 3950
Offline
Are you talking about Java API? Most likely, your customer gives you a jar file containing some java class. you need to put that jar file in the project's WEB-INF/lib directly and add it to the classpath using the project Properties window. Then you should be able to using the classes in the servlet. If you are talking about connecting to a jsp or another servlet, you can use the Java HttpURLConnection. For example:

URL url = new URL("http://localhost:8080/Test/TestServlet");
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setRequestMethod("GET");
httpCon.connect();

Or maybe it's a web service that your customer is providing, you could use DD Web Service Connector.
chukiatdenkongpon
Joined: Nov 7, 2013
Messages: 97
Offline
Hi

Thank you for suggestion.

However, if the API which provide be customer is not the *.jar file. How can DD connect to those API ?
Sample : windows API.

For *.jsp, If I used the way your suggestion to call *.jsp, what is the output of this function ?
Please give me sample.
How can I get the result from the *.jsp ?

Thank you.

Best Regards,
Chukiat D.
WilsonYu
Joined: Nov 6, 2013
Messages: 3950
Offline
You would have to use JNI (Java Native Interface) for invoking Windows APIs. There maybe 3rd party tool kits out in the market to make that eaiser.

To get the output from the http connection, you can use the following code to read the content return by the url request:

InputStream is = httpCon.getInputStream();
Reader reader = new InputStreamReader(is, "UTF-8");
int c;
StringBuffer sb = new StringBuffer();
while( (c = reader.read()) != -1){   
sb.append((char)c);
}

Please refer to the Java doc for any further help since this is the Java API that is used by Java developers
Go to:   
Mobile view