【问题标题】:Create Restful Client Consumer with Tomcat使用 Tomcat 创建 Restful 客户端消费者
【发布时间】:2011-08-15 12:48:48
【问题描述】:

我正在使用 Apache tomcat 6.0.20 我想创建客户端来使用 RESTFul Web 服务(使用 GET)

我知道我可以通过 URLConnection(常规 GET 请求)的老式方式来做到这一点。

但我想知道有什么不同的方法吗?也许带有注释?

【问题讨论】:

    标签: java rest tomcat jakarta-ee annotations


    【解决方案1】:

    我认为这篇文章http://www.oracle.com/technetwork/articles/javase/index-137171.html 会给你很好的指导如何在两个方向上行动。

    【讨论】:

    • 是的,但这是 Oracle。我谈论 Apache Tomcat。那里有能力为休息客户端使用注释吗?
    • 这里讲java。无论是 oracle 还是 apache。
    【解决方案2】:

    我目前正在使用spring的API。例如,连接处理已经在 RestTemplate 类中处理。看看http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/remoting.html#rest-client-access

    【讨论】:

    【解决方案3】:

    使用 NetBeans 7 可以通过简单的向导(使用 Jersey API)创建 RESTFul Web 服务:http://netbeans.org/kb/docs/websvc/rest.html。这种方法使用注释。

    【讨论】:

    • 但是是创建服务还是客户端?
    【解决方案4】:

    最后我还是选择了以老式的方式使用 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 ();
    
      }
    

    【讨论】:

      猜你喜欢
      • 2019-01-25
      • 1970-01-01
      • 2014-05-30
      • 1970-01-01
      • 1970-01-01
      • 2017-09-24
      • 2013-03-06
      • 1970-01-01
      • 2015-09-18
      相关资源
      最近更新 更多