DZone
Integration Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Integration Zone > Building Rest Service Made Easy Using Eclipse Plugin

Building Rest Service Made Easy Using Eclipse Plugin

Want to get a RESTful service up and running quickly? There is an Eclipse plugin for that.

Vivek Raut user avatar by
Vivek Raut
·
May. 12, 16 · Integration Zone · Tutorial
Like (1)
Save
Tweet
16.43K Views

Join the DZone community and get the full member experience.

Join For Free

RESTful services have become increasingly popular and as a result, there are various frameworks that support the development of REST Services. Each has their own advantages, but some of the widely used ones are:

  • Jersey
  • RestEasy
  • Restlet
  • Spring

Eclipse provides a plugin that leverages these frameworks and helps in rapidly developing services.

If you do not have eclipse installed on your machine, then download the installer from https://eclipse.org/downloads/.

In order to start with developing REST Services, download the plugin from https://marketplace.eclipse.org/content/restful-plugin-eclipse.

Once the plugin is installed successfully, you should be able to see a new category, “Restful Webservice,” in the wizard menu.

This plugin also provides the capability to add jars or libraries to the project and generate template classes.

Now create a new project in eclipse. Choose the dynamic web project as an option to create the project. Name the project and click Next. Leave the other options as default ones. In the Web Module screen, check the “Generate web.xml deployment descriptor” option and click Finish.

To make the project Jersey compliant, right click on project root and select New->other.

Go to the Restful Webservice option and choose the Jersey RESTful Webservice. It will launch the Jersey Restful Webservice wizard.

Enter the package name and click on Finish. Do not modify any other values.

The Web.xml file will get updated, and jersey jars are added to the lib folder.

A java class (with the same name as in the wizard) gets generated with Jersey supported annotations. The class is your starting point to develop a  REST service. Here is what it will look like:

@Path(“/<add your restful service class name here>”)

public class SimpleRestService {

private static final Logger logger = Logger.getLogger(SimpleRestService.class);


The @Path annotation will define the service class name. Similarly, every resource in the service has to be identified uniquely using the @Path annotation at method level.

You can also make the project RestEasy compliant. In this case, class generated will look like as follows:

@Path(“/<add your restful service class name here>”)

public class SimpleRestService {

private static final Logger logger = Logger.getLogger(SimpleRestService.class);

@GET

@Path(“/<add method name here>”)

@Produces(MediaType.TEXT_PLAIN)

public String getSomething(@QueryParam(“request”) String request ,

@DefaultValue(“1”) @QueryParam(“version”) int version) {


A Restlet compliant class will look like as follows:

public class SimpleRestService extends ServerResource {

private static final Logger logger = Logger.getLogger(SimpleRestService.class);

@Get

public String getSomething() {


A Spring compliant class will be seen like the one below:

@RestController

@RequestMapping(“/<add your restful service class name here>”)

public class SimpleRestController {

// Logger instance

private static final Logger logger = Logger.getLogger(SimpleRestController.class);

@RequestMapping(value = “/<add method name here>”, method = RequestMethod.GET)

public String getSomething(@RequestParam(value = “request”) String request, @RequestParam(value = “version”, required = false, defaultValue = “1”) int version) {

if (logger.isDebugEnabled()) {

logger.debug(“Start getSomething”);

logger.debug(“data: ‘” + request + “‘”);
Web Service Eclipse REST

Published at DZone with permission of Vivek Raut, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Flutter vs React Native. How to Cover All Mobile Platforms in 2022 With No Hassle
  • ERP Integration Guide | Common Scenarios, Challenges, and Methods
  • Handling Sensitive Data: A Primer
  • How To Deploy Apache Kafka With Kubernetes

Comments

Integration Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo