Example usage for org.springframework.web.util UrlPathHelper getContextPath

List of usage examples for org.springframework.web.util UrlPathHelper getContextPath

Introduction

In this page you can find the example usage for org.springframework.web.util UrlPathHelper getContextPath.

Prototype

public String getContextPath(HttpServletRequest request) 

Source Link

Document

Return the context path for the given request, detecting an include request URL if called within a RequestDispatcher include.

Usage

From source file:org.wallride.web.support.ControllerUtils.java

public static ResponseEntity<?> createRedirectResponseEntity(HttpServletRequest nativeRequest,
        HttpServletResponse nativeResponse, String path) {
    UrlPathHelper pathHelper = new UrlPathHelper();
    String url = pathHelper.getContextPath(nativeRequest) + path;
    String encodedUrl = nativeResponse.encodeRedirectURL(url);

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(URI.create(encodedUrl));

    ResponseEntity<?> response = new ResponseEntity<>(null, headers, HttpStatus.FOUND);
    return response;
}

From source file:arena.web.view.RedirectView.java

@SuppressWarnings("unchecked")
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    String uri = ServletUtils.replaceWildcards(this.url, this.allowRequestArgsInURI, model, request);

    if (this.serverSideRedirect) {
        log.info("Server side forwarding to: " + uri);
        getServletContext().getRequestDispatcher(uri).forward(request, response);
    } else {/*from w ww.  jav  a  2 s.c om*/
        if (!this.absoluteURL && this.absoluteURI) {
            UrlPathHelper helper = new UrlPathHelper();
            uri = helper.getContextPath(request) + uri;
        }
        log.info("Client side forwarding to: " + uri);
        response.sendRedirect(uri);
    }
}

From source file:org.wallride.web.support.BlogLanguageDataValueProcessor.java

@Override
public String processUrl(HttpServletRequest request, String url) {
    UrlPathHelper urlPathHelper = new UrlPathHelper();
    String contextPath = urlPathHelper.getContextPath(request);

    if (!url.startsWith(contextPath + "/")) {
        return url;
    }/*w  w  w .ja  v  a2 s  . c om*/

    BlogLanguage blogLanguage = (BlogLanguage) request
            .getAttribute(BlogLanguageMethodArgumentResolver.BLOG_LANGUAGE_ATTRIBUTE);
    if (blogLanguage == null || blogLanguage.getBlog().getLanguages().size() <= 1) {
        return url;
    }

    String path = url.substring(contextPath.length());
    String processedUrl = contextPath + "/" + blogLanguage.getLanguage() + path;
    logger.debug(url + " => " + processedUrl);
    return processedUrl;
}

From source file:org.jm.spring.controller.EndpointDocumentationController.java

@RequestMapping(value = "/{classRequestMapping}", method = RequestMethod.GET, produces = {
        MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody Documentation showAvailableResource(HttpServletRequest httpServletRequest,
        @PathVariable String classRequestMapping) throws ClassNotFoundException {

    Documentation document = null;/*  w  w w  .  j  a  va  2 s  . c  om*/
    UrlPathHelper urlPathHelper = new UrlPathHelper();
    String basePath = getBasePath(httpServletRequest);

    SpringMVCAPIReader springMVCAPIReader = new SpringMVCAPIReader("0.1", "1.1-SHAPSHOT.121026", basePath,
            urlPathHelper.getContextPath(httpServletRequest));

    document = springMVCAPIReader.processMethods(handlerMapping, classRequestMapping);

    return document;
}

From source file:org.jm.spring.controller.EndpointDocumentationController.java

/**
 * Should return a listing of available operations like 
 * http://petstore.swagger.wordnik.com/api/resources.json
 * /*from w  ww. j  a v a 2  s.c o  m*/
 * @param httpServletRequest
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/resources.json", method = RequestMethod.GET, produces = {
        MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody Documentation showAvailableResources(HttpServletRequest httpServletRequest)
        throws Exception {

    UrlPathHelper urlPathHelper = new UrlPathHelper();

    String basePath = getBasePath(httpServletRequest);

    SpringMVCAPIReader springMVCAPIReader = new SpringMVCAPIReader("0.1", "1.1-SHAPSHOT.121026", basePath,
            urlPathHelper.getContextPath(httpServletRequest));

    Documentation document = springMVCAPIReader.createResources(handlerMapping);

    return document;
}