Create a JAX-RS 2 REST client application for your createAuthor and findAuthorById service.
- Make a REST client prject
- Make a new rsClient java application project in Netbeans
- Make sure your Author webservice server project is open as well
- Add a new webservice client to the client project (File > new > Webservices > RESTful Java client)
- Select the REST resource, browse for your server project and select the Author REST service
- Finish
- This creates you a project with the JAX-RS libraries and client sample code.
- You can use the sample code for your inspiration, but write your own client code
- Copy the domain classes of your server project + the JAXB adapters to the client project
- Call the createAuthor service
- In the main method of your client project create a javax.ws.rs.client.Client object
- Create a request that expects an XML or JSON reply
- Create a new Author object, without an id
- POST the author object in the body as a XML or JSON Entity. Example of the creation of a JSON entity: javax.ws.rs.client.Entity.json(author)
- Call the findAuthorById service to retrieve the Author you just created from the server
- If the createAuthor service is well written, the Location header in the javax.ws.rs.core.Response should contain the URL of the newly created Author (including the generated author id). Retrieve the URL from the Location header in the Response.
- Use the URL to retrieve the author, converted by the Client to an Author object
- Print the Author object to the console
No comments:
Post a Comment