List of usage examples for org.springframework.web.servlet HandlerMapping BEST_MATCHING_PATTERN_ATTRIBUTE
String BEST_MATCHING_PATTERN_ATTRIBUTE
To view the source code for org.springframework.web.servlet HandlerMapping BEST_MATCHING_PATTERN_ATTRIBUTE.
Click Source Link
From source file:com.netflix.genie.web.controllers.ControllerUtils.java
/** * Get the remaining path from a given request. e.g. if the request went to a method with the matching pattern of * /api/v3/jobs/{id}/output/** and the request was /api/v3/jobs/{id}/output/blah.txt the return value of this * method would be blah.txt.//w w w.j ava2 s .c o m * * @param request The http servlet request. * @return The remaining path */ public static String getRemainingPath(final HttpServletRequest request) { String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); if (path != null) { final String bestMatchPattern = (String) request .getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); log.debug("bestMatchPattern = {}", bestMatchPattern); path = new AntPathMatcher().extractPathWithinPattern(bestMatchPattern, path); } path = path == null ? EMPTY_STRING : path; log.debug("Remaining path = {}", path); return path; }
From source file:fi.hsl.parkandride.front.RequestLoggingInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { Optional.ofNullable((String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE)) .filter(s -> s.startsWith(UrlSchema.API)).ifPresent(urlPattern -> { final String source = request.getHeader(SOURCE_HEADER); logger.trace("Intercepted API call: <{}> for source <{}>", urlPattern, source); batchingRequestLogService.increment(new RequestLogKey(urlPattern, source, DateTime.now())); });/* ww w.jav a 2s.c o m*/ return super.preHandle(request, response, handler); }
From source file:com.netflix.genie.web.controllers.ControllerUtilsUnitTests.java
/** * Test the getRemainingPath method.//ww w . ja v a 2 s . c o m */ @Test public void canGetRemainingPath() { final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); Mockito.when(request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).thenReturn(null); Assert.assertNull(ControllerUtils.getRemainingPath(request)); Mockito.when(request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)) .thenReturn("/api/v3/jobs/1234/output/genie/log.out"); Mockito.when(request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE)) .thenReturn("/api/v3/jobs/{id}/output/**"); Assert.assertThat(ControllerUtils.getRemainingPath(request), Matchers.is("genie/log.out")); Mockito.when(request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)) .thenReturn("/api/v3/jobs/1234/output"); Mockito.when(request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE)) .thenReturn("/api/v3/jobs/{id}/output"); Assert.assertThat(ControllerUtils.getRemainingPath(request), Matchers.is("")); Mockito.when(request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)) .thenReturn("/api/v3/jobs/1234/output/"); Mockito.when(request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE)) .thenReturn("/api/v3/jobs/{id}/output/"); Assert.assertThat(ControllerUtils.getRemainingPath(request), Matchers.is("")); Mockito.when(request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)) .thenReturn("/api/v3/jobs/1234/output/stdout"); Mockito.when(request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE)) .thenReturn("/api/v3/jobs/{id}/output/**"); Assert.assertThat(ControllerUtils.getRemainingPath(request), Matchers.is("stdout")); }
From source file:org.ng200.openolympus.controller.PartialsController.java
@RequestMapping("/partials/**") String getMapping(final HttpServletRequest request) { final String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); final String bestMatchPattern = (String) request .getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); final AntPathMatcher apm = new AntPathMatcher(); final String finalPath = apm.extractPathWithinPattern(bestMatchPattern, path); return "partials/" + finalPath + "::content"; }
From source file:eu.supersede.gr.rest.ResourcesRest.java
@RequestMapping("/**") public byte[] getResource(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); // System.out.println( "Serving page " + finalPath ); Resource resource = resourceLoader.getResource("classpath:static/ahprp/" + finalPath); // try { // System.out.println( resource.getFile().getAbsolutePath() ); // } catch (IOException e1) { // e1.printStackTrace(); // }/* w w w. ja v a 2 s . co m*/ // Resource resource = resourceLoader.getResource("classpath:static/game.html"); try { InputStream is = resource.getInputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try { int read = is.read(); while (read != -1) { byteArrayOutputStream.write(read); read = is.read(); } } catch (IOException e) { e.printStackTrace(); } byte[] bytes = byteArrayOutputStream.toByteArray(); return bytes; } catch (IOException e) { e.printStackTrace(); } // Something went wrong return ("Failed to load resource '" + finalPath).getBytes(); }
From source file:org.dawnsci.marketplace.controllers.FileController.java
@RequestMapping(value = "/{solution}/**", method = { RequestMethod.GET, RequestMethod.HEAD }) @ResponseBody//from ww w . j a va 2s .c o m public ResponseEntity<FileSystemResource> getFile(@PathVariable("solution") String solution, 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(); path = apm.extractPathWithinPattern(bestMatchPattern, path); File file = fileService.getFile(solution, path); if (file.exists() && file.isFile()) { try { String detect = tika.detect(file); MediaType mediaType = MediaType.parseMediaType(detect); return ResponseEntity.ok().contentLength(file.length()).contentType(mediaType) .lastModified(file.lastModified()).body(new FileSystemResource(file)); } catch (IOException e) { e.printStackTrace(); } } else { throw new ResourceNotFoundException(); } return null; }
From source file:com.netflix.spinnaker.gate.controllers.EntityTagsController.java
@RequestMapping(value = "/**", method = RequestMethod.GET) public Map get(HttpServletRequest request) { String pattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); String id = new AntPathMatcher().extractPathWithinPattern(pattern, request.getServletPath()); return entityTagsService.get(id); }
From source file:org.bonitasoft.web.designer.controller.WidgetDirectiveLoaderController.java
/** * Extract path from a controller mapping. /generator/widgets/pbInput/pbInput.js => /pbInput/pbInput.js *//*from w w w.j a v a 2 s.c om*/ private Path extractPathWithinPattern(final HttpServletRequest request) { String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); String finalPath = new AntPathMatcher().extractPathWithinPattern(bestMatchPattern, path); return widgetRepositoryPath.resolve(finalPath); }
From source file:org.zalando.zmon.actuator.metrics.MetricsWrapper.java
private String getFinalStatus(final HttpServletRequest request) { Object bestMatchingPattern = request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); if (bestMatchingPattern != null) { return fixSpecialCharacters(bestMatchingPattern.toString()); }// w ww.ja v a 2 s. co m // always return unknown, using the full path leads to an explosion of metrics due to path variables return UNKNOWN_PATH_SUFFIX; }