Example usage for javax.servlet.http HttpServletRequest getLocalName

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

Introduction

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

Prototype

public String getLocalName();

Source Link

Document

Returns the host name of the Internet Protocol (IP) interface on which the request was received.

Usage

From source file:org.apache.atlas.web.util.Servlets.java

public static String getHostName(HttpServletRequest httpServletRequest) {
    return httpServletRequest.getLocalName();
}

From source file:com.hangum.tadpole.engine.restful.RESTfulAPIUtils.java

/**
 * make url/*from  w  w  w  . ja v  a2 s.c om*/
 * 
 * @param strSQL
 * @param strRestURL
 * @return
 */
public static String makeURL(String strSQL, String strRestURL) {
    HttpServletRequest httpRequest = RWT.getRequest();
    String strServerURL = String.format("http://%s:%s%s", httpRequest.getLocalName(),
            httpRequest.getLocalPort(), httpRequest.getServletPath());

    return String.format("%s%s?%s", strServerURL + "api/rest/base", strRestURL, getParameter(strSQL));
}

From source file:de.qucosa.servlet.MetsDisseminatorServlet.java

private static String extractTargetUrlFromRequest(HttpServletRequest request) {
    return String.format("%s://%s:%s/fedora", request.getScheme(), request.getLocalName(),
            request.getLocalPort());/*from   ww w.  ja  v  a2 s . c  o  m*/
}

From source file:architecture.ee.web.util.WebSiteUtils.java

public static WebSite getWebSite(HttpServletRequest request) throws WebSiteNotFoundException {
    String localName = request.getLocalName();
    log.debug("check: " + localName + " - " + (StringUtils.isNotEmpty(localName)
            && !TextUtils.isValidIpAddress(localName) && TextUtils.isValidHostname(localName)));
    if (StringUtils.isNotEmpty(localName) && !TextUtils.isValidIpAddress(localName)
            && TextUtils.isValidHostname(localName)) {
        try {/*from   www.  ja  v  a  2 s . com*/
            log.debug("web site by url");
            return getWebSiteManager().getWebSiteByUrl(localName);
        } catch (WebSiteNotFoundException e) {
            if (localName.equals("localhost")) {
                return getDefaultWebSite();
            } else {
                throw e;
            }
        }
    }

    return getDefaultWebSite();
}

From source file:com.zimbra.cs.account.oauth.utils.OAuthServiceProvider.java

public static void handleException(Exception e, HttpServletRequest request, HttpServletResponse response,
        boolean sendBody) throws IOException, ServletException {
    String realm = (request.isSecure()) ? "https://" : "http://";
    realm += request.getLocalName();
    OAuthServlet.handleException(response, e, realm, sendBody);
}

From source file:net.firejack.platform.web.security.oauth.provider.OAuthProcessor.java

/**
 * @param e/*from  w w  w  .j  av a  2 s .  co m*/
 * @param request
 * @param response
 * @param sendBody
 * @throws javax.servlet.ServletException
 * @throws java.io.IOException
 */
public static void handleException(Exception e, HttpServletRequest request, HttpServletResponse response,
        boolean sendBody) throws IOException, ServletException {
    String realm = (request.isSecure()) ? "https://" : "http://";
    realm += request.getLocalName();
    OAuthServlet.handleException(response, e, realm, sendBody);
}

From source file:com.evolveum.midpoint.security.api.SecurityUtil.java

/**
 * Returns current connection information, as derived from HTTP request stored in current thread.
 * May be null if the thread is not associated with any HTTP request (e.g. task threads, operations invoked from GUI but executing in background).
 *//*from w  w  w .  j ava2  s  .co  m*/
public static HttpConnectionInformation getCurrentConnectionInformation() {
    RequestAttributes attr = RequestContextHolder.getRequestAttributes();
    if (!(attr instanceof ServletRequestAttributes)) {
        return null;
    }
    ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) attr;
    HttpServletRequest request = servletRequestAttributes.getRequest();
    if (request == null) {
        return null;
    }
    HttpConnectionInformation rv = new HttpConnectionInformation();
    HttpSession session = request.getSession(false);
    if (session != null) {
        rv.setSessionId(session.getId());
    }
    rv.setLocalHostName(request.getLocalName());
    rv.setRemoteHostAddress(getRemoteHostAddress(request));
    return rv;
}

From source file:de.micromata.genome.logging.LogRequestDumpAttribute.java

/**
 * Gen http request dump./*  ww w.  j  ava 2s.c  o m*/
 *
 * @param req the req
 * @return the string
 */
@SuppressWarnings("unchecked")
public static String genHttpRequestDump(HttpServletRequest req) {
    StringBuilder sb = new StringBuilder();

    sb.append("method: ").append(req.getMethod()).append('\n')//
            .append("requestURL: ").append(req.getRequestURL()).append('\n')//
            .append("servletPath: ").append(req.getServletPath()).append('\n')//
            .append("requestURI: ").append(req.getRequestURI()).append('\n') //
            .append("queryString: ").append(req.getQueryString()).append('\n') //
            .append("pathInfo: ").append(req.getPathInfo()).append('\n')//
            .append("contextPath: ").append(req.getContextPath()).append('\n') //
            .append("characterEncoding: ").append(req.getCharacterEncoding()).append('\n') //
            .append("localName: ").append(req.getLocalName()).append('\n') //
            .append("contentLength: ").append(req.getContentLength()).append('\n') //
    ;
    sb.append("Header:\n");
    for (Enumeration<String> en = req.getHeaderNames(); en.hasMoreElements();) {
        String hn = en.nextElement();
        sb.append("  ").append(hn).append(": ").append(req.getHeader(hn)).append("\n");
    }
    sb.append("Attr: \n");
    Enumeration en = req.getAttributeNames();
    for (; en.hasMoreElements();) {
        String k = (String) en.nextElement();
        Object v = req.getAttribute(k);
        sb.append("  ").append(k).append(": ").append(Objects.toString(v, StringUtils.EMPTY)).append('\n');
    }

    return sb.toString();
}

From source file:org.reallysqs.server.views.CreateQueueResponseView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    Queue queue = (Queue) model.get("queue");
    String location = "http://" + request.getLocalName() + ":" + request.getLocalPort()
            + request.getContextPath() + request.getServletPath() + "/queues/" + queue.getName();

    response.addHeader("Location", location);
}

From source file:edu.cornell.mannlib.vitro.webapp.filters.RequestLoggerFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {
    try {//from   w  ww  .j  a  v a  2  s .  c o m
        if (request instanceof HttpServletRequest) {
            HttpServletRequest theRequest = (HttpServletRequest) request;
            StringBuffer requestedLocation = new StringBuffer();
            requestedLocation.append(theRequest.getLocalName()).append(":");
            requestedLocation.append(theRequest.getLocalPort());
            requestedLocation.append(theRequest.getRequestURI());
            if (theRequest.getQueryString() != null) {
                requestedLocation.append("?").append(theRequest.getQueryString());
            }
            log.debug("Incoming request: " + requestedLocation.toString());
        }
    } catch (Exception e) {
        // This shouldn't really happen, but if it does, we'll be ready for it.
    } finally {
        filterChain.doFilter(request, response);
    }
}