0

I know this has been asked before. However In spite of doing everything as suggested I am facing an issue.

if my path variable has .jpg extension, it is getting truncated. Here are my settings

 <mvc:annotation-driven
        content-negotiation-manager="contentNegotiationManager">
        <mvc:message-converters>
            <bean
                class="org.springframework.http.converter.ByteArrayHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>image/jpeg</value>
                        <value>image/jpg</value>
                        <value>image/png</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>

    </mvc:annotation-driven>

    <bean id="contentNegotiationManager"
        class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
        <property name="favorPathExtension" value="false" />
    </bean>

<bean
        class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
        <property name="messageConverters">
            <util:list>
                <ref bean="jsonMessageConverter" />
            </util:list>
        </property>
    </bean>

    <bean name="exceptionHandlerExceptionResolver"
        class="org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver">
        <property name="order" value="0" />
        <property name="contentNegotiationManager" ref="contentNegotiationManager" />
    </bean>

    <bean name="handlerMapping"
        class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
        <property name="contentNegotiationManager" ref="contentNegotiationManager" />
        <property name="useSuffixPatternMatch" value="false" />
        <property name="useTrailingSlashMatch" value="true"></property>
    </bean>

Controller

@RequestMapping(value = "image/{fileName}", method = RequestMethod.GET, produces = { MediaType.IMAGE_JPEG_VALUE,
            MediaType.IMAGE_GIF_VALUE, MediaType.IMAGE_PNG_VALUE })
    public @ResponseBody
    byte[] getImage(@PathVariable("fileName") final String fileName);

Do I need to do more?

Yogi
  • 1,035
  • 2
  • 13
  • 39
  • 1
    Could it be that you really tried all that is proposed under http://stackoverflow.com/questions/16332092/spring-mvc-pathvariable-with-dot-is-getting-truncated. In my opinion better to list all that you've tried, otherwise you can get a lot of answers that you already attempted – Master Slave Nov 26 '14 at 09:04
  • See [this](http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-uri-templates-regex) for correct syntax – Bond - Java Bond Nov 26 '14 at 09:21
  • I have tried using content negotiation manager. I set favorPathExtension as false, but for some reason it is not working. I am using Spring 3.2.6 – Yogi Nov 26 '14 at 10:10
  • @Yogi could you post one of the controller with this issue ? – Bond - Java Bond Nov 26 '14 at 11:13
  • @JavaBond I have posted. Thanks – Yogi Nov 26 '14 at 11:15

1 Answers1

0

Try this (note the updated value for @RequestMapping)

@RequestMapping(value = "image/{fileName:[a-z]\\.[a-z]}}", method = RequestMethod.GET, produces = { MediaType.IMAGE_JPEG_VALUE,
        MediaType.IMAGE_GIF_VALUE, MediaType.IMAGE_PNG_VALUE })
public @ResponseBody
byte[] getImage(@PathVariable("fileName") final String fileName);

See reference here.

Bond - Java Bond
  • 3,972
  • 6
  • 36
  • 59