Example usage for org.springframework.web.servlet HandlerMapping PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE

List of usage examples for org.springframework.web.servlet HandlerMapping PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE

Introduction

In this page you can find the example usage for org.springframework.web.servlet HandlerMapping PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE.

Prototype

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

Document

Name of the HttpServletRequest attribute that contains the path within the handler mapping, in case of a pattern match, or the full relevant URI (typically within the DispatcherServlet's mapping) else.

Usage

From source file:org.cloudifysource.rest.command.CommandManager.java

/**
 * Constructor takes as input the entire commands URI, held in the request
 * and the root object from which to begin invocation.
 * @param request - the commands request 
 * @param root - the root command's object
 *///from  ww  w  .  j ava 2  s. co m
public CommandManager(HttpServletRequest request, Object root) {
    final String prefix = "/admin/";
    String executionPath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    if (executionPath.endsWith("/")) {
        executionPath = executionPath.substring(0, executionPath.length() - 1);
    }
    if (!executionPath.startsWith(prefix)) {
        throw new IllegalArgumentException("Bad request URL " + request.getRequestURL());
    }
    String restUrl = "http://" + request.getLocalAddr() + ":" + request.getLocalPort()
            + request.getContextPath();
    this.commandURL = restUrl + executionPath;
    initilizeCommandList(executionPath.substring(prefix.length()), root);
}

From source file:org.dawnsci.marketplace.controllers.FileController.java

@RequestMapping(value = "/{solution}/**", method = { RequestMethod.GET, RequestMethod.HEAD })
@ResponseBody//  w  w  w  .j  ava  2s  . c om
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:org.dawnsci.marketplace.controllers.PageController.java

@RequestMapping(value = { "/pages/*.md" }, method = RequestMethod.GET)
public String markdown(HttpServletRequest request, ModelMap map, Principal principal) {
    addCommonItems(map, principal);//from  w w  w  .  j a v a  2  s.co m
    String resource = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE))
            .substring(1);
    Path path = fileService.getPageFile(resource).toPath();
    map.addAttribute("text", parse(path));

    return "page";
}

From source file:coral.reef.web.ReefToCoralController.java

@RequestMapping(value = "/{exp}/**")
public void dispatchToExpHandler(@PathVariable("exp") String exp, HttpSession httpSession,
        HttpServletResponse httpResponse, HttpServletRequest httpRequest) throws IOException {

    httpResponse.setHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
    httpResponse.setHeader("Pragms", "no-cache");
    httpResponse.setHeader("Expires", "0");

    Integer id = (Integer) httpSession.getAttribute(REEF_ID);
    String sessionExp = (String) httpSession.getAttribute(REEF_EXP);

    String path = ((String) httpRequest.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE))
            .substring(exp.length() + 2);

    ReefHandler handler = service.handler(exp);

    if (path.startsWith(handler.startMarker())) {

        if (sessionExp != null || id != null) {
            // TODO remove old client (?)
        }//from  ww w .ja  v a 2 s  . c  om

        String query = httpRequest.getQueryString();
        query = (query == null) ? "" : query;
        id = handler.addClient(null);
        String result = handler.process(id, path, query);
        result = service.replaceHost(exp, result);
        httpSession.setAttribute(REEF_ID, id);
        httpSession.setAttribute(REEF_EXP, exp);
        httpResponse.setContentType("text/html");
        httpResponse.getWriter().println(result);

    } else if (path.startsWith(handler.refreshMarker())) {

        if (sessionExp != null || id != null) {
            // TODO remove old client (?)
        }

        String query = httpRequest.getQueryString();
        query = (query == null) ? "" : query;
        id = Integer.parseInt(query.replaceAll("[^\\d]", ""));
        id = handler.addClient(id);
        String result = handler.process(id, "", "?refreshid=" + id);
        result = service.replaceHost(exp, result);
        httpSession.setAttribute(REEF_ID, id);
        httpSession.setAttribute(REEF_EXP, exp);
        httpResponse.setContentType("text/html");
        httpResponse.getWriter().println(result);

    } else if (path.startsWith(handler.processMarker()) && sessionExp != null && sessionExp.equals(exp)) {

        /*
         * PROCESS
         */

        String query = httpRequest.getQueryString();
        query = (query == null) ? "" : query;
        String result = handler.process(id, path, query);
        result = service.replaceHost(exp, result);
        httpResponse.setContentType("text/html");
        httpResponse.getWriter().println(result);

    } else if (path.startsWith(handler.serverMarker())) {

        /*
         * SERVER
         */

        String result = handler.server(path.substring(handler.serverMarker().length() + 1),
                httpRequest.getParameterMap());
        result = service.replaceHost(exp, result);
        httpResponse.setContentType("text/html");
        httpResponse.getWriter().println(result);

    } else if (handler.getResMap().containsKey(path)) {

        /*
         * RESOURCE
         */

        File f = handler.getResMap().get(path);
        FileSystemResource fr = new FileSystemResource(f);
        String type = servletContext.getMimeType(path);
        httpResponse.setContentType(type);

        IOUtils.copy(fr.getInputStream(), httpResponse.getOutputStream());
    } else {
        // no match = no response => should propagate to next controller
        System.out.println(path + " - " + handler.getResMap());
    }

}

From source file:org.bonitasoft.web.designer.controller.WidgetDirectiveLoaderController.java

/**
 * Extract path from a controller mapping. /generator/widgets/pbInput/pbInput.js => /pbInput/pbInput.js
 *///w w  w  .j  a va  2s  .  co  m
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:istata.web.HtmlController.java

@RequestMapping(value = { "/graph **", "/graph **/**" })
public void graphs(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setContentType("image/png");

    String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    stataService.saveCmd(path);/*from   www .j a  va 2 s  . c  om*/

    path = path.substring(7);

    stataService.run("graph display " + path);

    File f = stataService.graph(path);

    InputStream in = new FileInputStream(f);
    IOUtils.copy(in, response.getOutputStream());
}

From source file:org.ngrinder.infra.spring.RemainedPathMethodArgumentResolver.java

@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
        NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
    AntPathMatcher pathMatcher = new AntPathMatcher();
    RequestMapping requestMappingOnMethod = parameter.getMethodAnnotation(RequestMapping.class);
    RequestMapping requestMappingOnClass = getDeclaringClassRequestMapping(parameter);
    String combine = pathMatcher.combine(requestMappingOnClass.value()[0], requestMappingOnMethod.value()[0]);
    return PathUtils.removePrependedSlash(pathMatcher.extractPathWithinPattern(combine,
            (String) webRequest.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE,
                    NativeWebRequest.SCOPE_REQUEST)));
}

From source file:com.netflix.genie.web.controllers.UIControllerUnitTests.java

/**
 * Make sure the getFile method returns the right forward command.
 * @throws Exception if an error occurs//from  w w w.ja  va  2  s.co  m
 */
@Test
public void canGetFile() throws Exception {
    final String id = UUID.randomUUID().toString();
    final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);

    Mockito.when(request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE))
            .thenReturn("/file/" + id + "/output/genie/log.out");
    Mockito.when(request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE))
            .thenReturn("/file/{id}/**");

    final String encodedId = URLEncoder.encode(id, "UTF-8");
    final String expectedPath = "/api/v3/jobs/" + encodedId + "/output/genie/log.out";

    Assert.assertThat(this.controller.getFile(id, request), Matchers.is("forward:" + expectedPath));
}

From source file:am.ik.categolj2.api.link.LinkRestController.java

String getUrl(HttpServletRequest request) {
    return ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE))
            .replace("/api/" + ApiVersion.CURRENT_VERSION + "/links/", "");
}