[英]Create Restful Client Consumer with Tomcat
我正在使用 Apache tomcat 6.0.20 我想創建客戶端以使用 RESTFul Web 服務(使用 GET)
我知道我可以通過 URLConnection (常規 GET 請求)的老式方式來做到這一點。
但我想知道有什么不同的方法嗎? 也許有注釋?
我認為這篇文章http://www.oracle.com/technetwork/articles/javase/index-137171.html將為您提供良好的指導。
我目前正在使用 spring 的 API。 例如,連接處理已經在 RestTemplate class 中處理。 看看http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/remoting.html#rest-client-access 。
Using NetBeans 7 there is the possibility to have RESTFul web services created with a simple wizard (with Jersey API): http://netbeans.org/kb/docs/websvc/rest.html . 這種方法使用注釋。
最后我選擇了以老式方式使用 JAVA SE API:
public void getRestfullMethod(...) throws IOException
{
String temp = null;
//Build the request data.
StringBuffer buf = new StringBuffer (..)
buf.append("&system=").append ("someVal");
String urlStr = buf.toString ();
//Send the request.
URL url = new URL (urlStr);
URLConnection con = url.openConnection();
//Return the response.
BufferedReader in = new BufferedReader (new InputStreamReader (con.getInputStream ()));
String inputLine = null;
buf = new StringBuffer ();
while ((inputLine = in.readLine ()) != null)
buf.append (inputLine);
in.close ();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.