Announcement Announcement Module
Collapse
No announcement yet.
Spring 3.1 RequestMappingHandlerMapping - Did not find handler method Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 3.1 RequestMappingHandlerMapping - Did not find handler method

    Hi, I don't what s wrong with my spring controller.
    When it maps a URI variable path from JSP to the controller, Spring 3.1 thrown IOException.

    jsp cpde:

    Code:
    <spring:url value="/category/image/${category.categoryId}" var="url" htmlEscape="true"/>
                                                                                <td><img alt="" src="${url}" /></td>

    Controller code:

    Code:
    @RequestMapping(value="/category/image/{processDefinitionKey}", method = RequestMethod.GET)
    public ResponseEntity<byte[]> downloadReportTemplateContent(
    @PathVariable final String processDefinitionKey)
    throws IOException {
    String categoryId = processDefinitionKey;
    System.out.println("categoryId: "+categoryId);
    List<CategoryImages> ciList = (List<CategoryImages>) categoryImageService.findImagesByCategoryId(Intege r.parseInt(categoryId), 0, categoryImageService.count()) ;
    if (ciList.isEmpty()) {
    System.out.print("cList is Empty.............");
    return null;
    }
    System.out.println(" .......... before ciList.get(0)..............");
    CategoryImages ci = ciList.get(0);
    int imageLength = ci.getImageData().length; 
    try {
    System.out.println(" ..........in Try Block......... ");
    InputStream image = new ByteArrayInputStream(ci.getImageData());
    byte[] imageBytes = IOUtils.toByteArray(image);
    System.out.println(" ..........imageBytes length: "+imageBytes.length);
    
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_JPEG);
    headers.setContentLength(imageBytes.length);
    System.out.println(" ..........headers: "+headers.toString());
    
    return new ResponseEntity<byte[]>(imageBytes, headers, HttpStatus.OK);
    } catch (Exception e) { 
    throw new RuntimeException(e);
    }
    }
    server.log file:
    Code:
    02:31:24,210 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-4) DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'Spring MVC Dispatcher Servlet' processing GET request for [/CategoryClient6-web/category/image/5499]
    02:31:24,211 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-4) DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /category/image/5499
    02:31:24,211 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-5) DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Returning handler method [public org.springframework.http.ResponseEntity<byte[]> ix.houseware.category.web.controller.CategoryImageController.downloadReportTemplateContent(java.lang.String) throws java.io.IOException]
    02:31:24,212 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/resources/images/th.bg.gif]
    02:31:24,212 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Matching patterns for request [/resources/images/th.bg.gif] are [/resources/**]
    02:31:24,212 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - URI Template variables for request [/resources/images/th.bg.gif] are {}
    02:31:24,212 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/resources/images/diplomat.jpg]
    02:31:24,212 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/resources/images/th.bg.gif] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@3ce724f5] and 1 interceptor
    02:31:24,213 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-4) DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Returning handler method [public org.springframework.http.ResponseEntity<byte[]> ix.houseware.category.web.controller.CategoryImageController.downloadReportTemplateContent(java.lang.String) throws java.io.IOException]
    02:31:24,213 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-7) DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/resources/images/springone2gx.jpeg]
    02:31:24,213 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/CategoryClient6-web/resources/images/th.bg.gif] is: -1
    02:31:24,213 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Matching patterns for request [/resources/images/diplomat.jpg] are [/resources/**]
    02:31:24,213 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.resource.ResourceHttpRequestHandler - Trying relative path [images/th.bg.gif] against base location: ServletContext resource [/]
    02:31:24,213 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-5) DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/CategoryClient6-web/category/image/4958] is: -1
    02:31:24,213 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-4) DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/CategoryClient6-web/category/image/5499] is: -1
    02:31:24,214 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-7) DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Matching patterns for request [/resources/images/springone2gx.jpeg] are [/resources/**]
    02:31:24,214 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-7) DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - URI Template variables for request [/resources/images/springone2gx.jpeg] are {}
    02:31:24,214 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-7) DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/resources/images/springone2gx.jpeg] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@3ce724f5] and 1 interceptor
    02:31:24,214 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-7) DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/CategoryClient6-web/resources/images/springone2gx.jpeg] is: -1
    02:31:24,214 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-7) DEBUG: org.springframework.web.servlet.resource.ResourceHttpRequestHandler - Trying relative path [images/springone2gx.jpeg] against base location: ServletContext resource [/]
    02:31:24,215 INFO  [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.resource.ResourceHttpRequestHandler - Found matching resource: ServletContext resource [/images/th.bg.gif]
    Any suggestion is very appreciated.
    Thanks
    Sam
    Last edited by Marten Deinum; May 29th, 2012, 02:44 AM. Reason: Fixed code tags

  • #2
    SamSam007,

    Apparently you are returning an image as a result of your GET request through the handler, right?

    Have you checked your dependencies and dispactcher-servlet.xml file? DO you have all the necessary beans, for example, the ones that participate in your view resolution for images/documents?

    Also, do you really need to include that complicated tag in your JSP page. Because as far as i am concerned, JSTL tags are slightly more complicated beast and does the job well ONLY if you know what you doing, which I believe you do.

    As an initial solution, I would recommend to make your JSP page independent and see if you can resolve the issue by modifying it from handler.

    Also, if it helps you (hopefully) see
    http://stackoverflow.com/questions/7...splaying-in-ie
    http://stackoverflow.com/questions/8...streamresource
    http://forum.springsource.org/showth...r-a-controller

    Comment


    • #3
      Hi Very appreciate for your suggestion.

      Here is my webmvc-config.xml file:

      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
      	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      	xmlns:mvc="http://www.springframework.org/schema/mvc"
      	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schem...ng-mvc-3.0.xsd
      		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
      
      	<!-- Enables controllers mapped with @RequestMapping annotations, formatting annotations @NumberFormat @DateTimeFormat, and JSR 303 style validation -->
      	<mvc:annotation-driven/>
      
      	<mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/web-resources/" />
      	<mvc:default-servlet-handler />
          
      
      	<!-- Map paths directly to view names without controller processing. Use the view-name attribute if necessary: by convention the view name equals the path without the leading slash -->
      	<mvc:view-controller path="/" view-name="intro" />
      	<mvc:view-controller path="/login" />
      	<mvc:view-controller path="/logoutSuccess" />
      
      	<!-- Resolves logical view names returned by Controllers to Tiles; a view name to resolve is treated as the name of a tiles definition -->
      	<bean id="tilesViewResolver" class="org.springframework.js.ajax.AjaxUrlBasedViewResolver">
      		<property name="viewClass" value="org.springframework.webflow.mvc.view.FlowAjaxTilesView"/>
      	</bean>
              
                        <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
                              <property name="basename" value="messages"/>
                          </bean>
      
                          <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">      
                          </bean>
                          
      	<!-- Configures the Tiles layout system -->
      	<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
      		<property name="definitions">
      			<list>
      				<value>/WEB-INF/**/views.xml</value>
      			</list>
      		</property>
      	</bean>
      ImageController.java file:

      Code:
      @RequestMapping(value="/category/image/{processDefinitionKey}", method = RequestMethod.GET)
      public ResponseEntity<byte[]> showImage(
              @PathVariable final String  processDefinitionKey) 
      {
              String categoryId = processDefinitionKey;
              System.out.println("categoryId: "+categoryId);
              List<CategoryImages> ciList = (List<CategoryImages>) categoryImageService.findImagesByCategoryId(Integer.parseInt(categoryId), 0, categoryImageService.count()) ;
                 if (ciList.isEmpty()) {
                     System.out.print("cList is Empty.............");
                     return null;
                 }
                 System.out.println(" .......... before ciList.get(0)..............");
                 CategoryImages ci = ciList.get(0);
                 int imageLength = ci.getImageData().length; 
                 try {
                     System.out.println(" ..........in Try Block......... ");
                      InputStream image = new ByteArrayInputStream(ci.getImageData());
                      byte[] imageBytes = IOUtils.toByteArray(image);
                      System.out.println(" ..........imageBytes length: "+imageBytes.length);
      
                      HttpHeaders headers = new HttpHeaders();
                      headers.setContentType(MediaType.IMAGE_JPEG);
                      headers.setContentLength(imageBytes.length);
                      System.out.println(" ..........headers: "+headers.toString());
      
                      return new ResponseEntity<byte[]>(imageBytes, headers, HttpStatus.OK);
                  } catch (Exception e) { 
                      throw new RuntimeException(e);
                  }
      }
      What should be added to my xml config file?

      Thanks a lot
      Sam
      Last edited by Marten Deinum; May 29th, 2012, 02:43 AM. Reason: Fixed code tags

      Comment


      • #4
        Please use [ code][/code ] tags when posting code (instead of quote tags) that way the code remains readable. (Fixed them for you in the previous posts).

        You use a lot of system.out statements, please use logging that way your statements show up in the logfile. Also the method seems to get resolved correctly so there is probably something wrong with your implementation (no image found or maybe an error on one of you debug statements?).

        Comment


        • #5
          Hi,
          It could be there is a missing configuration in my xml file, but I don't know how to map an URI template variable path from JSP to a method in Controller.

          Any suggestion is very appreciated.
          Thanks
          Samuel

          Comment

          Working...
          X