Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST URL mappings not working (Grails 1.3.3, Tomcat6)

Tags:

grails

tomcat

I'm new to Grails (but not to Groovy or web development).

I'm trying to write a web app that accepts REST requests. The problem I have is that despite following - as far as I can tell - the documentation, I still receive 404s when hitting what I believe is the correct URL.

The details are as follows.

The project is brand-new (using Grails 1.3.3 and Intellij IDEA 9.0.3 which supports 1.3.3)

A very simple test controller:

package com.myproject

class TestController {

  def index = { }

  def list = {
    System.out.println("params = " + params);
  }

  def save = {
    System.out.println("params = " + params);
  }

}

and the equally URL mapping, attempting to map all GET requests to the controller's list() method. According to the docs and the Grails in Action book, the "test" controller name in the mapping will be mapped to TestController.

class UrlMappings {

 static mappings = {

        "/test" (controller: "test") {
          action = [ GET: "list", POST: "save" ]
        }

 "/"(view:"/index")
 "500"(view:'/error')
}

}

The application is deployed (exploded) successfully in Tomcat6 in the myapp context (I have a static html in the root which I can display successfully).

Contents of apache-tomcat-6.0.28\webapps\myproject (if it matters) is included below. I stripped the non-essential stuff. The controller class is deployed, same for the UrlMappings class.

All HTTP requests to the following variations

http://localhost:8080/myproject/test/list
http://localhost:8080/myproject/test/list/
http://localhost:8080/myproject/test/
http://localhost:8080/myproject/test

return 404. Either is a weird bug or, more likely, a simple error to which I'm blind.

Your help is appreciated. Thank you!

|   index.html
|   mysql-connector-java-5.1.13-bin.jar
|   
\---WEB-INF
    |   applicationContext.xml
    |   sitemesh.xml
    |   
    +---classes
    |   |   BootStrap$_closure1.class
    |   |   BootStrap$_closure2.class
    |   |   BootStrap.class
    |   |   Config$_run_closure1.class
    |   |   Config$_run_closure1_closure3.class
    |   |   Config$_run_closure1_closure4.class
    |   |   Config$_run_closure1_closure5.class
    |   |   Config$_run_closure2.class
    |   |   Config.class
    |   |   resources$_run_closure1.class
    |   |   resources.class
    |   |   UrlMappings$__clinit__closure1.class
    |   |   UrlMappings$__clinit__closure1_closure2.class
    |   |   UrlMappings.class
    |   |   
    |   +---com
    |   |   \---myproject
    |   |           TestController$_closure1.class
    |   |           TestController$_closure2.class
    |   |           TestController$_closure3.class
    |   |           TestController.class
    |   |               
    |   \---org
    |       \---grails
    |           \---tomcat
    |                   ParentDelegatingClassLoader.class
    |                   SearchFirstURLClassLoader.class
    |                   TomcatLoader.class
    |                   TomcatServer$_preStart_closure3.class
    |                   TomcatServer$_preStart_closure3_closure5.class
    |                   TomcatServer$_start_closure1.class
    |                   TomcatServer$_start_closure1_closure4.class
    |                   TomcatServer$_start_closure2.class
    |                   TomcatServer.class
    |                   TomcatServerFactory.class
    |                   
    +---lib
    |       catalina-ant.jar
    |       grails-tomcat-plugin-1.0.jar
    |       jasper-jdt.jar
    |       mysql-connector-java-5.1.13-bin.jar
    |       tomcat-dbcp.jar
    |       tomcat-jasper.jar
    |       tomcat-juli-adapters.jar
    |       tomcat-juli.jar
    |       
    \---tld
            grails.tld
            spring.tld
like image 632
wishihadabettername Avatar asked Jul 22 '10 03:07

wishihadabettername


1 Answers

it is returning a 404 error because there is no view associated with any of the actions.

there is nothing for the application to render...

change your controller code

class TestController {

  def index = { }

  def list = {
    render("params = " + params);
  }

  def save = {
    render("params = " + params);
  }

}

you will see some output

like image 80
Aaron Saunders Avatar answered Sep 24 '22 05:09

Aaron Saunders