Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: How to map Template Variable URI to Spring Controller.

  1. #1
    Join Date
    Jul 2008
    Posts
    182

    Default How to map Template Variable URI to Spring Controller.

    Hi I am using Template Variable URI with Spring MVC 3.1 in JBOSS 7, I don't see my mapping from a Tempalte Variable URI mapped to a controller.
    Here is its jsp code:

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

    Code:
    @RequestMapping(value="/category/image/{processDefinitionKey}", method = RequestMethod.GET)
    public ResponseEntity<byte[]> showImage(
            @PathVariable final String  processDefinitionKey) 
    {
            String categoryId = processDefinitionKey;
            logger.debug("showImage() - categoryId: "+categoryId);
            ....
    }
    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>
    Any suggestion would be very appreciated.
    Thanks
    sam
    Last edited by Marten Deinum; Jun 11th, 2012 at 05:42 AM. Reason: Fixed code tags...

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Crank up your loglevel to debug (or trace) and see what is happening to your mappings and incoming requests.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Jul 2008
    Posts
    182

    Default

    Hi Marten,
    Thank you for your suggestion.
    I am using Jboss 7, the server.log file shown relevent debug info here:

    01:35:25,836 INFO [stdout] (http--192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'Spring MVC Dispatcher Servlet' processing GET request for [/CategoryClient6-web/category/image/4302]
    01:35:25,836 INFO [stdout] (http--192.168.1.20-8080-2) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - URI Template variables for request [/resources/images/springone2gx.jpeg] are {}
    01:35:25,836 INFO [stdout] (http--192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - Matching patterns for request [/category/image/4958] are [/**]
    01:35:25,836 INFO [stdout] (http--192.168.1.20-8080-4) DEBUG: org.springframework.web.servlet.resource.ResourceH ttpRequestHandler - Trying relative path [images/th.bg.gif] against base location: ServletContext resource [/]
    01:35:25,836 INFO [stdout] (http--192.168.1.20-8080-5) DEBUG: org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Did not find handler method for [/category/image/5499]
    01:35:25,836 INFO [stdout] (http--192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - URI Template variables for request [/category/image/4958] are {}
    01:35:25,836 INFO [stdout] (http--192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Looking up handler method for path /category/image/4302
    01:35:25,836 INFO [stdout] (http--192.168.1.20-8080-2) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - Mapping [/resources/images/springone2gx.jpeg] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceH ttpRequestHandler@55ac539f] and 1 interceptor
    01:35:25,837 INFO [stdout] (http--192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - Mapping [/category/image/4958] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultSe rvletHttpRequestHandler@1550a3c] and 1 interceptor
    01:35:25,837 INFO [stdout] (http--192.168.1.20-8080-5) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - Matching patterns for request [/category/image/5499] are [/**]
    01:35:25,837 INFO [stdout] (http--192.168.1.20-8080-4) DEBUG: org.springframework.web.servlet.resource.ResourceH ttpRequestHandler - Found matching resource: ServletContext resource [/images/th.bg.gif]
    01:35:25,837 INFO [stdout] (http--192.168.1.20-8080-5) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - URI Template variables for request [/category/image/5499] are {}
    01:35:25,837 INFO [stdout] (http--192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/CategoryClient6-web/category/image/4958] is: -1
    01:35:25,837 INFO [stdout] (http--192.168.1.20-8080-2) DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/CategoryClient6-web/resources/images/springone2gx.jpeg] is: -1
    01:35:25,837 INFO [stdout] (http--192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'Spring MVC Dispatcher Servlet': assuming HandlerAdapter completed request handling
    01:35:25,837 INFO [stdout] (http--192.168.1.20-8080-6) DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'Spring MVC Dispatcher Servlet' processing GET request for [/CategoryClient6-web/category/image/5955]
    01:35:25,838 INFO [stdout] (http--192.168.1.20-8080-6) DEBUG: org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Looking up handler method for path /category/image/5955
    01:35:25,838 INFO [stdout] (http--192.168.1.20-8080-5) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - Mapping [/category/image/5499] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultSe rvletHttpRequestHandler@1550a3c] and 1 interceptor
    01:35:25,838 INFO [stdout] (http--192.168.1.20-8080-4) DEBUG: org.springframework.web.servlet.resource.ResourceH ttpRequestHandler - Determined media type 'image/gif' for ServletContext resource [/images/th.bg.gif]
    01:35:25,838 INFO [stdout] (http--192.168.1.20-8080-5) DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/CategoryClient6-web/category/image/5499] is: -1
    01:35:25,838 INFO [stdout] (http--192.168.1.20-8080-5) DEBUG: org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'Spring MVC Dispatcher Servlet': assuming HandlerAdapter completed request handling
    The mapping /category/image/5499 does not map to the controller, here is the controller:

    @Controller
    @RequestMapping(value="/category/image/{processDefinitionKey}", method = RequestMethod.GET)
    public class CategoryImageController {

    private static final Logger logger = Logger.getLogger(CategoryImageController.class);

    private CategoryImageService categoryImageService;

    @Autowired
    public CategoryImageController(CategoryImageService categoryImageService) {
    this.categoryImageService = categoryImageService;
    }


    public ResponseEntity<byte[]> showImage(@PathVariable final String processDefinitionKey)
    {
    String categoryId = processDefinitionKey;
    logger.debug("showImage() - categoryId: "+categoryId);
    List<CategoryImages> ciList = (List<CategoryImages>) categoryImageService.findImagesByCategoryId(Intege r.parseInt(categoryId), 0, categoryImageService.count()) ;
    if (ciList.isEmpty()) {
    logger.debug("cList is Empty.............");
    return null;
    }
    logger.debug(" .......... before ciList.get(0)..............");
    CategoryImages ci = ciList.get(0);
    int imageLength = ci.getImageData().length;
    try {
    logger.debug(" ..........in Try Block......... ");
    InputStream image = new ByteArrayInputStream(ci.getImageData());
    byte[] imageBytes = IOUtils.toByteArray(image);
    logger.debug(" ..........imageBytes length: "+imageBytes.length);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_JPEG);
    headers.setContentLength(imageBytes.length);
    logger.debug(" ..........headers: "+headers.toString());

    return new ResponseEntity<byte[]>(imageBytes, headers, HttpStatus.OK);
    } catch (Exception e) {
    throw new RuntimeException(e);
    }
    }
    I think I have a special configration missing in my xml file, but I don't know what is missing there.
    Can you please suggest what should I create in the xml file for mapping url template variable path to a controller?

    Thanks
    Sam

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Your method should be annotated with @RequestMapping to mark it as a request handling method, currently there is nothing on there. which doesn't register your controller.

    Check the startup logs and you should see the mappings pass by.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Jul 2008
    Posts
    182

    Default

    Hi here is the corresponding message in log file:

    01:35:25,836 INFO [stdout] (http--192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'Spring MVC Dispatcher Servlet' processing GET request for [/CategoryClient6-web/category/image/4302]
    01:35:25,836 INFO [stdout] (http--192.168.1.20-8080-2) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - URI Template variables for request [/resources/images/springone2gx.jpeg] are {}
    01:35:25,836 INFO [stdout] (http--192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - Matching patterns for request [/category/image/4958] are [/**]
    01:35:25,836 INFO [stdout] (http--192.168.1.20-8080-4) DEBUG: org.springframework.web.servlet.resource.ResourceH ttpRequestHandler - Trying relative path [images/th.bg.gif] against base location: ServletContext resource [/]
    01:35:25,836 INFO [stdout] (http--192.168.1.20-8080-5) DEBUG: org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Did not find handler method for [/category/image/5499]
    01:35:25,836 INFO [stdout] (http--192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - URI Template variables for request [/category/image/4958] are {}
    01:35:25,836 INFO [stdout] (http--192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Looking up handler method for path /category/image/4302
    01:35:25,836 INFO [stdout] (http--192.168.1.20-8080-2) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - Mapping [/resources/images/springone2gx.jpeg] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceH ttpRequestHandler@55ac539f] and 1 interceptor
    01:35:25,837 INFO [stdout] (http--192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - Mapping [/category/image/4958] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultSe rvletHttpRequestHandler@1550a3c] and 1 interceptor
    01:35:25,837 INFO [stdout] (http--192.168.1.20-8080-5) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - Matching patterns for request [/category/image/5499] are [/**]
    01:35:25,837 INFO [stdout] (http--192.168.1.20-8080-4) DEBUG: org.springframework.web.servlet.resource.ResourceH ttpRequestHandler - Found matching resource: ServletContext resource [/images/th.bg.gif]
    01:35:25,837 INFO [stdout] (http--192.168.1.20-8080-5) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - URI Template variables for request [/category/image/5499] are {}
    01:35:25,837 INFO [stdout] (http--192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/CategoryClient6-web/category/image/4958] is: -1
    01:35:25,837 INFO [stdout] (http--192.168.1.20-8080-2) DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/CategoryClient6-web/resources/images/springone2gx.jpeg] is: -1
    01:35:25,837 INFO [stdout] (http--192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'Spring MVC Dispatcher Servlet': assuming HandlerAdapter completed request handling
    01:35:25,837 INFO [stdout] (http--192.168.1.20-8080-6) DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'Spring MVC Dispatcher Servlet' processing GET request for [/CategoryClient6-web/category/image/5955]
    01:35:25,838 INFO [stdout] (http--192.168.1.20-8080-6) DEBUG: org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Looking up handler method for path /category/image/5955
    01:35:25,838 INFO [stdout] (http--192.168.1.20-8080-5) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - Mapping [/category/image/5499] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultSe rvletHttpRequestHandler@1550a3c] and 1 interceptor
    01:35:25,838 INFO [stdout] (http--192.168.1.20-8080-4) DEBUG: org.springframework.web.servlet.resource.ResourceH ttpRequestHandler - Determined media type 'image/gif' for ServletContext resource [/images/th.bg.gif]
    01:35:25,838 INFO [stdout] (http--192.168.1.20-8080-5) DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/CategoryClient6-web/category/image/5499] is: -1
    01:35:25,838 INFO [stdout] (http--192.168.1.20-8080-5) DEBUG: org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'Spring MVC Dispatcher Servlet': assuming HandlerAdapter completed request handling
    Thanks
    Sam

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Hi here is the corresponding message in log file:
    No it isn't... You want the STARTUP log... Not the request processing log.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  7. #7
    Join Date
    Jul 2008
    Posts
    182

    Default

    Hi, here is the start up log when I deployed its .ear file to jboss server:

    02:30:38,832 INFO [stdout] (MSC service thread 1-6) INFO : org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Mapped "{[/category/image/{processDefinitionKey}/category/image/{processDefinitionKey}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<byte[]> ix.houseware.category.web.controller.CategoryImage Controller.showImage(java.lang.String)
    Source for CategoryImageController.java file:
    @Controller
    @RequestMapping(value="/category/image/{processDefinitionKey}", method = RequestMethod.GET)
    public class CategoryImageController {

    private static final Logger logger = Logger.getLogger(CategoryImageController.class);

    private CategoryImageService categoryImageService;

    @Autowired
    public CategoryImageController(CategoryImageService categoryImageService) {
    this.categoryImageService = categoryImageService;
    }


    @RequestMapping(value="/category/image/{processDefinitionKey}", method = RequestMethod.GET)
    public ResponseEntity<byte[]> showImage(@PathVariable final String processDefinitionKey)
    {
    String categoryId = processDefinitionKey;
    logger.debug("showImage() - categoryId: "+categoryId);
    List<CategoryImages> ciList = (List<CategoryImages>) categoryImageService.findImagesByCategoryId(Intege r.parseInt(categoryId), 0, categoryImageService.count()) ;
    if (ciList.isEmpty()) {
    logger.debug("cList is Empty.............");
    return null;
    }
    logger.debug(" .......... before ciList.get(0)..............");
    CategoryImages ci = ciList.get(0);
    int imageLength = ci.getImageData().length;
    try {
    logger.debug(" ..........in Try Block......... ");
    InputStream image = new ByteArrayInputStream(ci.getImageData());
    byte[] imageBytes = IOUtils.toByteArray(image);
    logger.debug(" ..........imageBytes length: "+imageBytes.length);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_JPEG);
    headers.setContentLength(imageBytes.length);
    logger.debug(" ..........headers: "+headers.toString());

    return new ResponseEntity<byte[]>(imageBytes, headers, HttpStatus.OK);
    } catch (Exception e) {
    throw new RuntimeException(e);
    }
    }
    Thanks a lot
    Sam

  8. #8
    Join Date
    Jul 2008
    Posts
    182

    Default

    Here is the request log:

    02:34:17,228 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'Spring MVC Dispatcher Servlet' processing GET request for [/CategoryClient6-web/category/image/5499]
    02:34:17,228 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-2) DEBUG: org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Looking up handler method for path /resources/images/springone2gx.jpeg
    02:34:17,228 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Looking up handler method for path /category/image/5499
    02:34:17,228 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-5) DEBUG: org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Looking up handler method for path /category/image/4958
    02:34:17,229 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - Matching patterns for request [/resources/images/diplomat.jpg] are [/resources/**]
    02:34:17,229 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - URI Template variables for request [/resources/images/diplomat.jpg] are {}
    02:34:17,229 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - Mapping [/resources/images/diplomat.jpg] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceH ttpRequestHandler@41225841] and 1 interceptor
    02:34:17,229 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/CategoryClient6-web/resources/images/diplomat.jpg] is: -1
    02:34:17,229 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.resource.ResourceH ttpRequestHandler - Trying relative path [images/diplomat.jpg] against base location: ServletContext resource [/]
    02:34:17,229 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-6) DEBUG: org.springframework.web.servlet.resource.ResourceH ttpRequestHandler - Found matching resource: ServletContext resource [/images/th.bg.gif]
    02:34:17,229 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.resource.ResourceH ttpRequestHandler - Found matching resource: ServletContext resource [/images/diplomat.jpg]
    02:34:17,229 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-1) DEBUG: org.springframework.web.servlet.resource.ResourceH ttpRequestHandler - Determined media type 'image/jpeg' for ServletContext resource [/images/diplomat.jpg]
    02:34:17,230 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Did not find handler method for [/category/image/5499]
    02:34:17,230 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-4) DEBUG: org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Did not find handler method for [/category/image/4302]
    02:34:17,230 INFO [stdout] (http-portal.ixsystems.com.au-192.168.1.20-8080-3) DEBUG: org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - Matching patterns for request [/category/image/5499] are [/**]

  9. #9
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Your mapping of the controller is wrong.... Mappings on the class and method level are merged together... Your method maps to /category/image/{processDefinitionKey}/category/image/{processDefinitionKey} (combined from class and method level). Remove the method level @RequestMapping annotation.

    This is also clearly stated in the startup log.

    Code:
    02:30:38,832 INFO [stdout] (MSC service thread 1-6) INFO : org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Mapped "{[/category/image/{processDefinitionKey}/category/image/{processDefinitionKey}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<byte[]> ix.houseware.category.web.controller.CategoryImage Controller.showImage(java.lang.String)
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  10. #10
    Join Date
    Jul 2008
    Posts
    182

    Default

    Thank you for your suggestion.
    I have changed it to the following implementation for CategoryImageController.java class:

    @Controller
    @RequestMapping("/category/image")
    public class CategoryImageController {

    private static final Logger logger = Logger.getLogger(CategoryImageController.class);

    private CategoryImageService categoryImageService;

    @Autowired
    public CategoryImageController(CategoryImageService categoryImageService) {
    this.categoryImageService = categoryImageService;
    }


    // @RequestMapping(value = "/reportTemplate/{id}/content", method = RequestMethod.GET)
    @RequestMapping(value="{processDefinitionKey}", method = RequestMethod.GET)
    public ResponseEntity<byte[]> showImage(@PathVariable String processDefinitionKey, Model model) throws Exception
    {
    String categoryId = processDefinitionKey;
    logger.debug("showImage() - categoryId: "+categoryId);
    List<CategoryImages> ciList = (List<CategoryImages>) categoryImageService.findImagesByCategoryId(Intege r.parseInt(categoryId), 0, categoryImageService.count()) ;
    if (ciList.isEmpty()) {
    logger.debug("cList is Empty.............");
    return null;
    }
    logger.debug(" .......... before ciList.get(0)..............");
    CategoryImages ci = ciList.get(0);
    int imageLength = ci.getImageData().length;
    try {
    logger.debug(" ..........in Try Block......... ");
    InputStream image = new ByteArrayInputStream(ci.getImageData());
    byte[] imageBytes = IOUtils.toByteArray(image);
    logger.debug(" ..........imageBytes length: "+imageBytes.length);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_JPEG);
    headers.setContentLength(imageBytes.length);
    logger.debug(" ..........headers: "+headers.toString());

    return new ResponseEntity<byte[]>(imageBytes, headers, HttpStatus.OK);
    } catch (Exception e) {
    throw new RuntimeException(e);
    }
    }
    Spring still failed to map it to the controller. Here with its log message:

    09:50:46,997 INFO [stdout] (MSC service thread 1-5) INFO : org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerMapping - Mapped "{[/category/image/{processDefinitionKey}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<byte[]> ix.houseware.category.web.controller.CategoryImage Controller.showImage(java.lang.String,org.springfr amework.ui.Model) throws java.lang.Exception

    Thanks
    Sam

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •