Sunday Jun 22, 2014

NetBeans Platform as a RESTful Web Service Client

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() {
    initComponents();
    setName(Bundle.CTL_CustomerExplorerTopComponent());
    setToolTipText(Bundle.HINT_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) {
        dlm.addElement(sd.getSalesyear());
    }
    list.setModel(dlm);
    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:


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
« June 2014 »
SunMonTueWedThuFriSat
14
15
19
28
29
     
       
Today