Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC with Roo - wanted to customize mapping, getting HTTP 400 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC with Roo - wanted to customize mapping, getting HTTP 400

    I Pulled-In all the Controller that Roo generated because i wanted to remap some methods.
    Accessing "http://localhost:8080/twiter-roo/tusers/register" i get on Tomcat "HTTP 400 - The request sent by the client was syntactically incorrect "
    The controller I have:

    Code:
    package twiterroo.controller;
    
    import java.io.UnsupportedEncodingException;
    import java.util.List;
    import javax.servlet.http.HttpServletRequest;
    import javax.validation.Valid;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.roo.addon.web.mvc.controller.scaffold.RooWebScaffold;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.validation.BindingResult;
    import org.springframework.web.bind.annotation.ModelAttribute;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.util.UriUtils;
    import org.springframework.web.util.WebUtils;
    
    import twiterroo.model.Post;
    import twiterroo.model.TUser;
    import twiterroo.service.TUserService;
    
    @RequestMapping(value = "/tusers")
    @Controller
    @RooWebScaffold(path = "tusers", formBackingObject = TUser.class)
    public class UserController {
    
    
    	@RequestMapping(value = "/{id}", produces = "text/html", method = RequestMethod.GET)
        public String show(@PathVariable("id") Long id, Model uiModel) {
            uiModel.addAttribute("object", tUserService.findTUser(id));
            uiModel.addAttribute("itemId", id);
            return "tusers/show";
        }
    	
    	@ModelAttribute(value = "postWall")
    	public List<Post> postWall(@PathVariable("id") Long id) {
    		TUser user = tUserService.findTUser(id);
    		return tUserService.getPostToShowUser(user);
    	}
    
    	@RequestMapping(value = "register")
        public String createForm(Model uiModel) {
            populateEditForm(uiModel, new TUser());
            return "tusers/create";
        }
    
    	void populateEditForm(Model uiModel, TUser TUser_) {
            uiModel.addAttribute("TUser", TUser_);
            uiModel.addAttribute("posts", null);
            uiModel.addAttribute("tusers",null);
        }
    
    	@Autowired
        TUserService tUserService;
    
    	@RequestMapping(method = RequestMethod.POST, produces = "text/html")
        public String create(@Valid TUser TUser_, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
            if (bindingResult.hasErrors()) {
                populateEditForm(uiModel, TUser_);
                return "tusers/create";
            }
            uiModel.asMap().clear();
            tUserService.saveTUser(TUser_);
            return "redirect:/tusers/" + encodeUrlPathSegment(TUser_.getId().toString(), httpServletRequest);
        }
    
    	@RequestMapping(produces = "text/html")
        public String list(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model uiModel) {
            if (page != null || size != null) {
                int sizeNo = size == null ? 10 : size.intValue();
                final int firstResult = page == null ? 0 : (page.intValue() - 1) * sizeNo;
                uiModel.addAttribute("tusers", tUserService.findTUserEntries(firstResult, sizeNo));
                float nrOfPages = (float) tUserService.countAllTUsers() / sizeNo;
                uiModel.addAttribute("maxPages", (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages));
            } else {
                uiModel.addAttribute("tusers", tUserService.findAllTUsers());
            }
            return "tusers/list";
        }
    
    	@RequestMapping(method = RequestMethod.PUT, produces = "text/html")
        public String update(@Valid TUser TUser_, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
            if (bindingResult.hasErrors()) {
                populateEditForm(uiModel, TUser_);
                return "tusers/update";
            }
            uiModel.asMap().clear();
            tUserService.updateTUser(TUser_);
            return "redirect:/tusers/" + encodeUrlPathSegment(TUser_.getId().toString(), httpServletRequest);
        }
    
    	@RequestMapping(value = "/{id}", params = "form", produces = "text/html")
        public String updateForm(@PathVariable("id") Long id, Model uiModel) {
            populateEditForm(uiModel, tUserService.findTUser(id));
            return "tusers/update";
        }
    
    	@RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = "text/html")
        public String delete(@PathVariable("id") Long id, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model uiModel) {
            TUser TUser_ = tUserService.findTUser(id);
            tUserService.deleteTUser(TUser_);
            uiModel.asMap().clear();
            uiModel.addAttribute("page", (page == null) ? "1" : page.toString());
            uiModel.addAttribute("size", (size == null) ? "10" : size.toString());
            return "redirect:/tusers";
        }
    
    	String 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;
        }
    }

  • #2
    Originally posted by adri View Post
    I Pulled-In all the Controller that Roo generated because i wanted to remap some methods.
    Accessing "http://localhost:8080/twiter-roo/tusers/register" i get on Tomcat "HTTP 400 - The request sent by the client was syntactically incorrect "
    Could it be that you misspelled your URL? You wrote "twiter" with only one "r"...

    Comment

    Working...
    X