I have following code
@Path("/hello")
public class Hello {
@GET
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_XML)
public String sayPlainTextHello(@Context UriInfo wsContext)
{
return "hello from xml";
}
}
This will result in a path http://localhost:8080/WSTest/rest/hello
. Now i want to have 2 different method so that when a user calls http://localhost:8080/WSTest/rest/hello.xml
it goes to XML method and when it calls http://localhost:8080/WSTest/rest/hello.json
it goes to JSON method. With current implementation, if i add .xml
or .json
at the end of the path, the server returns not found
error.
EDIT
here is my web.xml. Please note that if add a subpath lets say @Path("{name}.xml")
which means the web.xml
is fine.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>WSTest</display-name>
<servlet>
<servlet-name>Jersey REST Service</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.personal.ws.test</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
P.S:
I can't change the path, we want to keep the root path as http://localhost:8080/WSTest/rest/hello
it is.