Skip to main content

Posts

Showing posts with the label RESTEasy

REST Service on JBoss 7 (using RESTEasy) - Part 3

In the last post we learnt how to output JSON from a REST service. Here is the sample JSON output that we got in the last post. [     {         "name": "Java The Complete Reference, 8th Edition",         "author": "Herbert Schildt",         "price": 479     },     {         "name": "Jboss As 7 Configuration, Deployment, And Administration",         "author": "Francesco Marchioni",         "price": 450     },     {         "name": "RESTful Java with JAX-RS 2.0 2ed",         "author": "Bill Burke",         "price": 2018     } ] RESTEasy (default JAX-RS provider for JBoss AS 7) uses Jac...

REST Service on JBoss 7 (using RESTEasy) - Part 2

In this post we are going to enhance our REST service (which we developed in the last post) to return a user defined object instead of java.lang.String or any other primitive type. 1. Create a class called Book and paste the following contents into it. package org.jbosstest.jbosstest; import java.io.Serializable; public class Book implements Serializable {     private String name;     private String author;     private float price;     public Book() {     }     public Book(String name, String author, float price) {         this.name = name;         this.author = author;         this.price = price;     }     public String getName() {         return name;     }     public void setName(String...

REST Service on JBoss 7 (using RESTEasy) - Part 1

In this section we are going to see how we can host a simple REST service on JBoss AS 7.2 1. Start NetBeans 7.3.1 and create a new maven-web project as follows. 2. Name it as JbossTest. 3.  Choose JBoss as the server. 4. Click Finish 5. You will see the following under Projects tab 6. Create a class named TestService and copy paste the content from below. package org.jbosstest.jbosstest; import javax.ejb.LocalBean; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @LocalBean @Path("/test") public class TestService {     @GET     @Path("hello/{name}")     public String sayHello(@PathParam("name") String name) {         return "Hello " + name;     } } 7. Create a class called ApplicationConfig and paste the following content. This is to register the class TestService as a RESTService. package org.jbosstest.jbosstest; import ...