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: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 a v a 2 s. com*/ * * @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:ch.sbb.releasetrain.jsfbootadapter.FileDownloadUtil.java
@RequestMapping(value = "/static/**", method = RequestMethod.GET) public void getFile(HttpServletResponse response, HttpServletRequest request) { try {/*from ww w . j a v a2s. c o m*/ String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); PathMatchingResourcePatternResolver res = new PathMatchingResourcePatternResolver(); Resource template = res.getResource(path); if (!template.exists()) { log.info("file n/a... " + path); return; } org.apache.commons.io.IOUtils.copy(template.getInputStream(), response.getOutputStream()); response.flushBuffer(); } catch (IOException ex) { log.info("Error writing file to output stream", ex); } }
From source file:springku.HelloController.java
@RequestMapping(value = "/ambiltanggal/**", method = RequestMethod.GET) public String belajar1(ModelMap map, HttpServletRequest request) { String data = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); String[] pecah = data.split("/"); map.addAttribute("nama", pecah[2]); return "learning"; }
From source file:com.netflix.genie.web.controllers.ControllerUtilsUnitTests.java
/** * Test the getRemainingPath method./*from w w w .java 2s .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:com.app.controller.interceptor.AuthenticationInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { Subject currentUser = SecurityUtils.getSubject(); if (!currentUser.isAuthenticated()) { String originalUrl = (String) request .getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); WebUtils.setSessionAttribute(request, "redirect", originalUrl); response.sendRedirect("log_in"); return false; }//from w ww . j a v a 2 s. c o m return true; }
From source file:coral.reef.test.web.ReefControllerTest.java
@Test public void testUrl() throws IOException { final HttpServletRequest httpRequest = mock(HttpServletRequest.class); when(httpRequest.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)) .thenReturn("/lineup/world.xml"); final HttpServletResponse httpResponse = mock(HttpServletResponse.class); final HttpSession httpSession = mock(HttpSession.class); final ReefHandler handler = mock(ReefHandler.class); when(reefService.handler("test")).thenReturn(handler); when(handler.startMarker()).thenReturn("test"); when(handler.refreshMarker()).thenReturn("test"); when(handler.processMarker()).thenReturn("test"); when(handler.serverMarker()).thenReturn("test"); reefController.dispatchToExpHandler("test", httpSession, httpResponse, httpRequest); }
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(); // }//from w w w . j a v a2 s . c o 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:net.thewaffleshop.nimbus.web.WebJarsController.java
@ResponseBody @RequestMapping("/webjarslocator/{webjar}/**") public ResponseEntity locateWebjarAsset(@PathVariable String webjar, HttpServletRequest request) { try {//from www. j a va 2 s .co m String mvcPrefix = "/webjarslocator/" + webjar + "/"; String mvcPath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); String fullPath = assetLocator.getFullPath(webjar, mvcPath.substring(mvcPrefix.length())); return new ResponseEntity(new ClassPathResource(fullPath), HttpStatus.OK); } catch (Exception e) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } }