Example usage for com.liferay.portal.kernel.util HttpUtil getCompleteURL

List of usage examples for com.liferay.portal.kernel.util HttpUtil getCompleteURL

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util HttpUtil getCompleteURL.

Prototype

public static String getCompleteURL(HttpServletRequest httpServletRequest) 

Source Link

Usage

From source file:au.com.permeance.liferay.portal.servlet.filters.request.WebRequestLoggerFilter.java

License:Open Source License

/**
 * This processFilter method is derived from 
 * the Apache Tomcat RequestDumperFilter#doFilter(ServletRequest,ServletResponse,FilterChain)
 * and merged with the Liferay Portal 6.1.x Servlet Filter framework.
 * /*from ww  w .j av a  2 s  . c om*/
 * @see http://grepcode.com/file/repo1.maven.org/maven2/org.apache.tomcat.embed/tomcat-embed-core/7.0.0/org/apache/catalina/filters/RequestDumperFilter.java
 */
@Override
protected void processFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
        throws Exception {

    request.setAttribute(SKIP_FILTER, Boolean.TRUE);

    HttpServletRequest hRequest = null;
    HttpServletResponse hResponse = null;

    if (request instanceof HttpServletRequest) {
        hRequest = (HttpServletRequest) request;
    }
    if (response instanceof HttpServletResponse) {
        hResponse = (HttpServletResponse) response;
    }

    ServletContext sc = hRequest.getServletContext();

    String completeURL = HttpUtil.getCompleteURL(request);

    if (getLog().isInfoEnabled()) {
        getLog().info("Start filter for web request logger at URL " + completeURL);
    }

    // Log pre-service information
    doLog("FILTER START TIME", getTimestamp());

    if (sc != null) {
        doLog("servletContext.serverInfo", "" + sc.getServerInfo());
        doLog("servletContext.majorVersion", "" + sc.getMajorVersion());
        doLog("servletContext.minorVersion", "" + sc.getMinorVersion());
    }

    if (hRequest == null) {
        doLog("requestURI", NON_HTTP_REQ_MSG);
        doLog("authType", NON_HTTP_REQ_MSG);
    } else {
        doLog("requestURI", hRequest.getRequestURI());
        doLog("authType", hRequest.getAuthType());
    }

    doLog("characterEncoding", request.getCharacterEncoding());
    doLog("contentLength", Integer.valueOf(request.getContentLength()).toString());
    doLog("contentType", request.getContentType());

    if (hRequest == null) {
        doLog("contextPath", NON_HTTP_REQ_MSG);
        doLog("cookie", NON_HTTP_REQ_MSG);
        doLog("header", NON_HTTP_REQ_MSG);
    } else {
        doLog("contextPath", hRequest.getContextPath());
        Cookie cookies[] = hRequest.getCookies();
        if (cookies != null) {
            for (int i = 0; i < cookies.length; i++)
                doLog("cookie", cookies[i].getName() + "=" + cookies[i].getValue());
        }
        if (doesServletContainerSupportServletAPI_3_0(sc)) {
            Enumeration<String> hnames = hRequest.getHeaderNames();
            while (hnames.hasMoreElements()) {
                String hname = hnames.nextElement();
                Enumeration<String> hvalues = hRequest.getHeaders(hname);
                while (hvalues.hasMoreElements()) {
                    String hvalue = hvalues.nextElement();
                    doLog("header", hname + "=" + hvalue);
                }
            }
        } else {
            Enumeration hnames = hRequest.getHeaderNames();
            while (hnames.hasMoreElements()) {
                String hname = (String) hnames.nextElement();
                Enumeration<String> hvalues = hRequest.getHeaders(hname);
                while (hvalues.hasMoreElements()) {
                    String hvalue = hvalues.nextElement();
                    doLog("header", hname + "=" + hvalue);
                }
            }
        }
    }

    doLog("locale", request.getLocale().toString());

    if (hRequest == null) {
        doLog("method", NON_HTTP_REQ_MSG);
    } else {
        doLog("method", hRequest.getMethod());
    }

    Enumeration<String> pnames = request.getParameterNames();
    while (pnames.hasMoreElements()) {
        String pname = pnames.nextElement();
        String pvalues[] = request.getParameterValues(pname);
        StringBuilder result = new StringBuilder(pname);
        result.append('=');
        for (int i = 0; i < pvalues.length; i++) {
            if (i > 0)
                result.append(", ");
            result.append(pvalues[i]);
        }
        doLog("parameter", result.toString());
    }

    if (hRequest == null) {
        doLog("pathInfo", NON_HTTP_REQ_MSG);
    } else {
        doLog("pathInfo", hRequest.getPathInfo());
    }

    doLog("protocol", request.getProtocol());

    if (hRequest == null) {
        doLog("queryString", NON_HTTP_REQ_MSG);
    } else {
        doLog("queryString", hRequest.getQueryString());
    }

    doLog("remoteAddr", request.getRemoteAddr());
    doLog("remoteHost", request.getRemoteHost());

    if (hRequest == null) {
        doLog("remoteUser", NON_HTTP_REQ_MSG);
        doLog("requestedSessionId", NON_HTTP_REQ_MSG);
    } else {
        doLog("remoteUser", hRequest.getRemoteUser());
        doLog("requestedSessionId", hRequest.getRequestedSessionId());
    }

    doLog("scheme", request.getScheme());
    doLog("serverName", request.getServerName());
    doLog("serverPort", Integer.valueOf(request.getServerPort()).toString());

    if (hRequest == null) {
        doLog("servletPath", NON_HTTP_REQ_MSG);
    } else {
        doLog("servletPath", hRequest.getServletPath());
    }

    doLog("isSecure", Boolean.valueOf(request.isSecure()).toString());
    doLog("------------------", "--------------------------------------------");

    // Perform the request
    processFilter(WebRequestLoggerFilter.class, hRequest, hResponse, filterChain);

    // Log post-service information
    doLog("------------------", "--------------------------------------------");
    if (hRequest == null) {
        doLog("authType", NON_HTTP_REQ_MSG);
    } else {
        doLog("authType", hRequest.getAuthType());
    }

    doLog("contentType", response.getContentType());

    if (hResponse == null) {
        doLog("header", NON_HTTP_RES_MSG);
    } else {
        if (doesServletContainerSupportServletAPI_3_0(sc)) {
            Iterable<String> rhnames = hResponse.getHeaderNames();
            for (String rhname : rhnames) {
                Iterable<String> rhvalues = hResponse.getHeaders(rhname);
                for (String rhvalue : rhvalues)
                    doLog("header", rhname + "=" + rhvalue);
            }
        } else {
            doLog("Unable to log response headers; Servlet Container does not support Servlet API 3.0.",
                    StringPool.BLANK);
        }
    }

    if (hRequest == null) {
        doLog("remoteUser", NON_HTTP_REQ_MSG);
    } else {
        doLog("remoteUser", hRequest.getRemoteUser());
    }

    if (hResponse == null) {
        doLog("remoteUser", NON_HTTP_RES_MSG);
    } else {
        doLog("status", Integer.valueOf(hResponse.getStatus()).toString());
    }

    doLog("FILTER END TIME", getTimestamp());

    doLog("==================", "============================================");

    if (getLog().isInfoEnabled()) {
        getLog().info("End filter for web request logger at URL " + completeURL);
    }
}

From source file:com.fb.filter.OpenGraphFilter.java

License:Open Source License

@Override
protected void processFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
        throws Exception {

    request.setAttribute(SKIP_FILTER, Boolean.TRUE);

    if (_log.isDebugEnabled()) {
        String completeURL = HttpUtil.getCompleteURL(request);

        _log.debug("Adding Open Graph Attributes " + completeURL);
    }//from  w  w w  . j a v  a2  s.  c o m

    BufferCacheServletResponse bufferCacheServletResponse = new BufferCacheServletResponse(response);

    processFilter(OpenGraphFilter.class, request, bufferCacheServletResponse, filterChain);

    String content = bufferCacheServletResponse.getString();

    String contentType = response.getContentType();

    if ((contentType != null) && contentType.startsWith(ContentTypes.TEXT_HTML)) {

        content = getContent(request, content);

        ServletResponseUtil.write(response, content);
    } else {
        ServletResponseUtil.write(response, bufferCacheServletResponse);
    }
}

From source file:com.liferay.content.targeting.analytics.hook.filter.YoutubeVideoHtmlFilter.java

License:Open Source License

@Override
protected void processFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
        throws Exception {

    request.setAttribute(SKIP_FILTER, Boolean.TRUE);

    if (_log.isDebugEnabled()) {
        String completeURL = HttpUtil.getCompleteURL(request);

        _log.debug("Processing Youtube URLs for " + completeURL);
    }/*  w  w w .  ja  v a  2s. c om*/

    BufferCacheServletResponse bufferCacheServletResponse = new BufferCacheServletResponse(response);

    processFilter(YoutubeVideoHtmlFilter.class, request, bufferCacheServletResponse, filterChain);

    String content = bufferCacheServletResponse.getString();

    String contentType = response.getContentType();

    if ((contentType != null) && contentType.startsWith(ContentTypes.TEXT_HTML)) {

        content = getContent(request, content);

        ServletResponseUtil.write(response, content);
    } else {
        ServletResponseUtil.write(response, bufferCacheServletResponse);
    }
}