Announcement Announcement Module
Collapse
No announcement yet.
Web MVC JSON Setup fails or is incomplete Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Web MVC JSON Setup fails or is incomplete

    Hello,

    I'm new to Spring, just bought the Book "Spring in Action" and got a basic overview about the Framework with DI and Aspects. I'm now digging further in to the book but appart from that I want to learn on a practical example. And I think doing it with Roo is the most convenient way to also learn the best practices.

    I want to achieve a RESTful Web MVC Setup with MongoDB as backend. I'm using Spring Roo 1.2.3.RELEASE, Maven 3.0.4 and Java 1.6.0_37. I'm using a 64bit Mac OS X and the command line to achieve the tasks.

    I have executed the following commands to create my roo project:

    Code:
    / Spring Roo 1.2.3.RELEASE [rev 7fd62b6] log opened at 2012-12-30 19:04:59
    hint
    project --topLevelPackage com.eerra.cardkeeperweb
    mongo setup
    entity mongo --class ~.domain.Card --testAutomatically
    field string --fieldName name --sizeMin 2 --notNull --class ~.domain.Card
    field string --fieldName barcode --sizeMin 2 --notNull --class ~.domain.Card
    json all
    web mvc json setup
    web mvc json all --package ~.controller
    web mvc setup
    web mvc all --package ~.controller
    logging setup --level DEBUG
    quit
    // Spring Roo 1.2.3.RELEASE [rev 7fd62b6] log closed at 2012-12-30 19:12:44
    Then I executed the Maven build and start of Jetty from the command line:

    Code:
    mvn clean package
    mvn jetty:run-war

    The Jetty Container is starting and I can reach the default page by opening the URL:
    http://localhost/cardkeeperweb

    But when I click on to the "Create New Card" link on the left hand side I get following message:
    Requested Resource not found

    In the DEBUG Log I see following entry:
    RequestMappingHandlerMapping - Did not find handler method for [/cards]

    So I guess the REST methods are still missing. Does anybody know how to add them?

    Code:
    The DEBUG log output is following:
    2012-12-30 19:19:28,427 [qtp1433183189-66] DEBUG org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'cardkeeperweb' processing GET request for [/cardkeeperweb/cards]
    2012-12-30 19:19:28,427 [qtp1433183189-66] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /cards
    2012-12-30 19:19:28,427 [qtp1433183189-66] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/cards]
    2012-12-30 19:19:28,428 [qtp1433183189-66] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Matching patterns for request [/cards] are [/**]
    2012-12-30 19:19:28,428 [qtp1433183189-66] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - URI Template variables for request [/cards] are {}
    2012-12-30 19:19:28,428 [qtp1433183189-66] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/cards] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler@30e72b6c] and 1 interceptor
    2012-12-30 19:19:28,428 [qtp1433183189-66] DEBUG org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/cardkeeperweb/cards] is: -1
    2012-12-30 19:19:28,428 [qtp1433183189-66] DEBUG org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'cardkeeperweb' processing GET request for [/cardkeeperweb/resourceNotFound]
    2012-12-30 19:19:28,428 [qtp1433183189-66] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /resourceNotFound
    2012-12-30 19:19:28,428 [qtp1433183189-66] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/resourceNotFound]
    2012-12-30 19:19:28,428 [qtp1433183189-66] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/resourceNotFound] to HandlerExecutionChain with handler [org.springframework.web.servlet.mvc.ParameterizableViewController@18d3d889] and 1 interceptor
    2012-12-30 19:19:28,428 [qtp1433183189-66] DEBUG org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/cardkeeperweb/resourceNotFound] is: -1
    2012-12-30 19:19:28,429 [qtp1433183189-66] DEBUG org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.tiles2.TilesView: name 'resourceNotFound'; URL [resourceNotFound]] in DispatcherServlet with name 'cardkeeperweb'
    2012-12-30 19:19:28,429 [qtp1433183189-66] DEBUG org.apache.tiles.impl.BasicTilesContainer - Render request recieved for definition 'resourceNotFound'
    2012-12-30 19:19:28,434 [qtp1433183189-66] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request
    2012-12-30 19:19:28,434 [qtp1433183189-66] DEBUG org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'cardkeeperweb': assuming HandlerAdapter completed request handling
    2012-12-30 19:19:28,434 [qtp1433183189-66] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request
    This indicates that the resource has not been setup successfully. Indeed I don't seem to have GET, POST, PUT, DELETE functions anywhere in my controller or the associated aj files.

    CardController_Roo_Controller.aj
    Code:
    package com.eerra.cardkeeperweb.controller;
    
    import com.eerra.cardkeeperweb.controller.CardController;
    import com.eerra.cardkeeperweb.domain.Card;
    import java.io.UnsupportedEncodingException;
    import javax.servlet.http.HttpServletRequest;
    import org.springframework.ui.Model;
    import org.springframework.web.util.UriUtils;
    import org.springframework.web.util.WebUtils;
    
    privileged aspect CardController_Roo_Controller {
        
        void CardController.populateEditForm(Model uiModel, Card card) {
            uiModel.addAttribute("card", card);
        }
        
        String CardController.encodeUrlPathSegment(String pathSegment, HttpServletRequest httpServletRequest) {
            String enc = httpServletRequest.getCharacterEncoding();
            if (enc == null) {
                enc = WebUtils.DEFAULT_CHARACTER_ENCODING;
            }
            try {
                pathSegment = UriUtils.encodePathSegment(pathSegment, enc);
            } catch (UnsupportedEncodingException uee) {}
            return pathSegment;
        }
        
    }
    CardController.java
    Code:
    package com.eerra.cardkeeperweb.controller;
    
    import com.eerra.cardkeeperweb.domain.Card;
    import org.springframework.roo.addon.web.mvc.controller.json.RooWebJson;
    import org.springframework.roo.addon.web.mvc.controller.scaffold.RooWebScaffold;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @RooWebJson(jsonObject = Card.class)
    @Controller
    @RequestMapping("/cards")
    @RooWebScaffold(path = "cards", formBackingObject = Card.class)
    public class CardController {
    }
    Can somebody tell me what I'm doing wrong or what's missing?

    Thanks for your help,
    Chris

  • #2
    Similar problem and reason

    Hello,

    I was looking for help on similar problem and found your post. I get same behavior - application can be build and deployed, but no resources available. In my case the reason why ROO will not generate the methods is that I didn't want the activeRecord pattern, so I used "--activeRecord false". If I use activeRecord everything comes in place.

    In your case it could be related to MongoDB (just guessing). I use MySQL.

    Kind regards,

    Pavlin


    Originally posted by charms View Post
    Hello,

    I'm new to Spring, just bought the Book "Spring in Action" and got a basic overview about the Framework with DI and Aspects. I'm now digging further in to the book but appart from that I want to learn on a practical example. And I think doing it with Roo is the most convenient way to also learn the best practices.

    I want to achieve a RESTful Web MVC Setup with MongoDB as backend. I'm using Spring Roo 1.2.3.RELEASE, Maven 3.0.4 and Java 1.6.0_37. I'm using a 64bit Mac OS X and the command line to achieve the tasks.

    I have executed the following commands to create my roo project:

    Code:
    / Spring Roo 1.2.3.RELEASE [rev 7fd62b6] log opened at 2012-12-30 19:04:59
    hint
    project --topLevelPackage com.eerra.cardkeeperweb
    mongo setup
    entity mongo --class ~.domain.Card --testAutomatically
    field string --fieldName name --sizeMin 2 --notNull --class ~.domain.Card
    field string --fieldName barcode --sizeMin 2 --notNull --class ~.domain.Card
    json all
    web mvc json setup
    web mvc json all --package ~.controller
    web mvc setup
    web mvc all --package ~.controller
    logging setup --level DEBUG
    quit
    // Spring Roo 1.2.3.RELEASE [rev 7fd62b6] log closed at 2012-12-30 19:12:44
    Then I executed the Maven build and start of Jetty from the command line:

    Code:
    mvn clean package
    mvn jetty:run-war

    The Jetty Container is starting and I can reach the default page by opening the URL:
    http://localhost/cardkeeperweb

    But when I click on to the "Create New Card" link on the left hand side I get following message:
    Requested Resource not found

    In the DEBUG Log I see following entry:
    RequestMappingHandlerMapping - Did not find handler method for [/cards]

    So I guess the REST methods are still missing. Does anybody know how to add them?

    Code:
    The DEBUG log output is following:
    2012-12-30 19:19:28,427 [qtp1433183189-66] DEBUG org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'cardkeeperweb' processing GET request for [/cardkeeperweb/cards]
    2012-12-30 19:19:28,427 [qtp1433183189-66] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /cards
    2012-12-30 19:19:28,427 [qtp1433183189-66] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/cards]
    2012-12-30 19:19:28,428 [qtp1433183189-66] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Matching patterns for request [/cards] are [/**]
    2012-12-30 19:19:28,428 [qtp1433183189-66] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - URI Template variables for request [/cards] are {}
    2012-12-30 19:19:28,428 [qtp1433183189-66] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/cards] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler@30e72b6c] and 1 interceptor
    2012-12-30 19:19:28,428 [qtp1433183189-66] DEBUG org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/cardkeeperweb/cards] is: -1
    2012-12-30 19:19:28,428 [qtp1433183189-66] DEBUG org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'cardkeeperweb' processing GET request for [/cardkeeperweb/resourceNotFound]
    2012-12-30 19:19:28,428 [qtp1433183189-66] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /resourceNotFound
    2012-12-30 19:19:28,428 [qtp1433183189-66] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/resourceNotFound]
    2012-12-30 19:19:28,428 [qtp1433183189-66] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/resourceNotFound] to HandlerExecutionChain with handler [org.springframework.web.servlet.mvc.ParameterizableViewController@18d3d889] and 1 interceptor
    2012-12-30 19:19:28,428 [qtp1433183189-66] DEBUG org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/cardkeeperweb/resourceNotFound] is: -1
    2012-12-30 19:19:28,429 [qtp1433183189-66] DEBUG org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.tiles2.TilesView: name 'resourceNotFound'; URL [resourceNotFound]] in DispatcherServlet with name 'cardkeeperweb'
    2012-12-30 19:19:28,429 [qtp1433183189-66] DEBUG org.apache.tiles.impl.BasicTilesContainer - Render request recieved for definition 'resourceNotFound'
    2012-12-30 19:19:28,434 [qtp1433183189-66] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request
    2012-12-30 19:19:28,434 [qtp1433183189-66] DEBUG org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'cardkeeperweb': assuming HandlerAdapter completed request handling
    2012-12-30 19:19:28,434 [qtp1433183189-66] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request
    This indicates that the resource has not been setup successfully. Indeed I don't seem to have GET, POST, PUT, DELETE functions anywhere in my controller or the associated aj files.

    CardController_Roo_Controller.aj
    Code:
    package com.eerra.cardkeeperweb.controller;
    
    import com.eerra.cardkeeperweb.controller.CardController;
    import com.eerra.cardkeeperweb.domain.Card;
    import java.io.UnsupportedEncodingException;
    import javax.servlet.http.HttpServletRequest;
    import org.springframework.ui.Model;
    import org.springframework.web.util.UriUtils;
    import org.springframework.web.util.WebUtils;
    
    privileged aspect CardController_Roo_Controller {
        
        void CardController.populateEditForm(Model uiModel, Card card) {
            uiModel.addAttribute("card", card);
        }
        
        String CardController.encodeUrlPathSegment(String pathSegment, HttpServletRequest httpServletRequest) {
            String enc = httpServletRequest.getCharacterEncoding();
            if (enc == null) {
                enc = WebUtils.DEFAULT_CHARACTER_ENCODING;
            }
            try {
                pathSegment = UriUtils.encodePathSegment(pathSegment, enc);
            } catch (UnsupportedEncodingException uee) {}
            return pathSegment;
        }
        
    }
    CardController.java
    Code:
    package com.eerra.cardkeeperweb.controller;
    
    import com.eerra.cardkeeperweb.domain.Card;
    import org.springframework.roo.addon.web.mvc.controller.json.RooWebJson;
    import org.springframework.roo.addon.web.mvc.controller.scaffold.RooWebScaffold;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @RooWebJson(jsonObject = Card.class)
    @Controller
    @RequestMapping("/cards")
    @RooWebScaffold(path = "cards", formBackingObject = Card.class)
    public class CardController {
    }
    Can somebody tell me what I'm doing wrong or what's missing?

    Thanks for your help,
    Chris

    Comment

    Working...
    X