Example usage for javax.servlet.http HttpServletRequest getServerName

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

Introduction

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

Prototype

public String getServerName();

Source Link

Document

Returns the host name of the server to which the request was sent.

Usage

From source file:br.com.gerenciapessoal.security.JsfLoginUrlAuthenticationEntryPoint.java

/**
 * Builds a URL to redirect the supplied request to HTTPS. Used to redirect
 * the current request to HTTPS, before doing a forward to the login page.
 *
 * @param request/*from  w  ww  .  j a  va2 s  . c  o m*/
 * @return
 * @throws java.io.IOException
 * @throws javax.servlet.ServletException
 */
protected String buildHttpsRedirectUrlForRequest(HttpServletRequest request)
        throws IOException, ServletException {

    int serverPort = portResolver.getServerPort(request);
    Integer httpsPort = portMapper.lookupHttpsPort(serverPort);

    if (httpsPort != null) {
        RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder();
        urlBuilder.setScheme("https");
        urlBuilder.setServerName(request.getServerName());
        urlBuilder.setPort(httpsPort);
        urlBuilder.setContextPath(request.getContextPath());
        urlBuilder.setServletPath(request.getServletPath());
        urlBuilder.setPathInfo(request.getPathInfo());
        urlBuilder.setQuery(request.getQueryString());

        return urlBuilder.getUrl();
    }

    // Fall through to server-side forward with warning message
    logger.warn("Unable to redirect to HTTPS as no port mapping found for HTTP port " + serverPort);

    return null;
}

From source file:com.athena.peacock.controller.web.lb.LoadBalancerController.java

@RequestMapping("/applyListener")
public @ResponseBody SimpleJsonResponse applyListener(HttpServletRequest request, SimpleJsonResponse jsonRes,
        LoadBalancerDto loadBalancer) throws Exception {
    Assert.notNull(loadBalancer.getLoadBalancerId(), "loadBalancerId can not be null.");
    Assert.notNull(loadBalancer.getMachineId(), "machineId can not be null.");

    try {//from  w  w w .ja va  2  s  .c o m
        String urlPrefix = "http://" + request.getServerName() + ":" + request.getServerPort() + "/"
                + request.getContextPath() + "/repo";
        lbListenerService.applyListener(loadBalancer, urlPrefix);
        jsonRes.setMsg("Load Balancer Listener ? ??.");
    } catch (Exception e) {
        jsonRes.setSuccess(false);
        jsonRes.setMsg("Load Balancer Listener  ?  ? ?.");

        logger.error("Unhandled Expeption has occurred. ", e);
    }

    return jsonRes;
}

From source file:edu.stanford.muse.webapp.JSPHelper.java

public static boolean runningOnMuseMachine(HttpServletRequest request) {
    String sn = request.getServerName();
    if (sn != null) {
        return sn.contains("stanford");
    }// ww w . j a  va 2s  .  co m
    return false;
}

From source file:edu.stanford.muse.webapp.JSPHelper.java

public static boolean runningOnAshokaMachine(HttpServletRequest request) {
    String sn = request.getServerName();
    if (sn != null) {
        return sn.contains("ashoka.edu.in");
    }//from w  ww . j ava  2 s .com
    return false;
}

From source file:com.boylesoftware.web.Router.java

/**
 * Send redirect to the same request URI (including the query string), but
 * over HTTPS.//from  w  w w. j  a v a 2s .co  m
 *
 * @param webapp The web-application.
 * @param request The HTTP request.
 * @param response The HTTP response.
 */
private void sendRedirectToSecureURI(final AbstractWebApplication webapp, final HttpServletRequest request,
        final HttpServletResponse response) {

    LooseCannon.heel();

    try (final PooledStringBuffer buf = StringBufferPool.get()) {
        final StringBuilder redirectURL = buf.getStringBuilder();

        redirectURL.append("https://").append(request.getServerName());

        final int httpsPort = webapp.getHTTPSPort();
        if (httpsPort != 443)
            redirectURL.append(':').append(httpsPort);

        redirectURL.append(request.getRequestURI());

        final String queryString = request.getQueryString();
        if (queryString != null)
            redirectURL.append('?').append(queryString);

        response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
        response.setHeader("Location", redirectURL.toString());
    }
}

From source file:io.neba.core.logviewer.LogfileViewerConsolePlugin.java

/**
 * Streams the contents of the log directory as a zip file.
 *//*  ww w.  ja va2s  . c  o m*/
private void download(HttpServletResponse res, HttpServletRequest req) throws IOException {
    final String selectedLogfile = req.getParameter("file");
    final String filenameSuffix = isEmpty(selectedLogfile) ? ""
            : "-" + substringAfterLast(selectedLogfile, File.separator);

    res.setContentType("application/zip");
    res.setHeader("Content-Disposition",
            "attachment;filename=logfiles-" + req.getServerName() + filenameSuffix + ".zip");
    ZipOutputStream zos = new ZipOutputStream(res.getOutputStream());
    try {
        for (File file : this.logFiles.resolveLogFiles()) {
            if (selectedLogfile != null && !file.getAbsolutePath().equals(selectedLogfile)) {
                continue;
            }

            ZipEntry ze = new ZipEntry(toZipFileEntryName(file));
            zos.putNextEntry(ze);
            FileInputStream in = new FileInputStream(file);
            try {
                copy(in, zos);
                zos.closeEntry();
            } finally {
                closeQuietly(in);
            }
        }
        zos.finish();
    } finally {
        closeQuietly(zos);
    }
}

From source file:com.rxx.base.interceptor.ActionInterceptor.java

/**
 * action,basebasepath/*from  w  w  w.  j ava  2 s.  c  om*/
 * @param request HttpServletRequest
 * @param response HttpServletResponse 
 * @param handler 
 * @throws Exception 
 * @return true
 */
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    String modelId = request.getParameter(MODEL_ID); //
    if (StringUtil.isInteger(modelId)) {
        request.getSession().setAttribute(SessionConst.MODEL_ID_SESSION.toString(), modelId);
        request.getSession().setAttribute(SessionConst.MODEL_TITLE_SESSION.toString(),
                request.getParameter("modelTitle"));

    }
    request.setAttribute(BASE, Const.BASE);
    request.setAttribute(BASE_PATH, request.getScheme() + "://" + request.getServerName()
            + (request.getServerPort() == 80 ? "" : ":" + request.getServerPort()) + Const.BASE);
    request.setAttribute(BASE_URL,
            request.getScheme() + "://" + request.getServerName()
                    + (request.getServerPort() == 80 ? "" : ":" + request.getServerPort())
                    + request.getContextPath() + request.getServletPath()
                    + (request.getQueryString() == null ? "" : "?" + request.getQueryString()));
    return true;
}

From source file:mml.test.Editor.java

public void handle(HttpServletRequest request, HttpServletResponse response, String urn) throws MMLException {
    try {//from w w w  .  ja v a  2s .  c  om
        this.requestURL = request.getRequestURL().toString();
        this.service = Utils.first(request.getRequestURI());
        this.host = request.getServerName();
        this.docid = ensureParam(request, Params.DOCID, "italian/deroberto/ivicere/cap1");
        this.version1 = ensureParam(request, Params.VERSION1, "/Base/1920");
        this.style = ensureParam(request, Params.STYLE, "italian/deroberto");
        this.title = ensureParam(request, Params.TITLE, "I Vicer");
        this.author = ensureParam(request, Params.AUTHOR, "De Roberto");
        composePage();
        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().println(doc);
    } catch (Exception e) {
        throw new MMLException(e);
    }
}

From source file:org.apache.ofbiz.base.util.UtilHttp.java

private static StringBuilder prepareServerRootUrl(HttpServletRequest request) {
    StringBuilder requestUrl = new StringBuilder();
    requestUrl.append(request.getScheme());
    requestUrl.append("://" + request.getServerName());
    if (request.getServerPort() != 80 && request.getServerPort() != 443)
        requestUrl.append(":" + request.getServerPort());
    return requestUrl;
}

From source file:br.com.sg.security.SgLoginUrlAuthenticationEntryPoint.java

/**
 * Builds a URL to redirect the supplied request to HTTPS. Used to redirect
 * the current request to HTTPS, before doing a forward to the login page.
 *///ww  w .j  a v a2s.  co  m
protected String buildHttpsRedirectUrlForRequest(HttpServletRequest request)
        throws IOException, ServletException {

    Integer serverPort = portResolver.getServerPort(request);
    Integer httpsPort = portMapper.lookupHttpsPort(new Integer(serverPort));

    if (httpsPort != null) {
        RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder();
        urlBuilder.setScheme("https");
        urlBuilder.setServerName(request.getServerName());
        urlBuilder.setPort(httpsPort.intValue());
        urlBuilder.setContextPath(request.getContextPath());
        urlBuilder.setServletPath(request.getServletPath());
        urlBuilder.setPathInfo(request.getPathInfo());
        urlBuilder.setQuery(request.getQueryString());

        return urlBuilder.getUrl();
    }

    // Fall through to server-side forward with warning message
    logger.warn("Unable to redirect to HTTPS as no port mapping found for HTTP port " + serverPort);

    return null;
}