I wanted to figure out what it takes to create HelloREST application in WAS 8.0 so i followed this steps to create Hello JAX-RS service. You can download the source code for sample from here
- First i used RAD 8.0 to create Servlet Technology 3.0 compliant web application( Which means no need for web.xml or no need of declaring servlets)
- Next create a
HelloRestService
class that is basically a REST service and is available at/hellorest
url
package com.webspherenotes.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
@Path("/hellorest")
public class HelloRESTService {
@GET
@Produces("text/html")
public String sayHello(@QueryParam("name") String name){
return "Hello " + name;
}
}
Next createHelloApplication
class which is basically a REST servlet class like this.
package com.webspherenotes.rest;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/rest/")
public class HelloApplication extends Application{
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(HelloRESTService.class);
return s;
}
}
TheHelloApplication
class extendsjavax.ws.rs.core.Application
which helps you to declare the JAX-RS application, in this class i am overriding the getClasses() method which returns set of JAX-RS classes that act as JAX-RS service. In my case i do have only one HelloRESTService class so i am only adding that- Now deploy the application on your WAS 8.0 server, if you try accessing it by sending GET request to http://localhost:9080/HelloRESTService/rest/hellorest?name=Sunil URL and you should get Hello Sunil as response
This comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeletevery nice blog more information our site <a href='http://www.softql.com/services/infrastructure-management-services/datacenter">rf services </a>
ReplyDeleteThanks for info
ReplyDeleteWeb Design Company in Bangalore
Website development in Bangalore
Website development in Bangalore
ReplyDelete