1

I am using Apache tomcat 6.0.20 I want to create Client To Consume RESTFul Web Service(using GET)

I know I can do it via the old fashion way with URLConnection (regular GET request).

But I wonder is there any way of doing it differently? maybe with Annotations?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
rayman
  • 20,786
  • 45
  • 148
  • 246

4 Answers4

4

I think this article http://www.oracle.com/technetwork/articles/javase/index-137171.html will give you good guidance how to act in both directions.

0

I'm currently using the API of spring. The connection handling for example is handled already within the RestTemplate class. Have a look to http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/remoting.html#rest-client-access.

schdef
  • 1
  • Hi, I am not using Spring framework, so I assume I cant use that API. thanks. – rayman Aug 15 '11 at 14:36
  • In this http://stackoverflow.com/questions/221442/rest-clients-for-java thread are some non-spring APIs like Jersey mentioned. – schdef Aug 15 '11 at 15:10
0

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 . This approach uses annotations.

perissf
  • 15,979
  • 14
  • 80
  • 117
-1

In the end I chose to use the JAVA SE API in the old and fashion way:

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

  }
rayman
  • 20,786
  • 45
  • 148
  • 246