Example usage for javax.servlet.http HttpServletRequest getContextPath

List of usage examples for javax.servlet.http HttpServletRequest getContextPath

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getContextPath.

Prototype

public String getContextPath();

Source Link

Document

Returns the portion of the request URI that indicates the context of the request.

Usage

From source file:com.jaeksoft.searchlib.web.AbstractServlet.java

private void buildUrls(HttpServletRequest request) throws MalformedURLException {
    serverBaseURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(),
            request.getContextPath()).toString();
    StringBuilder sbUrl = new StringBuilder(request.getRequestURI());
    String qs = request.getQueryString();
    if (qs != null) {
        sbUrl.append('?');
        sbUrl.append(qs);//from   ww  w. j  av a 2 s.com
    }
    URL url = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), sbUrl.toString());
    serverURL = url.toString();
}

From source file:de.perdian.apps.dashboard.mvc.portal.PortalView.java

private void appendDashboardJsContent(Map<String, ?> model, HttpServletRequest request,
        HttpServletResponse response) throws IOException {

    // Make sure to make environment information available before the
    // actual JavaScript is included in the page
    response.getWriter().append("dashboard.contextPath = \"").append(request.getContextPath())
            .append("\";\n\n");

    // Now include the JavaScript file into the resulting document which
    // will render the actual dashboard
    try (Reader resourceReader = new InputStreamReader(
            new BufferedInputStream(this.getJsResource().getInputStream()), "UTF-8")) {
        IOUtils.copy(resourceReader, response.getWriter());
    }/*  ww  w. ja v  a 2s. co  m*/

    // Make sure page is reloaded once every three hours, so that changes will
    // propagate automatically and to reset memory
    response.getWriter()
            .append("\nwindow.setTimeout(function() { location.reload(); }, (1000 * 60 * 60 * 3));\n");

}

From source file:net.sourceforge.fenixedu.presentationTier.servlets.filters.AnnualTeachingCreditsDocumentFilter.java

private String buildRedirectURL(HttpServletRequest request) {
    String url = "/scientificCouncil/defineCreditsPeriods.do?method=showPeriods";

    String urlWithChecksum = GenericChecksumRewriter.injectChecksumInUrl(request.getContextPath(), url,
            request.getSession());//w w w. j  a v  a  2s .c  o m

    return request.getContextPath() + urlWithChecksum;
}

From source file:pivotal.au.se.gemfirexdweb.controller.AddListenerController.java

@RequestMapping(value = "/addlistener", method = RequestMethod.GET)
public String createListener(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {

    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {//from  w  ww . ja  v a  2s.  c o m
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to add new Table Listener");

    AddListener listenerAttribute = new AddListener();

    if (request.getParameter("tableName") != null) {
        listenerAttribute.setTableName(request.getParameter("tableName"));
    }

    if (request.getParameter("schemaName") != null) {
        listenerAttribute.setSchemaName(request.getParameter("schemaName"));
    }

    model.addAttribute("listenerAttribute", listenerAttribute);

    // This will resolve to /WEB-INF/jsp/addlistener.jsp
    return "addlistener";
}

From source file:pivotal.au.se.gemfirexdweb.controller.CreateGatewayReceiverController.java

@RequestMapping(value = "/creategatewayreceiver", method = RequestMethod.GET)
public String createGatewayReceiver(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {

    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {//from w w w  .  j a  v  a 2  s .c o m
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to create a new Gateway Receiver");

    model.addAttribute("gatewayReceiverAttribute", new NewGatewayReceiver());

    // This will resolve to /WEB-INF/jsp/create-gatewayreceiver.jsp
    return "create-gatewayreceiver";
}

From source file:com.glaf.core.util.RequestUtils.java

/**
 * ?/*from   ww w  .j  a  v  a2  s  .c  o  m*/
 * 
 * @param request
 * @param url
 * @return
 */
public static String getRelativeUrl(HttpServletRequest request, String url) {
    if (!url.startsWith(getLocalHostAddress(request, true) + "/")) {
        return url;
    }
    url = url.replace((getLocalHostAddress(request, true) + "/"), "");
    String actualServlet = request.getContextPath() + request.getServletPath();
    if (actualServlet.startsWith("/")) {
        actualServlet = actualServlet.substring(1);
    }
    int i = actualServlet.indexOf("/");
    while (i != -1) {
        if (url.startsWith(actualServlet.substring(0, i))) {
            url = url.replace(actualServlet.substring(0, i + 1), "");
        } else {
            url = "../" + url;
        }
        actualServlet = actualServlet.substring(i + 1);
        i = actualServlet.indexOf("/");
    }
    return url;
}

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

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    Blog blog = blogService.getBlogById(Blog.DEFAULT_ID);
    if (blog != null) {
        return true;
    }//from   ww w.  j  a v a  2 s .  c om

    final String requestPath = getRequestPath(request);
    if (!SETUP_PATH.equalsIgnoreCase(requestPath)) {
        response.sendRedirect(request.getContextPath() + SETUP_PATH);
        return false;
    }

    return true;
}

From source file:br.vschettino.forum.interceptor.AuthInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {

    Usuario visitante = (Usuario) request.getSession().getAttribute("usuario");
    if (request.getRequestURI().contains("/login") || request.getRequestURI().contains("/logout")) {
        return true;
    }/* ww  w  .  j a va 2  s  .  co  m*/
    if (visitante == null) {
        response.sendRedirect(request.getContextPath() + "/web/login?unauthorized=true");
        return false;
    }
    return true;
}

From source file:org.bpmscript.web.TemplateController.java

/**
 * Gets the sitemesh HTMLPage and passes that information to the right view
 * along with the following parameters://from   www . j a  va 2  s .  com
 * 
 * <ul>
 * <li>base - the context path</li>
 * <li>locale - the locale for the page</li>
 * <li>req - the http request</li>
 * <li>res - the http response</li>
 * </ul>
 */
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    HTMLPage htmlPage = (HTMLPage) request.getAttribute(RequestConstants.PAGE);

    Map<String, Object> context = new HashMap<String, Object>(templateModel);

    context.put("base", request.getContextPath());
    context.put("locale", request.getLocale());

    // For backwards compatability with apps that used the old VelocityDecoratorServlet
    // that extended VelocityServlet instead of VelocityViewServlet
    context.put("req", request);
    context.put("res", response);

    if (htmlPage == null) {
        context.put("title", "Title?");
        context.put("body", "<p>Body?</p>");
        context.put("head", "<!-- head -->");
    } else {
        context.put("title", OutputConverter.convert(htmlPage.getTitle()));
        {
            StringWriter buffer = new StringWriter();
            htmlPage.writeBody(OutputConverter.getWriter(buffer));
            context.put("body", buffer.toString());
        }
        {
            StringWriter buffer = new StringWriter();
            htmlPage.writeHead(OutputConverter.getWriter(buffer));
            context.put("head", buffer.toString());
        }
        context.put("page", htmlPage);
        Factory factory = Factory.getInstance(new Config(new ServletConfig() {
            public ServletContext getServletContext() {
                return TemplateController.this.getServletContext();
            }

            public String getInitParameter(String name) {
                return null;
            }

            public String getServletName() {
                return null;
            }

            public Enumeration<?> getInitParameterNames() {
                return null;
            }
        }));
        Decorator decorator = factory.getDecoratorMapper().getDecorator(request, htmlPage);
        context.put("decorator", decorator);
    }
    return new ModelAndView(getViewName(), context);
}

From source file:org.abstracthorizon.proximity.webapp.controllers.ArtifactsController.java

/**
 * Artifacts list.//from w  w w  .  j  a v a2  s.c o  m
 * 
 * @param request the request
 * @param response the response
 * 
 * @return the model and view
 * 
 * @throws Exception the exception
 */
public ModelAndView artifactsList(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String requestURI = request.getRequestURI()
            .substring(request.getContextPath().length() + request.getServletPath().length());
    if (requestURI.length() == 0) {
        requestURI = "/";
    }
    logger.debug("Got artifact request on URI " + requestURI);
    String orderBy = request.getParameter("orderBy") == null ? "name" : request.getParameter("orderBy");
    String targetRepository = request.getParameter("repositoryId");
    String targetGroup = request.getParameter("repositoryGroupId");
    List requestPathList = explodeUriToList(requestURI);

    String gid = null;
    String aid = null;
    String version = null;

    if (requestPathList.size() > 0) {
        gid = (String) requestPathList.get(0);
    }
    if (requestPathList.size() > 1) {
        aid = (String) requestPathList.get(1);
    }
    if (requestPathList.size() > 2) {
        version = (String) requestPathList.get(2);
    }

    // this view relies on search only, thats the trick:
    // level 1: search for "kind:pom", extract the "pom.gid" properties,
    // make them unique, show
    // level 2: search for "kind:pom AND pom.gid:SELECTION", extract the
    // "pom.aid" properties, make them unqie, show
    // level 3: search for "kind:pom AND pom.gid:SELECTION AND
    // pom.aid:SELECTION", extract the "pom.version" ...
    // level 4: search for "kind:pom AND pom.gid:SELECTION AND
    // pom.aid:SELECTION AND pom.version:SELECTION" and offer pom.pck
    // download?

    // URI: /pom.gid/pom.aid/pom.version

    logger.debug("Got request for artifactList on URI=" + requestURI);

    String searchExpr = "m2kind:pom";
    if (targetRepository != null) {
        searchExpr += " AND repository.id:" + targetRepository;
    }
    if (targetGroup != null) {
        searchExpr += " AND repository.groupId:" + targetGroup;
    }
    if (gid != null) {
        searchExpr += " AND pom.gid:" + gid;
    }
    if (aid != null) {
        searchExpr += " AND pom.aid:" + aid;
    }
    if (version != null) {
        searchExpr += " AND pom.version:" + version;
    }

    // make list unique and ordered on smthn
    List artifactList = null;
    if (version != null) {
        artifactList = sortAndMakeUnique(indexer.searchByQuery(searchExpr), "pom.version");
    } else if (aid != null) {
        artifactList = sortAndMakeUnique(indexer.searchByQuery(searchExpr), "pom.version");
    } else if (gid != null) {
        artifactList = sortAndMakeUnique(indexer.searchByQuery(searchExpr), "pom.aid");
    } else {
        artifactList = sortAndMakeUnique(indexer.searchByQuery(searchExpr), "pom.gid");
    }

    Map result = new HashMap();
    result.put("gid", gid);
    result.put("aid", aid);
    result.put("version", version);
    result.put("items", artifactList);
    result.put("orderBy", orderBy);
    result.put("requestUri", requestURI);
    result.put("requestPathList", requestPathList);

    return new ModelAndView("repository/artifactList", result);

}