NetBeans IDE can generate a Java client for a RESTful service
based on the Jersey Client API. The client code can be generated in an existing Java class, or the IDE
can generate a client class in a Java application, Web application, or NetBeans module. Java Client generation
uses the Web Services Manager.
How To Generate a RESTful client In an Existing Java Class
Use the Insert Code feature to insert RESTful service client code into
a Java class.
To insert RESTful client code:
In the Java editor, Press Alt-Insert, or right-click and select
Insert Code from the context menu. A menu of code to insert opens.
Choose Generate REST Client. The Available REST Resources dialog opens.
Browse for either a NetBeans project or a service registered in the IDE's
Web Services Manager. Note that you can register
a service in the Manager if you have the URL of the service's WSDL or WADL.
You might need to set the authentication and class name. In most cases, the
authentication and class name are read from the WADL and set automatically.
You can also select whether to authenticate over SSL.
Click OK. A dialog opens asking if you want to generate Java objects
from the XML schema references in the WADL file. Click Yes.
The IDE generates the RESTful client code. You still need to put in
any authentication keys and write additional implementation code.
For a tutorial on generating RESTful client code in a Swing application,
see .
How to Create a Client Class In an Application or Module
NetBeans IDE can generate a client class in a Java application,
Web application, or NetBeans module.
If you are generating a class in a NetBeans module,
that module needs the RESTful Web Service Libraries and their dependencies
on the module's classpath.
To create a client class:
In the Projects window, select the node of the Web application,
Java application, or NetBeans module in which you want to create a
RESTful client class.
Launch the New File wizard (Ctrl-N, or New File icon, or context menu of the node).
In the New File wizard, select the Web Services category and the
RESTful Java Client file type. Click Next. The New RESTful
Java Client panel opens.
Name the class and name the class package.
Browse for either a NetBeans project or a service registered in the IDE's
Web Services Manager. Note that you can register
a service in the Manager if you have the URL of the service's WSDL or WADL.
You might need to set the authentication and class name. In most cases, the
authentication and class name are read from the WADL and set automatically.
You can also select whether to authenticate over SSL.
Click OK. A dialog opens asking if you want to generate Java objects
from the XML schema references in the WADL file. Click Yes.
(NetBeans module only) Another warning might
appear asking you to add modules to the classpath. Click OK.
(NetBeans module only) If you need to add modules to the classpath, right-click the module's
node and open its Project Properties. Go to the Libraries section, and
add the modules with the Add Dependency button. This button opens a list
of module dependencies to browse.
The IDE generates the RESTful client code. You still need to put in
any authentication keys and write additional implementation code.
For a tutorial on generating RESTful client classes in an application,
see .