DZone
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
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Building Your Next Microservice With Eclipse MicroProfile (Updated)
  • Building a MongoDB-Powered RESTful Application With Quarkus and Eclipse JNoSQL
  • How To Create a Restful Web Service Using Tibco Business Works 6 (BW6) Or Container Edition (BWCE)
  • How To REST With Rails and ActiveResource: Part Three

Trending

  • Bad Software Examples: How Much Can Poor Code Hurt You?
  • Cognitive AI: The Road To AI That Thinks Like a Human Being
  • Modular Software Architecture: Advantages and Disadvantages of Using Monolith, Microservices and Modular Monolith
  • LLMs for Bad Content Detection: Pros and Cons
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. 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 · Tutorial
Like (1)
Save
Tweet
Share
16.83K 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.

Related

  • Building Your Next Microservice With Eclipse MicroProfile (Updated)
  • Building a MongoDB-Powered RESTful Application With Quarkus and Eclipse JNoSQL
  • How To Create a Restful Web Service Using Tibco Business Works 6 (BW6) Or Container Edition (BWCE)
  • How To REST With Rails and ActiveResource: Part Three

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: