REST Web Services
REST Web Services can now be added to your applications, with features based on Jersey. Here you will learn about:
- Web Service projects and new REST web services
- Exposing JPA entities
- Testing with the REST Web Services explorer
This feature is available in MyEclipse.
1. REST Web Services Development Tools
MyEclipse includes tools that let you amp up your web development by adding REST web services to your applications. The REST features in MyEclipse are based on Jersey, which is the reference implementation for JAX-RS, the Java API for RESTful Web Services.
2. Web Service Projects
A Web Service project is one of the project types you can create using a technology-specific project wizard. When you begin a new Web Service project, you can specify the REST (JAX-RS) framework.
Specifying the REST framework
Other configurations specific to JAX-RS that you can set in a new project are Servlet name, URL pattern, and the Jersey libraries you want to add to the build path.
Completing the REST web project configuration
You can also add the REST Web Service facet to any JavaEE 5 or higher project. Right-click the project, and select MyEclipse>Project Facets>Install JAX-RS Facet from the menu to configure the existing project as a REST web service project.
Adding the REST facet to an existing project
3. Use REST Web Services to Expose JPA Entities
Another option is to expose reverse-engineered database entities via REST web services. Exposing the entities generates REST facades. The facades provide methods that are exposed via REST for managing the database. See Exposing JPA Entities via REST Web Services for more information.
Exposing reverse-engineered entities
4. New REST Web Services
The New Web Service wizard gets you started with creating a web service. Use the Web Services icon on the toolbar.
You can choose the REST (JAX-RS) framework, and the web service creation strategy. Bottom-up creates the web service from a Java class. Top-down starts with a WSDL.
Creating a new web service
If you chose the bottom-up scenario, you can create a web service from a new or existing class.
Specifying the class from which to create the web service
Add REST resource methods to your web service class either using the Add button in the New REST Web Service window shown above, or by opening the Java class file, right-clicking the editor, and selecting MyEclipse>Add REST Method from the menu.
Adding methods while editing the Java class file
When you add methods, the New JAX-RS Resource Method window appears. Specify the method name, path, parameter details, etc.
Configuring methods for the web service
4.1 REST Project Explorer View
The REST Project Explorer view gives you an overview at a glance of the web services you’ve defined for a specific project. Use this view to quickly navigate between methods and resources; double-clicking a method in the REST Project Explorer opens the resource file to the selected method.
When you select a REST web services project in the Explorer view, the project is scanned for all methods and resources, and they appear neatly organized in the REST Project Explorer. The same resource information appears in the MyEclipse Explorer in the project’s REST Resources node.
REST resources in the REST Project Explorer and MyEclipse Explorer
To open the Rest Project Explorer view, select Window>Show View from the menu. Search for REST, or open the MyEclipse Java Enterprise node.
Opening the REST Project Explorer view
5. Testing with the REST Web Services Explorer
Right-clicking a project in the Explorer view, and selecting Run As>MyEclipse Server Application deploys the application and starts the server so you can test your REST services.
Running the application
To test in the REST explorer, right-click a project, and select MyEclipse>Test with REST Web Services Explorer.
Opening the REST Web Services Explorer
You can select operations and methods to test. The Test method link invokes the service. A new tab appears for the specified method where you can specify test details and run the test.
Selecting the method in the WADL to test
Running a method test