RESTful Web Service Clients

Here's a small snippet that's useful for hooking into the generated code for creating RESTful web service clients in NetBeans IDE. I.e., you start by exposing the database via RESTful web services, then you create a RESTful web service client, which gives you a new Java class with a bunch of methods for interacting with the web services.

Now, how do you print out all the, for example, customers via your RESTful web service client? Here's how, where "CustomerFacadeREST_JerseyClient" is the name of the generated RESTful web service client:

public static void main(String[] args) {
    CustomerFacadeREST_JerseyClient client = new CustomerFacadeREST_JerseyClient();
    GenericType<List<Customer>> gType = new GenericType<List<Customer>>() {};
    Response response = client.findAll_XML(Response.class);
    List<Customer> customers = response.readEntity(gType);
    for (Customer c : customers) {
        System.out.println(c.getCustomerId() + " / " + c.getName());
    }
}

And here's a step by step silent YouTube movie that shows you how to get to the place where the code snippet above can be used, i.e., how to expose a database via RESTful web services and consume them via a generated RESTful web service client:

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2015
SunMonTueWedThuFriSat
   
4
5
11
12
20
21
22
23
24
25
26
27
28
29
30
  
       
Today