Example usage for javax.servlet ServletRequest getServerName

List of usage examples for javax.servlet ServletRequest getServerName

Introduction

In this page you can find the example usage for javax.servlet ServletRequest 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:de.iteratec.iteraplan.businesslogic.common.URLBuilder.java

/**
 * Retrieves the URL of the server. It is also needed in case of ServletReqeusts, where
 * ContextPath is not available, so URL is without application name. It should be something like:
 * https://localhost:8443 This method is private because the iteraplan.properties are not checked
 * to see if the user has entered an application url by hand as in the other methods. Therefore
 * there could be problems if this method is used directly and the user depends on the property
 * setting./*from  w  w  w. j  av  a 2 s.c  o m*/
 * 
 * @param req
 *          The current servlet request providing the necessary information.
 * @return The constructed application URL.
 */
private static String getServerURL(ServletRequest req) {
    StringBuilder serverUrl = new StringBuilder(BUFFER_SIZE);

    serverUrl.append(req.getScheme());
    serverUrl.append(COLON);
    serverUrl.append(FORWARD_SLASH);
    serverUrl.append(FORWARD_SLASH);
    serverUrl.append(req.getServerName());

    int port = req.getServerPort();
    if (port != WEB_PORT) {
        serverUrl.append(COLON);
        serverUrl.append(Integer.toString(port));
    }

    return serverUrl.toString();
}

From source file:org.kie.appformer.backend.server.service.build.BuildAndDeployCallable.java

private void fireAppReadyEvent(File war, ServletRequest sreq) {
    final String url = "http://" + sreq.getServerName() + ":" + sreq.getServerPort() + "/"
            + war.getName().replace(".war", "");

    appReadyEvent.fire(new AppReady(url));
}

From source file:no.sesat.search.http.filters.SiteLocatorFilter.java

private static String getServerName(final ServletRequest servletRequest) {

    // find the current site. Since we are behind a ajp13 connection request.getServerName() won't work!
    // httpd.conf needs:
    //      1) "JkEnvVar SERVER_NAME" inside the virtual host directive.
    //      2) "UseCanonicalName Off" to assign ServerName from client's request.
    return null != servletRequest.getAttribute("SERVER_NAME")
            ? (String) servletRequest.getAttribute("SERVER_NAME")
            // falls back to this when not behind Apache. (Development machine).
            : servletRequest.getServerName() + ":" + servletRequest.getServerPort();
}

From source file:com.sourcesense.alfresco.opensso.AlfrescoOpenSSOFilter.java

protected String buildURLForRedirect(ServletRequest request) {
    String serverURL = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
    String alfrescoContext = ((HttpServletRequest) request).getContextPath();
    return getOpenSSOLoginURL().concat("?goto=").concat(serverURL).concat(alfrescoContext);
}

From source file:GetKey.java

public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();

    String key = getInitParameter("key");
    String host = req.getServerName();
    int port = req.getServerPort();

    if (!keyFitsServer(key, host, port)) {
        out.println("Pirated!");
    } else {/* ww w .j  a v  a 2  s.  c om*/
        out.println("Valid");
    }
}

From source file:pt.webdetails.cdc.plugin.CdcContentGenerator.java

private String getRoot() {

    ServletRequest wrapper = getRequest();
    String root = wrapper.getServerName() + ":" + wrapper.getServerPort();

    return root;/*from  w  w w.j  a  v  a 2 s  .c  o m*/
}

From source file:org.yes.cart.web.filter.ShopResolverFilter.java

/**
 * {@inheritDoc}//from   ww w .  jav  a  2s . c om
 */
public ServletRequest doBefore(final ServletRequest servletRequest, final ServletResponse servletResponse)
        throws IOException, ServletException {

    final String serverDomainName = servletRequest.getServerName().toLowerCase();

    final Shop shop = shopService.getShopByDomainName(serverDomainName);

    if (shop == null) {
        final String url = systemService.getDefaultShopURL();
        final Logger log = ShopCodeContext.getLog(this);
        if (log.isInfoEnabled()) {
            log.info("Shop can not be resolved. For server name [" + serverDomainName + "] Redirect to : ["
                    + url + "]");
        }
        ((HttpServletResponse) servletResponse).sendRedirect(url);
        return null;
    }

    ApplicationDirector.setCurrentShop(shop);
    ApplicationDirector.setShopperIPAddress(getRemoteIpAddr(servletRequest));
    ShopCodeContext.setShopCode(shop.getCode());
    ShopCodeContext.setShopId(shop.getShopId());

    return getModifiedRequest(servletRequest, ApplicationDirector.getCurrentThemeChain());

}

From source file:ServerSnoop.java

public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();

    ServletContext context = getServletContext();
    out.println("req.getServerName(): " + req.getServerName());
    out.println("req.getServerPort(): " + req.getServerPort());
    out.println("context.getServerInfo(): " + context.getServerInfo());
    out.println("getServerInfo() name: " + getServerInfoName(context.getServerInfo()));
    out.println("getServerInfo() version: " + getServerInfoVersion(context.getServerInfo()));
    out.println("context.getAttributeNames():");
    Enumeration e = context.getAttributeNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        out.println("  context.getAttribute(\"" + name + "\"): " + context.getAttribute(name));
    }/*from  ww  w .  j  av a2  s .c om*/
}

From source file:com.netpace.cms.sso.filter.AlfrescoOpenSSOFilter.java

protected String buildURLForRedirect(ServletRequest request) {
    String serverURL = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
    String alfrescoContext = ((HttpServletRequest) request).getContextPath();
    System.out.println("ServerURL: " + serverURL);
    return getOpenSSOLoginURL().concat("?goto=").concat(serverURL).concat(alfrescoContext);
}

From source file:org.niord.core.NiordApp.java

/**
 * Registers the server name associated with the current thread (i.e. servlet request)
 * @param req the servlet request// www .j  a v  a2 s  .  c  o  m
 */
public void registerServerNameForCurrentThread(ServletRequest req) {
    String scheme = StringUtils.defaultIfBlank(req.getScheme(), "http");
    String serverName = StringUtils.defaultIfBlank(req.getServerName(), "localhost");
    String port = (scheme.equalsIgnoreCase("https"))
            ? (req.getServerPort() == 443 ? "" : ":" + req.getServerPort())
            : (req.getServerPort() == 80 ? "" : ":" + req.getServerPort());
    if (StringUtils.isNotBlank(serverName)) {
        THREAD_LOCAL_SERVER_NAME.set(scheme + "://" + serverName + port);
    }
}