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:istata.web.HtmlController.java

@RequestMapping("/est")
public void est(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setContentType("text/html");

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

    File f = stataService.est();

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

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

@RequestMapping(value = "/pages/**", method = RequestMethod.GET)
@ResponseBody//  w w  w.  j av a2  s  . c om
public ResponseEntity<FileSystemResource> picture(HttpServletRequest request) {

    String resource = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE))
            .substring(1);
    Path path = fileService.getPageFile(resource).toPath();

    File file = path.toAbsolutePath().toFile();

    if (file.exists() && file.isFile()) {
        try {
            String detect = tika.detect(file);
            MediaType mediaType = MediaType.parseMediaType(detect);
            return ResponseEntity.ok().contentLength(file.length()).contentType(mediaType)
                    .body(new FileSystemResource(file));
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        throw new ResourceNotFoundException();
    }
    return null;
}

From source file:org.craftercms.engine.controller.PageRenderController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    String pageUrl;//from  w w w  .j av a2  s  .  co  m
    SiteContext siteContext = SiteContext.getCurrent();

    if (siteContext != null) {
        if (siteContext.isFallback()) {
            logger.warn("Rendering fallback page [" + fallbackPageUrl + "]");

            pageUrl = fallbackPageUrl;
        } else {
            pageUrl = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
            if (StringUtils.isEmpty(pageUrl)) {
                throw new IllegalStateException("Required request attribute '"
                        + HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE + "' is not set");
            }

            Script controllerScript = getControllerScript(siteContext, request, pageUrl);
            if (controllerScript != null) {
                Map<String, Object> model = new HashMap<>();
                Map<String, Object> variables = createScriptVariables(request, response, model);
                String viewName = executeScript(controllerScript, variables);

                if (StringUtils.isNotEmpty(viewName)) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Rendering view " + viewName + " returned by script " + controllerScript);
                    }

                    return new ModelAndView(viewName, model);
                } else {
                    return null;
                }
            }

            if (logger.isDebugEnabled()) {
                logger.debug("Rendering page [" + pageUrl + "]");
            }
        }
    } else {
        throw new IllegalStateException("No current site context found");
    }

    return new ModelAndView(pageUrl);
}

From source file:org.atmosphere.samples.pubsub.PubSubController.java

private void processGet(String topic, HttpServletRequest req, AtmosphereResource event) {

    event.addEventListener(new WebSocketEventListenerAdapter());
    event.addEventListener(new AtmosphereResourceEventListenerAdapter());

    String restOfTheUrl = (String) req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);

    Broadcaster b = lookupBroadcaster(topic, restOfTheUrl);

    String header = req.getHeader(HeaderConfig.X_ATMOSPHERE_TRANSPORT);
    if (HeaderConfig.LONG_POLLING_TRANSPORT.equalsIgnoreCase(header)) {
        req.setAttribute(ApplicationConfig.RESUME_ON_BROADCAST, Boolean.TRUE);
    }/*from   www  .  j av  a2 s . c o  m*/

    event.suspend(FORE_EVER);
    b.addAtmosphereResource(event);

    ClusterBroadcastFilter filter = newFilter(b, event.getAtmosphereConfig());
    b.getBroadcasterConfig().addFilter(filter);
    b.getBroadcasterConfig().addFilter(new XSSHtmlFilter());
}

From source file:csns.web.controller.WikiController.java

@RequestMapping("/wiki/content/**")
public String view(@RequestParam(required = false) Long revisionId, HttpServletRequest request,
        ModelMap models) {/*from   w w w .j a v  a 2  s  .  co m*/
    String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    models.put("path", path);

    Revision revision = revisionId == null ? revisionDao.getRevision(path)
            : revisionDao.getRevision(revisionId);
    if (revision == null)
        return "wiki/nopage";

    if (StringUtils.hasText(revision.getPage().getPassword())
            && request.getSession().getAttribute(path) == null)
        return "wiki/password";

    revision.getPage().incrementViews();
    pageDao.savePage(revision.getPage());
    models.put("revision", revision);

    String dept = getDept(path);
    if (revision.isIncludeSidebar()) {
        String sidebar = dept == null ? "/wiki/content/sidebar"
                : "/wiki/content/department/" + dept + "/sidebar";
        models.put("sidebar", revisionDao.getRevision(sidebar));
    }

    if (SecurityUtils.isAuthenticated()) {
        User user = SecurityUtils.getUser();
        models.put("user", user);
        models.put("isAdmin", dept == null ? user.isSysadmin() : user.isAdmin(dept));

        Subscription subscription = subscriptionDao.getSubscription(revision.getPage(), user);
        if (subscription != null) {
            if (subscription.isNotificationSent()) {
                subscription.setNotificationSent(false);
                subscription = subscriptionDao.saveSubscription(subscription);
            }
            models.put("subscription", subscription);
        }
    }

    return "wiki/page";
}

From source file:org.craftercms.engine.controller.HttpProxyRequestHandler.java

protected String getUrlToProxy(HttpServletRequest request) {
    String url = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    if (StringUtils.isEmpty(url)) {
        throw new IllegalStateException("Required request attribute '"
                + HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE + "' is not set");
    }/*from  ww  w  .j  a v a2  s  .  c  om*/

    return url;
}

From source file:istata.web.HtmlController.java

@RequestMapping(value = { "/edit \"**", "/edit \"**/**" })
@ResponseBody/*from w  w w .j  a v a2  s .c o m*/
public String edit(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model)
        throws IOException {

    String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    stataService.saveCmd(path);

    path = path.substring(7, path.length() - 1);

    Path dofile = Paths.get(path).toAbsolutePath();

    if (dofile.toString().equals(path) && dofile.toFile().exists()) {
        model.put("content", stataService.loadDoFile(path).getContent());
        model.put("title", path);

        return VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "edit.vm", "UTF-8", model);
    } else {
        path = stataService.expandPath(path);

        dofile = Paths.get(path).toAbsolutePath();

        if (dofile.toFile().exists()) {
            response.sendRedirect("/edit \"" + dofile.toAbsolutePath().toString() + "\"");
            return null;
        } else {
            // TODO maybe this can be done more graceful
            throw new NoSuchFileException(path);
        }
    }

}

From source file:org.springjutsu.validation.util.RequestUtils.java

/**
 * Identifies the view name pattern which best matches
 * the current request URL (path within handler mapping).
 * @param candidateViewNames The view name patterns to test
 * @param controllerPaths Possible request mapping prefixes 
 * from a controller-level RequestMapping annotation 
 * @param request the current request/*from w  w  w .j  a  v  a2 s  .  com*/
 * @return the best matching view name.
 */
public static String findFirstMatchingRestPath(String[] candidateViewNames, String[] controllerPaths,
        HttpServletRequest request) {

    String pathWithinHandlerMapping = removeLeadingAndTrailingSlashes(
            (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE));

    AntPathMatcher antPathMatcher = new AntPathMatcher();
    for (String candidatePath : candidateViewNames) {
        if ((controllerPaths == null || candidatePath.startsWith("/")) && antPathMatcher
                .match(removeLeadingAndTrailingSlashes(candidatePath), pathWithinHandlerMapping)) {
            return candidatePath;
        } else if (controllerPaths != null) {
            for (String controllerPath : controllerPaths) {
                String testPath = (controllerPath + "/" + candidatePath).replace("//", "/");
                if (antPathMatcher.match(removeLeadingAndTrailingSlashes(testPath), pathWithinHandlerMapping)) {
                    return candidatePath;
                }
            }
        }
    }
    return null;
}

From source file:org.craftercms.engine.controller.rest.RestScriptsController.java

protected String getServiceUrl(HttpServletRequest request) {
    String pathWithinHandlerMappingAttr = HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE;
    String url = (String) request.getAttribute(pathWithinHandlerMappingAttr);

    if (StringUtils.isEmpty(url)) {
        throw new IllegalStateException(
                "Required request attribute '" + pathWithinHandlerMappingAttr + "' is not set");
    }/*from w  w  w  . ja  v a 2  s  . c  om*/

    return url;
}

From source file:com.netflix.genie.web.resources.handlers.GenieResourceHttpRequestHandlerUnitTests.java

/**
 * Make sure we can't handle the HTTP request for a resource if we don't have the proper attribute in the request.
 *
 * @throws ServletException on error// ww  w.  ja v a  2 s  .c om
 * @throws IOException      on error
 */
@Test(expected = IllegalStateException.class)
public void cantHandleRequestWithoutHandlerMappingAttribute() throws ServletException, IOException {
    final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    final HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    Mockito.when(request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).thenReturn(null);
    this.handler.handleRequest(request, response);
}