Announcement Announcement Module
Collapse
No announcement yet.
Spring The request sent by the client was syntactically incorrect Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring The request sent by the client was syntactically incorrect

    Is there something wrong with this URL???

    Code:
    http://localhost:8080/rcmi/provisioner/requests/scoa/newscoa?delCh=606&location=3411&future1=&future2=&department=&product=&interconnect=&carrierBillingAccount=&amount=12312&percentage=12313&active=Active&scoaid=1
    Here is my method in controller

    Code:
    @RequestMapping(value="order/scoa/newscoa", method=RequestMethod.GET)
    	public @ResponseBody JSONResp updateScoa(@ModelAttribute("form") OrderForm form, ModelMap map,
    			@RequestParam String comapny,
    			@RequestParam String  delCh,
    			@RequestParam String  location,
    			@RequestParam String  future1,
    	        @RequestParam String  future2,
    	        @RequestParam String  department,
    	        @RequestParam String  product,
    	        @RequestParam String  interconnect,
    	        @RequestParam String  carrierBillingAccount,
    	        @RequestParam double  amount,
    	        @RequestParam double  percentage,
    	        @RequestParam String  active,
    	        @RequestParam int    scoaid) {
    		
    		
    		JSONResp jr = new JSONResp();
    		return jr;
    	}
    Last edited by romsan; Nov 14th, 2010, 11:45 AM.

  • #2
    Found a typo..... which cost me 3-4 hours........to find out.

    Comment


    • #3
      Could you tell us how you fixed that? I'm having the same problem. Thanks.

      Comment


      • #4
        Code:
        @RequestMapping(value="order/scoa/newscoa", method=RequestMethod.GET)
        	public @ResponseBody JSONResp updateScoa(@ModelAttribute("form") OrderForm form, ModelMap map,
        			@RequestParam String comapny,
        Your request is URL is http://localhost:8080/rcmi/provisioner/requests/scoa/newscoa

        But the mapping is:
        order/scoa/newscoa


        Also, comapny could be a spelling error. Instead, maybe you're expecting company

        Comment


        • #5
          Beware

          also can happen if you define @RequestParam("bla")String bla, but no parameter send by request

          Comment


          • #6
            Old thread, I know, but what's the best way to intercept that error and display something more informational to the end user if the link doesn't have the correct parameters?

            Comment


            • #7
              reply

              Originally posted by LinuxLars View Post
              Old thread, I know, but what's the best way to intercept that error and display something more informational to the end user if the link doesn't have the correct parameters?
              Well I have redefined most of my request mapping with genereal getAttribute or getParameter, or made sure needed parameters are always sent. I think if my memory doesn't betray me you can define something like required=false

              you can then check null or use validator and then redirect to specific url request of your wish.

              Comment


              • #8
                Makes sense for internals. Should have been more specific: if there's an external link, say, on a blog or a business card, that you want to handle, and the blog link or the user doesn't enter all the parameters - the end user gets a pretty ugly error. Wondering how best to handle that.

                Comment


                • #9
                  Handling invalid @RequestParam input

                  Catch TypeMismatchException to deal with bad parameters and MissingServletRequestParameterException to deal with invalid/missing parameters (when required != false). For example,

                  Code:
                      @ExceptionHandler(TypeMismatchException.class)
                      public ModelAndView handleTypeMismatchException(TypeMismatchException ex, HttpServletRequest req, HttpServletResponse resp) {
                          log.debug("Parameter failure: {}", ex.getRootCause().getLocalizedMessage());
                          log.debug("Invalid value is: {}", ex.getValue());
                          log.debug("Required type is: {}", ex.getRequiredType().getSimpleName());
                          // Return something reasonable to the end user.
                          ...
                      }
                  
                      // Throws TypeMismatchException if you call /label/xyz
                      @RequestMapping(value = "/label/{labelId}", method = RequestMethod.GET)
                      public String getLabel(@PathVariable("labelId") int labelId, ModelMap model) {
                          ...
                      }
                  
                      // Throws TypeMismatchException if you call /?userId=xyz or /?labelId=xyz
                      @RequestMapping(value = {"/"}, method = RequestMethod.GET)
                      public String getAll(
                              @RequestParam(value="userId", required=false) Integer userId,
                              @RequestParam(value="labelId", required=false) Integer labelId,
                              ModelMap model) throws ApiException {
                          ...
                      }
                  The thing that I don't like about this is that there doesn't seem to be a way to discern which RequestParam has failed: in the OP's example s/he has 13 parameters. Does anyone know a way to deal with this nicely?

                  Another option is to use @ModelAttribute with an object and interrogate the BindingResult to find the errors. This is nice because you can easily get the incorrect name/value, but at the expense of creating a DTO you might not otherwise need.

                  Code:
                      @RequestMapping(value="search", method= RequestMethod.GET)
                      public String getSearch(@ModelAttribute("form") SourceBundleRequest form, BindingResult result, ModelMap model) {
                          if (result.hasErrors()) {
                              List<String> fieldErrors = new ArrayList<String>();
                              for (FieldError f : result.getFieldErrors()) {
                                  fieldErrors.add(f.getField() + "=" + f.getRejectedValue().toString());
                                  log.debug("BindingFailure: {} = {}", new Object[] { f.getField(), f.getRejectedValue() });
                              }
                              // deal with the invalid input
                          }
                          ...
                      }

                  Comment

                  Working...
                  X