0

I'm using Spring boot (1.2.2) and I'm trying to send a png file as response. On my IDE (IntelliJ) it works perfect, but when deploying to tomcat I'm getting the following message for url http://example.com/myWebapp/files/17.png

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.

When I open catalina log I see this:

o.s.web.servlet.PageNotFound : No mapping found for HTTP request with URI [/myWebapp/files/18.png] in DispatcherServlet with name 'dispatcherServlet'

MyService.java:

@RestController
public class MyService {

    @RequestMapping(value = "/files/{file_name:.+}", method = RequestMethod.GET)
    public void getFile(@PathVariable("file_name") String fileName, HttpServletResponse response) {
        InputStream is = null;
        try {
            is = session().getFileServer().getInputStream(fileName);
            org.apache.commons.io.IOUtils.copy(is, response.getOutputStream());
            response.setContentType("image/png");
            response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
            response.flushBuffer();
            is.close();
        }
    }
}

Other endpoints also works well on tomcat.
According to what I understand, tomcat is trying to search for that path ('/myWebapp/files/18.png') in disk, instead of forward the request to spring app. I googled this error and figured out I need to add something in my web.xml but cant figure out what exactly.

Shoham
  • 7,014
  • 8
  • 40
  • 40
  • Try to get a response for that URL at all without accessing the file. Get rid of the regex, you don't need it. IIRC correctly, you need to enable content negotiation only for known formats or disable it completely. Otherwise you will get problems with urls ending with `.xyz`. – atamanroman May 11 '15 at 14:42
  • I tried 'files/aaa' and 'files/aaa.xyz' - same error. What is this means? – Shoham May 11 '15 at 15:03
  • I guess that the URL is not mapped at all. Are there any exceptions on startup? – atamanroman May 11 '15 at 15:05
  • No... Just one warning: 'No base packages specified - no classpath scanning will be done' – Shoham May 11 '15 at 15:07
  • 1
    Please check your war. Assuming your Boot application works fine when started directly I bet that the war is not created correctly (e.g compare startup logs). – atamanroman May 11 '15 at 15:11
  • hmmm... That's awkward but It seems you are right. Its not the same version. While on my local startup I see this: 'main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/files/{file_name:.+}]' - I cant see it on server. Thanks! – Shoham May 11 '15 at 15:24

0 Answers0