Geertjan's Blog

  • June 22, 2014

NetBeans Platform as a RESTful Web Service Client

Geertjan Wielenga
Product Manager

OK, let's now port the RESTful web service client created yesterday to the NetBeans Platform. Create a new NetBeans Platform application and create within it a new module. Next, create a new TopComponent via the New Window Component wizard.

Then go to the Project Properties dialog of the module. In Libraries | Wrapped JARs, include the JARs shown below.

Some of the JARs above come from the New Window Component wizard, i.e., the Window System API JAR and Nodes API JAR, among others, are added because you used the New Window Component wizard.

All the others are there because they were there at the end of the blog entry yesterday. I.e., I had generated a RESTful Web Service Client in NetBeans IDE, which added multiple JARs to the classpath of the Java SE application. These are the JARs that I added to the module as described above.

Better would be to create a separate library wrapper module, etc. Instead of including all the JARs in your functionality JAR. But the point of this exercise is simply to get the code below to work, which it does, once all the JARs above have been added as described above.

public CustomerExplorerTopComponent() {
    setLayout(new BorderLayout());
    JList list = new JList();
    DefaultListModel dlm = new DefaultListModel();
    SalesdataJerseyClient client = new SalesdataJerseyClient();
//        CustomerFacadeREST_JerseyClient client = new CustomerFacadeREST_JerseyClient();
    GenericType<List<Salesdata>> gType = new GenericType<List<Salesdata>>() {};
//        GenericType<List<Customer>> gType = new GenericType<List<Customer>>() {};
    Response response = client.findAll_XML(Response.class);
    List<Salesdata> sds = response.readEntity(gType);
    for (Salesdata sd : sds) {
    add(list, BorderLayout.CENTER);

The above code is the constructor of the TopComponent created at the start of this blog entry, i.e., I have included code for trying out some of the RESTful Web Service Client code that I ported to the functionality module. I.e., I copied the entity classes and I copied the RESTful Web Service Client into the module and then typed the code above into the constructor of the TopComponent. For example, anyone using the NetBeans Sample Derby database can try out the "CustomerFacadeREST_JerseyClient" shown above (as well as yesterday), together with RESTful Web Services generated from that same database, with this result:

Note that probably not all the JARs shown in the first screenshot above are needed. But, if those are present, the above definitely works. Now you can start weeding out the ones, could be about 5 or so I guess, that are maybe not needed after all. Via trial and error, which would have been simpler when using Maven of course, I have managed to get the list down to this:

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.