0% found this document useful (0 votes)
1K views25 pages

Jax-Rs Hello World With Resteasy

The document shows how to create a simple RESTful web service using JAX-RS and RESTEasy that returns the string "Hello World". It involves creating a HelloWorldResource class with a GET method annotated with @Path and @Produces, a MyRESTApplication class that registers the resource, and modifying web.xml to register the RESTEasy servlet and application class. When deployed, output is shown confirming successful deployment and registration of the resource.

Uploaded by

Punit Batra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views25 pages

Jax-Rs Hello World With Resteasy

The document shows how to create a simple RESTful web service using JAX-RS and RESTEasy that returns the string "Hello World". It involves creating a HelloWorldResource class with a GET method annotated with @Path and @Produces, a MyRESTApplication class that registers the resource, and modifying web.xml to register the RESTEasy servlet and application class. When deployed, output is shown confirming successful deployment and registration of the resource.

Uploaded by

Punit Batra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

JAX-RS Hello World with RESTEasy

From jboss-soa-p.5.0.0\resteasy\resteasy-jaxrs.war\WEB-INF\lib

jaxrs-api.jar, resteasy-jaxrs.jar, scannotation.jar

Drag & Drop

New Class

package mypackage; import javax.ws.rs.Produces; import javax.ws.rs.GET; import javax.ws.rs.Path; @Path("/helloworld") public class HelloWorldResource { @GET @Produces("text/plain") public String sayHello() { return "Hello World"; } }

New Class

package mypackage; import java.util.Set; import java.util.HashSet; import javax.ws.rs.core.Application; public class MyRESTApplication extends Application { private Set<Object> singletons = new HashSet<Object>(); private Set<Class<?>> empty = new HashSet<Class<?>>(); public MyRESTApplication(){ singletons.add(new HelloWorldResource()); } @Override public Set<Class<?>> getClasses() { return empty; } @Override public Set<Object> getSingletons() { return singletons; }

Edit web.xml

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-ap id="WebApp_ID" version="2.5"> <display-name>My_JAX-RS_HelloWorld</display-name> <context-param> <param-name>javax.ws.rs.Application</param-name> <param-value>mypackage.MyRESTApplication</param-value> </context-param> <listener> <listener-class> org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap </listener-class> </listener> <servlet> <servlet-name>Resteasy</servlet-name> <servlet-class> org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher </servlet-class> </servlet> <servlet-mapping> <servlet-name>Resteasy</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>

On Console tab, assumes server is already started

21:58:58,169 INFO [TomcatDeployment] deploy, ctxPath=/My_JAX-RS_HelloWorld 21:58:58,472 INFO [ResteasyDeployment] Deploying javax.ws.rs.core.Application: class mypackage.MyRESTApplication 21:58:58,472 INFO [ResteasyDeployment] Adding singleton resource mypackage.HelloWorldResource from Application javax.ws.rs.core.Application

Deployed

You might also like