CKFinderController { @GetMapping("/userfiles/{first}/**") public void attachment(HttpServletRequest request, HttpServletResponse response, @PathVariable("first") String first) throws IOException, ServletException { final String uri = request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE).toString(); final String pattern = request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE).toString(); String rest = matcher.extractPathWithinPattern(pattern, uri); String path = StringUtils.isEmpty(rest) ? first : first + "/" + rest; pathPartial.service(request, response, toPath(path)); }  @GetMapping("/userfiles/{first}/**") void attachment(HttpServletRequest request, HttpServletResponse response,
            @PathVariable("first") String first); @ResponseBody @GetMapping(value = "webjars/ckfinder/2.6.2.1/config", produces = {"application/javascript", "text/javascript"}) String configJs(Locale locale);  }
@Test public void testAttachment() throws Exception { log.info("attachment"); setUp(DEFAULT_PATH_NAME); String pathName = DEFAULT_PATH_NAME; mvc.perform(get("/userfiles/" + pathName)) .andExpect(status().isOk()) .andExpect(content().contentTypeCompatibleWith(MediaType.IMAGE_JPEG)) .andExpect(content().bytes(content)) .andReturn(); mvc.perform(get("/userfiles/" + pathName + "?hash=1")) .andExpect(status().isOk()) .andExpect(content().contentTypeCompatibleWith(MediaType.IMAGE_JPEG)) .andExpect(content().bytes(content)) .andReturn(); for (String uri : new String[]{ "/userfiles/images", "/userfiles/images/", "/userfiles/images/sample.png", "/userfiles/images/folder/sample.png", "/userfiles/images/f1/f2/sample.png" }) { mvc.perform(get(uri)) .andExpect(handler().handlerType(CKFinderController.class)); } tearDown(); }