Reputation: 6291
I am using Java Jersey to write web services for my app and am having some problems with the cofiguration. When I call my service as given below, it says:
message Method Not Allowed description The specified HTTP method is not allowed for the requested resource (Method Not Allowed).
Sample request:
localhost:8080/MovieManager/rest/movies?movie_count=2&country_code=USA
Here are my Service source file and web.xml file:
package com.recommendation.movies;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
@Path("/")
public class MovieData {
@GET
@Path("movies")
@Produces(MediaType.TEXT_PLAIN)
public String getMovies (@QueryParam("movie_count") int movieCount, @QueryParam("country_code") String countryCode) {
String moviesJson = null; // This has the JSON list of all movies returned by the external service
// DO SOMETHING...
// returned the customized json string...
return moviesJson;
}
}
web.xml:
<?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>Movie Manager</display-name>
<servlet>
<servlet-name>Get Top Box Office Movie Listing</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.recommendation.movies</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Get Top Box Office Movie Listing</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
Upvotes: 0
Views: 459
Reputation:
What's the version of Jersey ?
Because ... I used this, and it works !
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.test.application.sinister</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Try also
@Path("/test")
And use the following url :
localhost:8080/MovieManager/rest/test/movies?movie_count=2&country_code=USA
Upvotes: 2
Reputation: 6291
it is strange how I managed to fix this problem, but here is the solution:
Instead of using a:
@Path("/")
When I replaced it with a:
@Path("search_movie/")
and called the API with the updated URI, it works.
Upvotes: 0