Generating RESTful Web Service Java Clients

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:

  1. 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.
  2. Choose Generate REST Client. The Available REST Resources dialog opens.
    Available REST Resources dialog
  3. 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.
  4. 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.
  5. Click OK. A dialog opens asking if you want to generate Java objects from the XML schema references in the WADL file. Click Yes.
  6. 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:

  1. 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.
  2. Launch the New File wizard (Ctrl-N, or New File icon, or context menu of the node).
  3. 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.
  4. Name the class and name the class package.
  5. 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.
  6. 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.
  7. Click OK. A dialog opens asking if you want to generate Java objects from the XML schema references in the WADL file. Click Yes.
  8. (NetBeans module only) Another warning might appear asking you to add modules to the classpath. Click OK.
  9. (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.
  10. 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 .


Legal Notices