org.springframework.core.io.AbstractFileResolvingResource Java Examples
The following examples show how to use
org.springframework.core.io.AbstractFileResolvingResource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SwaggerServlet.java From chassis with Apache License 2.0 | 5 votes |
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // figure out the real path String pathInfo = StringUtils.trimToEmpty(req.getPathInfo()); while (pathInfo.endsWith("/")) { pathInfo = StringUtils.removeEnd(pathInfo, "/"); } while (pathInfo.startsWith("/")) { pathInfo = StringUtils.removeStart(pathInfo, "/"); } if (StringUtils.isBlank(pathInfo)) { resp.sendRedirect(rootContextPath + "/" + WELCOME_PAGE); } else { // get the resource AbstractFileResolvingResource resource = (AbstractFileResolvingResource)resourceLoader.getResource(SWAGGER_DIRECTORY + "/" + pathInfo); // send it to the response if (resource.exists()) { StreamUtils.copy(resource.getInputStream(), resp.getOutputStream()); resp.setStatus(HttpServletResponse.SC_OK); resp.flushBuffer(); } else { resp.sendError(HttpServletResponse.SC_NOT_FOUND); } } }