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:com.indeed.imhotep.web.BashScriptServlet.java

@RequestMapping("/iql.sh")
@ResponseBody/*from   w  w  w  .  ja  va 2 s.  com*/
protected String doGet(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {
    resp.setHeader("content-disposition", "attachment; filename=iql.sh");
    final String server = req.getServerName();
    final String protocol;
    if (server.contains("qa.indeed") || server.contains("stage.indeed") || server.contains("indeed.com")) {
        protocol = "https://";
    } else {
        protocol = "http://";
    }

    final URL scriptResourceURL = Resources.getResource("iql.sh");
    final String script = Resources.toString(scriptResourceURL, Charsets.UTF_8);
    final String serverURLVariable = "SERVER_URL=" + protocol + server + ":" + req.getServerPort()
            + req.getContextPath() + "/query\n";
    return serverURLVariable + script;
}

From source file:com.education.lessons.ui.server.login.OpenIDLoginController.java

/**
 * Builds the current base URL; up to the the domain name, e.g.
 * http://www.mydomain.com//*  w w  w.  j  av  a  2s  .c  o m*/
 */
private String getRealm(HttpServletRequest request) {
    String scheme = request.getScheme();
    String serverName = request.getServerName();
    int serverPort = request.getServerPort();

    StringBuilder sb = new StringBuilder();
    sb.append(scheme).append("://").append(serverName);

    if (serverPort != 80) {
        sb.append(":").append(serverPort);
    }

    sb.append("/");
    return sb.toString();
}

From source file:org.esco.web.servlet.ServerNameLocaleResolverAdaptor.java

@Override
public void setLocale(final HttpServletRequest request, final HttpServletResponse response,
        final Locale locale) {
    // Add the server name variant to the locale
    final String serverName = request.getServerName();
    Locale variantLocale = new Locale(locale.getLanguage(), locale.getCountry(), serverName);

    request.setAttribute(LOCALE_ATTRIBUTE_KEY, variantLocale);

    if (this.storeLocaleInSession) {
        // Store the locale in session
        request.getSession().setAttribute(LOCALE_ATTRIBUTE_KEY, variantLocale);
    }//from  w ww  . j ava 2 s.  c  om
}

From source file:org.ow2.chameleon.everest.servlet.EverestServlet.java

/**
 * Computes the HTTP url of the given path.
 * The url is computed thanks to the request.
 * @param  request the HTTP Request//from   ww  w  .j  a v a  2 s.co  m
 * @param path the path
 * @return the URL pointing to the given path
 */
private String toURL(HttpServletRequest request, Path path) {
    return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + EVEREST_SERVLET_PATH + "/" + path.toString();
}

From source file:info.magnolia.cms.util.UrlPatternDelegate.java

/**
 * Compares the reques with the url and host patterns.
 * @return <code>true</code> if the pattern matches the configured host (if set) and url (if set)
 *///from  w w  w  .  j a va  2 s  .  c  o  m
@Override
public boolean match(HttpServletRequest request) {

    boolean match = true;

    if (hostPattern != null) {
        match = hostPattern.match(request.getServerName());
    }

    if (urlPattern != null) {
        match = urlPattern.match(MgnlContext.getAggregationState().getCurrentURI());
    }

    if (originalUrlPattern != null) {
        match = originalUrlPattern.match(MgnlContext.getAggregationState().getOriginalURI());
    }

    return match;
}

From source file:edu.indiana.d2i.sloan.ui.LoginAction.java

/**
 * get server context// ww  w  . j av  a  2 s. com
 * 
 * @return
 */
private String getServerContext() {
    HttpServletRequest request = getServletRequest();
    final StringBuilder serverPath = new StringBuilder();
    serverPath.append(request.getScheme() + "://");
    serverPath.append(request.getServerName());
    if (request.getServerPort() != 80) {
        serverPath.append(":" + request.getServerPort());
    }
    serverPath.append(request.getContextPath());
    return serverPath.toString();
}

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

public static String getServiceUrl(HttpServletRequest request) {
    String scheme = request.getScheme();
    String serviceUrl = scheme + "://" + request.getServerName();
    if (request.getServerPort() != 80) {
        serviceUrl += ":" + request.getServerPort();
    }/*from w ww . j a  va2 s  .c om*/
    if (!"/".equals(request.getContextPath())) {
        serviceUrl += request.getContextPath();
    }
    return serviceUrl;
}

From source file:eu.scape_project.pw.idp.bean.CreateAccountView.java

/**
 * Adds the user./*from   w  ww  .j  a v a2s . c  om*/
 */
public void addUser() {
    userManager.addUser(user);

    HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext()
            .getRequest();
    String serverString = request.getServerName() + ":" + request.getServerPort();
    try {
        userManager.sendActivationMail(user, serverString);
        addUserSuccessful = true;
    } catch (CannotSendMailException e) {
        facesMessages.addError("Could not send activation mail.");
        addUserSuccessful = false;
    }
}

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

public static String getLocalHostAddress(HttpServletRequest request, boolean includePort) {
    String scheme = request.getScheme();
    String serverName = request.getServerName();
    String port = "";
    if (includePort) {
        int p = request.getServerPort();
        port = (p == 80) ? "" : ":" + p;
    }/*from   w  w w . j a va2  s.com*/
    return scheme + "://" + serverName + port;
}

From source file:org.magnum.dataup.CopyOfMyVideoController.java

private String getUrlBaseForLocalServer() {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
            .getRequest();/*from w  ww .  j a v  a2 s  .  c  o  m*/
    String base = "http://" + request.getServerName()
            + ((request.getServerPort() != 80) ? ":" + request.getServerPort() : "");
    //System.out.println(base);
    return base;
}