Code Monkey home page Code Monkey logo

ex-02_restful_web_services's Introduction

Ex-02_RESTful_Web_Services

Aim:

To create, deploy and execute RESTful Web service programs using Server, Client and Client-Side remote invocation

Procedure:

Server side:

Step 1: Create a new Java Web Project. Follow Steps 1-5 as in SOAP Based Web Service. Step 2: Right-click on the project name and select New->RESTful Web Services from Patterns.

Step 3: A new window will appear. Select “Simple Root Resource” and click Next.

Step 4: In the next window, give a Resource Package name and choose MIME Type as “text/html”. Click Finish.

Step 5: Two editing tabs will appear. Close “ApplicationConfig.java”. You need to write all your required functionalities in GenericResource.java. Step 6: Alter getHtml() method as shown below. Step 7: Save your project, clean and build it. Deploy your project.

Step 8: To test your web service, open a new browser window/tab and type the URL as http://localhost:8080/project_name/webresources/generic?params=45&params=35 and hit enter. (This is the easiest way of testing the web service when it makes use of List).

Client-Side:

Step 1: Create a new Java Web Project. Follow steps 1-5 as in section 1.1. Step 2: Right-click on the project and select New->RESTful Java Client.

Step 3: A new window will appear. In that, give a name to your client, a package name and select “From Project” under the “Select the REST resource:” tab and click Browse. Step 4: Carefully select your RESTful resource (web service) and click OK.

Step 5: Once everything is filled, the New RESTful Java Client window should look like this. Click Finish.

Step 6: An editing tab will open. Alter getHtml() method with the following.

Step 7: Right-click on the Libraries folder under your project and select “Add JAR/Folder”.

Step 8: A new window will appear. Navigate to the folder where you have placed the “javax.ws.rs-api2.0.1.jar” file and select Open.

Step 9: Right-click on the Web Pages folder and select JSP. In the new window, give a name to the JSP page and click Finish. Step 10: A new tab will appear with the default contents of the JSP page. In that, include at the top and type the following code to invoke the client java code.

Step 11: Save the project and build it. Step 12: Run the JSP file and you should see the output in a new browser window.

Client-Side Remote Invocation:

Step 1: Follow steps 1-5 as in Section 2.2 Step 2: In the generated NewJerseyClient.java file, Replace BASE_URI from private static final String BASE_URI = "http://localhost:8080/RESTful_Server/webresources"; TO private static final String BASE_URI = "http://192.168.116.62:8080/RESTful_Server/webresources"; Step 3: Follow steps 6-12 as in Section 2.2

Result:

Thus, the RESTful web service program has been successfully created and executed.

ex-02_restful_web_services's People

Contributors

drmalathisaravanan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.