Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java REST Caculator In this lab you’ll be implementing a number of smaller funct

ID: 3806875 • Letter: J

Question

Java REST Caculator

In this lab you’ll be implementing a number of smaller functions as part of a REST based service. You will only need to create the server side of this service so no need for any browser client code. However, be sure to test your methods using either Postman or a client browser. For this lab used the context root ‘/LabRest’ Create an online REST based calculator service with the path ‘/calculator’

Create methods for the basic arithmetic functions /Addition, /Subtraction, /Multiplication, /Division.

These will all be post operations since you will need to supply data.

Each of these calculator functions should accept two operands which will be passed via XML (ie your REST services will consume XML).

You will need to be able to return both XML and JSON responses.

Support returning the value of pi to the nth digit.

This will be a GET operation.

Use the form ‘/pi/[digits]’ where [digits] is a pathparam.

Return in both xml or json.

Create an Addition method that takes any number of operands and adds them together.

For this you will read in the operands as query parameters. (ie ‘?a=1&b=1&c=3 etc).

Since these are query params you can use GET.

You can use UriInfo to get the query params.

@GET public Response get(@Context UriInfo uriInfo){ MultivaluedMap queryParams = uriInfo.getQueryParameters(); String nameParam = queryParams.getFirst("a");

Explanation / Answer

Cache class (here we check if there any result in cache with for given parameters. If not - then we will call Logic class to calculate result):

ActInfo class (Using this in Logic class):

Error class (Error object returns by Calculator service in case of errors):

Output class (If there is no error then object of this class will be converted to JSON and returned by Calculator class):

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote