【发布时间】:2011-08-15 12:48:48
【问题描述】:
我正在使用 Apache tomcat 6.0.20 我想创建客户端来使用 RESTFul Web 服务(使用 GET)
我知道我可以通过 URLConnection(常规 GET 请求)的老式方式来做到这一点。
但我想知道有什么不同的方法吗?也许带有注释?
【问题讨论】:
标签: java rest tomcat jakarta-ee annotations
我正在使用 Apache tomcat 6.0.20 我想创建客户端来使用 RESTFul Web 服务(使用 GET)
我知道我可以通过 URLConnection(常规 GET 请求)的老式方式来做到这一点。
但我想知道有什么不同的方法吗?也许带有注释?
【问题讨论】:
标签: java rest tomcat jakarta-ee annotations
我认为这篇文章http://www.oracle.com/technetwork/articles/javase/index-137171.html 会给你很好的指导如何在两个方向上行动。
【讨论】:
我目前正在使用spring的API。例如,连接处理已经在 RestTemplate 类中处理。看看http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/remoting.html#rest-client-access。
【讨论】:
使用 NetBeans 7 可以通过简单的向导(使用 Jersey API)创建 RESTFul Web 服务: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 ();
}
【讨论】: