Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using RESTeasy on Tomcat

I am new to restful web services.One of my client given me some methods with resteasy implementation those methods i have use in my project.I am using apache tomcat server in my project.can these methods will run on apache tomcat server or not???

like image 554
Sujithrao Avatar asked Jan 08 '23 01:01

Sujithrao


1 Answers

Yes it's possible. You need to add the RESTeasy implementation jars/dependencies.

For Maven (resteasy.version == 3.0.9.Final)

<!-- Basic support -->
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxrs</artifactId>
    <version>${resteasy.version}</version>
</dependency>
<!-- Servlet pluggability support -->
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-servlet-initializer</artifactId>
    <version>${resteasy.version}</version>
</dependency>
<!-- JSON/POJO support -->
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jackson2-provider</artifactId>
    <version>${resteasy.version}</version>
</dependency>
<!-- REST Client support -->
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>${resteasy.version}</version>
</dependency>

You can see all the jars and transitive jars the Maven dependencies pull in (if you are not using Maven) below.

enter image description here

You can download the distribution here, which comes with all the jars. Also keep the Documentation handy. I didn't include all the dependencies that come with the distribution. Some dependencies are needed for other features. You could add all the jars (from the distribution) if you want, but I'm just showing you the basics of what it needed.

You should also pay attention to the version. The 3.x and 2.x series work of different APIs, so you may need to figure out exactly which one you need. The links I provided contain distributions and documentation for all versions. For the sake of this answer, I just used 3.0.9.Final.

Another thing, the distribution comes with a bunch of example that will probably come in handy. Though all the examples require Maven.


UPDATE

With the above jars/dependencies, you can get a simple app up and running, simply with

@ApplicationPath("/rest")
public class WebConfig extends Application {
}

@Path("/simple")
public class SimpleResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getTest() {
        return "Hello REST World!";
    }
}

No extra (web.xml) configuration is needed. With the empty Application class with the @ApplicationPath annotation, all classes with @Path will be registered as resource classes. This is made possible by the resteasy-servlet-initializer, which works off the servlet pluggability mechanism.


EDIT

In the image, the javaee-web-api jar should not be in there. I must've created a new maven web project that included that in there when I was trying to create the image.

like image 59
Paul Samsotha Avatar answered Jan 10 '23 14:01

Paul Samsotha