List of usage examples for org.springframework.web.servlet HandlerMapping PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
String PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
To view the source code for org.springframework.web.servlet HandlerMapping PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE.
Click Source Link
From source file:org.avidj.zuul.rs.Zuul.java
private static List<String> getLockPath(HttpServletRequest request, String session) { String matchedPath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); final int prefixLength = "/s/".length() + session.length(); String lockPath = matchedPath.substring(prefixLength); if (lockPath.startsWith("/")) { lockPath = lockPath.substring(1); }/*www. j av a2s .com*/ return toLockPath(lockPath); }
From source file:org.springjutsu.validation.util.RequestUtils.java
public static String getPathWithinHandlerMapping() { HttpServletRequest request = getCurrentRequest(); String pathWithinHandlerMapping = request == null ? null : (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); return removeLeadingAndTrailingSlashes(pathWithinHandlerMapping); }
From source file:com.netflix.genie.web.resources.handlers.GenieResourceHttpRequestHandlerUnitTests.java
/** * Make sure if the resource isn't a directory it's sent to super. * <p>/*from w w w . ja va 2 s .c o m*/ * Note: This doesn't actually test returning a file as we leverage Spring's implementation * which we assume is working. * * @throws ServletException On any error * @throws IOException On any error */ @Test public void canHandleRequestForFile() throws ServletException, IOException { final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); final HttpServletResponse response = Mockito.mock(HttpServletResponse.class); final String path = UUID.randomUUID().toString(); Mockito.when(request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).thenReturn(path); final Resource resource = Mockito.mock(Resource.class); Mockito.when(this.location.createRelative(Mockito.eq(path))).thenReturn(resource); Mockito.when(resource.exists()).thenReturn(true); final File file = Mockito.mock(File.class); Mockito.when(resource.getFile()).thenReturn(file); Mockito.when(file.isDirectory()).thenReturn(false); this.handler.handleRequest(request, response); Mockito.verify(response, Mockito.times(1)).sendError(HttpStatus.NOT_FOUND.value()); }
From source file:org.wallride.web.controller.guest.article.ArticleIndexController.java
private String extractPathFromPattern(final HttpServletRequest request) { String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); AntPathMatcher apm = new AntPathMatcher(); String finalPath = apm.extractPathWithinPattern(bestMatchPattern, path); return finalPath; }
From source file:com.tasktop.c2c.server.internal.wiki.server.WikiServiceController.java
@Section(value = "Wiki Pages", order = 0) @Title("Retrieve Rendered Page By Path") @Documentation("Retrieve a rendered page by its path. The returned page content is rendered in HTML format.") @RequestMapping(value = "/" + RENDERED_PAGE_PATH + "**", method = RequestMethod.GET) public Page retrieveRenderedPageByPath(HttpServletRequest request) throws EntityNotFoundException { String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); path = path.startsWith(RENDERED_PAGE_PATH) ? path.substring(RENDERED_PAGE_PATH.length()) : path; return retrieveRenderedPageByPath(path); }
From source file:com.netflix.genie.web.resources.handlers.GenieResourceHttpRequestHandlerUnitTests.java
/** * Make sure if the resource is a directory as HTML it's handled properly. * * @throws Exception On any error/* www. ja v a2s .c o m*/ */ @Test public void canHandleRequestForDirectoryHtml() throws Exception { final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); final HttpServletResponse response = Mockito.mock(HttpServletResponse.class); final String path = UUID.randomUUID().toString(); Mockito.when(request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).thenReturn(path); Mockito.when(request.getHeader(HttpHeaders.ACCEPT)).thenReturn(MediaType.TEXT_HTML_VALUE); final String forwardedUrl = UUID.randomUUID().toString(); Mockito.when(request.getHeader(JobConstants.GENIE_FORWARDED_FROM_HEADER)).thenReturn(forwardedUrl); final Resource resource = Mockito.mock(Resource.class); Mockito.when(this.location.createRelative(Mockito.eq(path))).thenReturn(resource); Mockito.when(resource.exists()).thenReturn(true); final File file = Mockito.mock(File.class); Mockito.when(resource.getFile()).thenReturn(file); Mockito.when(file.isDirectory()).thenReturn(true); final String html = UUID.randomUUID().toString(); Mockito.when(this.directoryWriter.toHtml(Mockito.eq(file), Mockito.eq(forwardedUrl), Mockito.eq(false))) .thenReturn(html); final ServletOutputStream os = Mockito.mock(ServletOutputStream.class); Mockito.when(response.getOutputStream()).thenReturn(os); this.handler.handleRequest(request, response); Mockito.verify(response, Mockito.times(1)).setContentType(MediaType.TEXT_HTML_VALUE); Mockito.verify(response, Mockito.times(1)).getOutputStream(); Mockito.verify(this.directoryWriter, Mockito.times(1)).toHtml(Mockito.eq(file), Mockito.eq(forwardedUrl), Mockito.eq(false)); Mockito.verify(os, Mockito.times(1)).write(html.getBytes(Charset.forName("UTF-8"))); }
From source file:com.tasktop.c2c.server.internal.wiki.server.WikiServiceController.java
@Section(value = "Wiki Pages", order = 0) @Title("Retrieve Page outline By Path") @Documentation("Retrieve an outline by its path.") @RequestMapping(value = "/" + OUTLINE_PATH + "**", method = RequestMethod.GET) public PageOutline retrieveOutlineByPath(HttpServletRequest request) throws EntityNotFoundException { String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); path = path.startsWith(OUTLINE_PATH) ? path.substring(OUTLINE_PATH.length()) : path; return retrieveOutlineByPath(path); }
From source file:com.civilizer.web.handler.ResourceHttpRequestHandler.java
protected Resource getResource(HttpServletRequest request) { String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); if (path == null) { throw new IllegalStateException("Required request attribute '" + HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE + "' is not set"); }/* w w w. jav a2s. co m*/ // // For resources having UTF-8 encoded path; // path = FsUtil.toUtf8Path(path); if (!StringUtils.hasText(path) || isInvalidPath(path)) { if (logger.isDebugEnabled()) { logger.debug("Ignoring invalid resource path [" + path + "]"); } return null; } for (Resource location : this.locations) { try { if (logger.isDebugEnabled()) { logger.debug("Trying relative path [" + path + "] against base location: " + location); } Resource resource = location.createRelative(path); if (resource.exists() && resource.isReadable()) { if (logger.isDebugEnabled()) { logger.debug("Found matching resource: " + resource); } return resource; } else if (logger.isTraceEnabled()) { logger.trace("Relative resource doesn't exist or isn't readable: " + resource); } } catch (IOException ex) { logger.debug("Failed to create relative resource - trying next resource location", ex); } } return null; }
From source file:de.tobiasbruns.content.storage.ContentController.java
private String getPath(HttpServletRequest req) { return req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE).toString(); }
From source file:es.logongas.ix3.web.util.ControllerHelper.java
public EndPoint getEndPoint(HttpServletRequest httpServletRequest) { String path = (String) httpServletRequest .getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); String method = httpServletRequest.getMethod(); EndPoint endPoint = EndPoint.getBestEndPoint( EndPoint.getMatchEndPoint(endPointsFactory.getEndPoints(), path, method), path, method); return endPoint; }