0

I am working on a server where we are using a third party API provider for a particular service. The third party send a image endpoint. Eg. "/media/image/image.jpg". The image is available on the third party base URL.

I need to make the image available on our base url. For that I have a controller.

@RequestMapping(value = "/media/movie/{imageName}", method = RequestMethod.GET)
public void getMovieImage(@PathVariable("imageName") String imageName, HttpServletResponse response) throws IOException {
    String type = imageName.split(".")[imageName.split("\\.").length - 1];
    String imageUrl = getBaseUrl() + imageName;
    BufferedImage image = ImageIO.read(new URL(imageUrl));
    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentType("image/" + type);
    ImageIO.write(image, type, response.getOutputStream());
}

But the problem is *.jpg is defined as a default servlet mapping on web.xml.

<servlet-mapping>
   <servlet-name>default</servlet-name>
   <url-pattern>*.jpg</url-pattern>
</servlet-mapping>`

So the request don't get to the controller and shows 404.

How can I get the request on my controller or is there any alternative way to the problem?

1 Answers1

0

You can add filter's init parameter excludedUrls and check in filter if it isn't in exclsion list. See full example

if(!excludedUrls.contains(path))
Ori Marko
  • 56,308
  • 23
  • 131
  • 233