0

I followed this tutorial http://www.javawebtutor.com/articles/web-services/rest/creating-web-service-with-maven-jersey.php

and it accesses the API using a link like this

localhost:8080/RESTfullApp/rest/hello/inputhere

I have a requirement to replace an existing RESTFul API with a link like this:

localhost:8080/Sample.pl?Task=GetStuff&StuffNumber=1

Things done:

@Path("/Sample.pl?")
public class HelloWorldService {

    @GET
    @Path("Task=GetStuff&StuffNumber={name}")
    public Response getMsg(@PathParam("name") String name) {

        String output = "Stuff num  : " + name;

        return Response.status(200).entity(output).build();

    }

}

web.xml: what to change here?

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>RESTfulExample</display-name>
    <servlet>
        <servlet-name>jersey-serlvet</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
             <param-name>com.sun.jersey.config.property.packages</param-name>
             <param-value>com.jwt.rest</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/*I dont know what to do here*/</url-pattern>
    </servlet-mapping>

</web-app>
Al-un
  • 3,102
  • 2
  • 21
  • 40
  • First, make sure that your application context path is `/`. Then for the `I don't what to do here`, you can have `/` as well but this is not recommended: all URI for this web application will be treated as a web service endpoint and you will not be able to server normal html pages. See [here](https://stackoverflow.com/q/46725977/4906586) for example – Al-un Jan 09 '18 at 17:51
  • Both `@Path` annotations look weird. The `?` should not be part of the first `@Path` annotation and the second one should be empty or omitted. Both `task` and `stuffNumber` should be method parameters and annotated by `@QueryParam`. – braunpet Jan 13 '18 at 18:06

0 Answers0