0

I know there lots of answered questions to the same topic, however none of the answers seem to feet my problem. I'm trying to do a REST WS in Java. @GET methods work ok, but when I try to do anything else (using either RESTClient or Poster -both Firefox extensions) I get the following message:

Status Code: 405 Method Not Allowed
Allow: GET,OPTIONS,HEAD
Content-Length: 0
Date: Thu, 02 Jan 2014 18:17:07 GMT
Server: Apache-Coyote/1.1

Example of CRUD methods:

@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/Update/{addNewData}")
public Response Update(
        @PathParam("addNewData") JSONObject addNewData) {
    String str = new JSONObject().toString();
    return Response.status(200).entity(str).build();
}

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/AddNew/{addNewData}")
public Response AddNew(
        @PathParam("addNew") JSONObject addNew) {
    String str = new JSONObject().toString();
    return Response.status(200).entity(str).build();
}

@DELETE
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.TEXT_PLAIN)
@Path("/Delete/{profileId}")
public Response Delete(@PathParam("profileId") String profileId) {
    String str = new JSONObject().toString();
    return Response.status(200).entity(str).build();
}

In case it's needed, here's the 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_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>RMGTrackerServices</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>middlewireServices</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>

Using Apache 7.0.47. Thanks in advance.

RominaV
  • 3,335
  • 1
  • 29
  • 59
  • Try enabling the trace mode in Jersey to find the real cause of the problem http://java.dzone.com/articles/troubleshooting-jersey-rest – vzamanillo Jan 02 '14 at 19:02
  • Thanks @vzamanillo. I restarted the server and now I get 404 method not found. Any ideas? – RominaV Jan 03 '14 at 12:43
  • A configuration issue maybe? http://stackoverflow.com/questions/17709039/jersey-rest-web-service-tomcat-eclipse-and-404s – vzamanillo Jan 03 '14 at 17:02

0 Answers0