2 Replies Latest reply on Dec 6, 2012 1:45 PM by mircea.markus

    Rest Server returns HTTP 405 Error

    sannsims

      Hello all and thanks for reading my post.

       

      This issue isn’t related to an Infinispan Cache issue; however I’m trying to get my client communicating with the Rest server so I can start working on implementing the Infinispan Cache.  I found this link:  http://www.theserverside.com/tip/RESTful-Web-services-made-easy.  When I try to invoke a simple service using the example code, I get “HTTP Status 405 - specified HTTP method is not allowed for the requested resource ()”.  The web.xml in the example shows a servlet mapping to a Jersey ServletContainer.  I’m not using Jersey; is there a different ServletContainer I should use instead?  If I do, will this conflict with the HttpServletDispatcher?

       

      Web.xml

      [code] <web-app id="WebApp_ID" version="2.5"

                      xmlns="http://java.sun.com/xml/ns/javaee"

                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

                                      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

       

                      <display-name>Infinispan cache REST server</display-name>

                      <context-param>

                                      <param-name>contextConfigLocation</param-name>

                                      <param-value>/WEB-INF/context/applicationContext.xml</param-value>

                      </context-param>

       

                      <context-param>

                                      <param-name>resteasy.resources</param-name>

                                      <param-value>org.infinispan.rest.Server</param-value>

                      </context-param>

       

                      <context-param>

                                      <param-name>resteasy.scan</param-name>

                                      <param-value>true</param-value>

                      </context-param>

       

                      <context-param>

                                      <param-name>resteasy.servlet.mapping.prefix</param-name>

                                      <param-value>/</param-value>

                      </context-param>

       

         <listener>

            <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>

         </listener>

       

         <servlet>

            <servlet-name>InitServlet</servlet-name>

            <servlet-class>org.infinispan.rest.StartupListener</servlet-class>

       

            <!-- Specify your cache configuration file -->

            <init-param>

               <param-name>infinispan.config</param-name>

               <param-value>config-samples/sample.xml</param-value>

            </init-param>

       

            <!-- Managed bean name to look up when the REST server is running an app server -->

            <init-param>

               <param-name>infinispan.cachemanager.bean</param-name>

               <param-value>DefaultCacheManager</param-value>

            </init-param>

            <load-on-startup>1</load-on-startup>

         </servlet>

       

         <servlet>

            <servlet-name>Resteasy</servlet-name>

            <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>

         </servlet>

       

         <servlet-mapping>

            <servlet-name>Resteasy</servlet-name>

            <url-pattern>/rest/*</url-pattern>

         </servlet-mapping>

       

         <welcome-file-list>

            <welcome-file>/index.html</welcome-file>

         </welcome-file-list>

      </web-app> [/code]

       

      Service Class:

      [code] package com.infinispan.demo.services;

       

      import javax.ws.rs.GET;

      import javax.ws.rs.Path;

      import javax.ws.rs.Produces;

      @Path("___defaultcache")

      public class PetService

      {

                      @GET

                      @Produces("text/plain")

                      public String displayMessage()

                      {

                                      System.out.println( "Executing GET on the Rest Server!" ); //save data to database and cache here.

                                      return "Rest Never Sleeps";

                      }

      } [/code]

       

      Environment:  Windows 7, JBoss 5.1, Java 1.6, Eclipse Helios Release 2.

      Thanks!