org.apache.catalina.AccessLog Java Examples

The following examples show how to use org.apache.catalina.AccessLog. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MongoAccessLogValve.java    From tomcat-mongo-access-log with Apache License 2.0 6 votes vote down vote up
/**
 * Set the format pattern, first translating any recognized alias.
 *
 * @param pattern The new pattern
 */
public void setPattern(String pattern) {
    if (pattern == null) {
        this.pattern = "";
    } else if (pattern.equals(Constants.AccessLog.COMMON_ALIAS)) {
        this.pattern = Constants.AccessLog.COMMON_PATTERN;
    } else if (pattern.equals(Constants.AccessLog.COMBINED_ALIAS)) {
        this.pattern = Constants.AccessLog.COMBINED_PATTERN;
    } else if (pattern.equals(me.chanjar.tomcat.valves.Constants.MongoAccessLog.DEFAULT_ALIAS)) {
        this.pattern = me.chanjar.tomcat.valves.Constants.MongoAccessLog.DEFAULT_PATTERN;
    } else if (pattern.equals(me.chanjar.tomcat.valves.Constants.MongoAccessLog.ALL_ALIAS)) {
      this.pattern = me.chanjar.tomcat.valves.Constants.MongoAccessLog.ALL_PATTERN;
    } else {
        this.pattern = pattern;
    }
    logElements = createLogElements();
}
 
Example #2
Source File: ContainerBase.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public AccessLog getAccessLog() {

    if (accessLogScanComplete) {
        return accessLog;
    }

    AccessLogAdapter adapter = null;
    Valve valves[] = getPipeline().getValves();
    for (Valve valve : valves) {
        if (valve instanceof AccessLog) {
            if (adapter == null) {
                adapter = new AccessLogAdapter((AccessLog) valve);
            } else {
                adapter.add((AccessLog) valve);
            }
        }
    }
    if (adapter != null) {
        accessLog = adapter;
    }
    accessLogScanComplete = true;
    return accessLog;
}
 
Example #3
Source File: ContainerBase.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public AccessLog getAccessLog() {
    
    if (accessLogScanComplete) {
        return accessLog;
    }

    AccessLogAdapter adapter = null;
    Valve valves[] = getPipeline().getValves();
    for (Valve valve : valves) {
        if (valve instanceof AccessLog) {
            if (adapter == null) {
                adapter = new AccessLogAdapter((AccessLog) valve);
            } else {
                adapter.add((AccessLog) valve);
            }
        }
    }
    if (adapter != null) {
        accessLog = adapter;
    }
    accessLogScanComplete = true;
    return accessLog;
}
 
Example #4
Source File: TestRemoteIpFilter.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testRequestAttributesForAccessLog() throws Exception {
    // PREPARE
    FilterDef filterDef = new FilterDef();
    filterDef.addInitParameter("protocolHeader", "x-forwarded-proto");
    filterDef.addInitParameter("remoteIpHeader", "x-my-forwarded-for");
    filterDef.addInitParameter("httpServerPort", "8080");

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("192.168.0.10");
    request.setHeader("x-my-forwarded-for", "140.211.11.130");
    request.setHeader("x-forwarded-proto", "http");

    // TEST
    HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();

    // VERIFY
    Assert.assertEquals("org.apache.catalina.AccessLog.ServerPort",
            Integer.valueOf(8080),
            actualRequest.getAttribute(AccessLog.SERVER_PORT_ATTRIBUTE));

    Assert.assertEquals("org.apache.catalina.AccessLog.RemoteAddr",
            "140.211.11.130",
            actualRequest.getAttribute(AccessLog.REMOTE_ADDR_ATTRIBUTE));

    Assert.assertEquals("org.apache.catalina.AccessLog.RemoteHost",
            "140.211.11.130",
            actualRequest.getAttribute(AccessLog.REMOTE_HOST_ATTRIBUTE));
}
 
Example #5
Source File: TomcatLogbackAccessEvent.java    From logback-access-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected Optional<String> evaluateValueToOverride() {
    return Optional.of(TomcatLogbackAccessEvent.this)
            .filter(TomcatLogbackAccessEvent::isRequestAttributesEnabled)
            .map(AccessEvent::getRequest)
            .map(request -> (String) request.getAttribute(AccessLog.PROTOCOL_ATTRIBUTE));
}
 
Example #6
Source File: TomcatLogbackAccessEvent.java    From logback-access-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected Optional<String> evaluateValueToOverride() {
    return Optional.of(TomcatLogbackAccessEvent.this)
            .filter(TomcatLogbackAccessEvent::isRequestAttributesEnabled)
            .map(AccessEvent::getRequest)
            .map(request -> (String) request.getAttribute(AccessLog.REMOTE_HOST_ATTRIBUTE));
}
 
Example #7
Source File: TomcatLogbackAccessEvent.java    From logback-access-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected Optional<String> evaluateValueToOverride() {
    return Optional.of(TomcatLogbackAccessEvent.this)
            .filter(TomcatLogbackAccessEvent::isRequestAttributesEnabled)
            .map(AccessEvent::getRequest)
            .map(request -> (String) request.getAttribute(AccessLog.REMOTE_ADDR_ATTRIBUTE));
}
 
Example #8
Source File: TomcatLogbackAccessEvent.java    From logback-access-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected Optional<Integer> evaluateValueToOverride() {
    return Optional.of(TomcatLogbackAccessEvent.this)
            .filter(AbstractLogbackAccessEvent::isUseServerPortInsteadOfLocalPort)
            .filter(TomcatLogbackAccessEvent::isRequestAttributesEnabled)
            .map(AccessEvent::getRequest)
            .map(request -> (Integer) request.getAttribute(AccessLog.SERVER_PORT_ATTRIBUTE));
}
 
Example #9
Source File: TestRemoteIpFilter.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testRequestAttributesForAccessLog() throws Exception {
    // PREPARE
    FilterDef filterDef = new FilterDef();
    filterDef.addInitParameter("protocolHeader", "x-forwarded-proto");
    filterDef.addInitParameter("remoteIpHeader", "x-my-forwarded-for");
    filterDef.addInitParameter("httpServerPort", "8080");

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("192.168.0.10");
    request.setHeader("x-my-forwarded-for", "140.211.11.130");
    request.setHeader("x-forwarded-proto", "http");

    // TEST
    HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();

    // VERIFY
    Assert.assertEquals("org.apache.catalina.AccessLog.ServerPort",
            Integer.valueOf(8080),
            actualRequest.getAttribute(AccessLog.SERVER_PORT_ATTRIBUTE));

    Assert.assertEquals("org.apache.catalina.AccessLog.RemoteAddr",
            "140.211.11.130",
            actualRequest.getAttribute(AccessLog.REMOTE_ADDR_ATTRIBUTE));

    Assert.assertEquals("org.apache.catalina.AccessLog.RemoteHost",
            "140.211.11.130",
            actualRequest.getAttribute(AccessLog.REMOTE_HOST_ATTRIBUTE));
}
 
Example #10
Source File: TestRemoteIpValve.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testRequestAttributesForAccessLog() throws Exception {

    // PREPARE
    RemoteIpValve remoteIpValve = new RemoteIpValve();
    remoteIpValve.setRemoteIpHeader("x-forwarded-for");
    remoteIpValve.setProtocolHeader("x-forwarded-proto");
    RemoteAddrAndHostTrackerValve remoteAddrAndHostTrackerValve = new RemoteAddrAndHostTrackerValve();
    remoteIpValve.setNext(remoteAddrAndHostTrackerValve);

    Request request = new MockRequest();
    request.setCoyoteRequest(new org.apache.coyote.Request());
    // client ip
    request.setRemoteAddr("192.168.0.10");
    request.setRemoteHost("192.168.0.10");
    request.getCoyoteRequest().getMimeHeaders().addValue("x-forwarded-for").setString("140.211.11.130");
    // protocol
    request.setServerPort(8080);
    request.getCoyoteRequest().scheme().setString("http");

    // TEST
    remoteIpValve.invoke(request, null);

    // VERIFY
    Assert.assertEquals("org.apache.catalina.AccessLog.ServerPort",
            Integer.valueOf(8080),
            request.getAttribute(AccessLog.SERVER_PORT_ATTRIBUTE));

    Assert.assertEquals("org.apache.catalina.AccessLog.RemoteAddr",
            "140.211.11.130",
            request.getAttribute(AccessLog.REMOTE_ADDR_ATTRIBUTE));

    Assert.assertEquals("org.apache.catalina.AccessLog.RemoteHost",
            "140.211.11.130",
            request.getAttribute(AccessLog.REMOTE_HOST_ATTRIBUTE));
}
 
Example #11
Source File: AccessLogAdapter.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public void add(AccessLog log) {
    if (log == null) {
        throw new NullPointerException();
    }
    AccessLog newArray[] = Arrays.copyOf(logs, logs.length + 1);
    newArray[newArray.length - 1] = log;
    logs = newArray;
}
 
Example #12
Source File: AccessLogValve.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Set the format pattern, first translating any recognized alias.
 *
 * @param pattern The new pattern
 */
public void setPattern(String pattern) {
    if (pattern == null) {
        this.pattern = "";
    } else if (pattern.equals(Constants.AccessLog.COMMON_ALIAS)) {
        this.pattern = Constants.AccessLog.COMMON_PATTERN;
    } else if (pattern.equals(Constants.AccessLog.COMBINED_ALIAS)) {
        this.pattern = Constants.AccessLog.COMBINED_PATTERN;
    } else {
        this.pattern = pattern;
    }
    logElements = createLogElements();
}
 
Example #13
Source File: TestRemoteIpValve.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testRequestAttributesForAccessLog() throws Exception {

    // PREPARE
    RemoteIpValve remoteIpValve = new RemoteIpValve();
    remoteIpValve.setRemoteIpHeader("x-forwarded-for");
    remoteIpValve.setProtocolHeader("x-forwarded-proto");
    RemoteAddrAndHostTrackerValve remoteAddrAndHostTrackerValve = new RemoteAddrAndHostTrackerValve();
    remoteIpValve.setNext(remoteAddrAndHostTrackerValve);

    Request request = new MockRequest();
    request.setCoyoteRequest(new org.apache.coyote.Request());
    // client ip
    request.setRemoteAddr("192.168.0.10");
    request.setRemoteHost("192.168.0.10");
    request.getCoyoteRequest().getMimeHeaders().addValue("x-forwarded-for").setString("140.211.11.130");
    // protocol
    request.setServerPort(8080);
    request.getCoyoteRequest().scheme().setString("http");

    // TEST
    remoteIpValve.invoke(request, null);

    // VERIFY
    Assert.assertEquals("org.apache.catalina.AccessLog.ServerPort",
            Integer.valueOf(8080),
            request.getAttribute(AccessLog.SERVER_PORT_ATTRIBUTE));

    Assert.assertEquals("org.apache.catalina.AccessLog.RemoteAddr",
            "140.211.11.130",
            request.getAttribute(AccessLog.REMOTE_ADDR_ATTRIBUTE));

    Assert.assertEquals("org.apache.catalina.AccessLog.RemoteHost",
            "140.211.11.130",
            request.getAttribute(AccessLog.REMOTE_HOST_ATTRIBUTE));
}
 
Example #14
Source File: AbstractAccessLogValve.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Set the format pattern, first translating any recognized alias.
 *
 * @param pattern The new pattern
 */
public void setPattern(String pattern) {
    if (pattern == null) {
        this.pattern = "";
    } else if (pattern.equals(Constants.AccessLog.COMMON_ALIAS)) {
        this.pattern = Constants.AccessLog.COMMON_PATTERN;
    } else if (pattern.equals(Constants.AccessLog.COMBINED_ALIAS)) {
        this.pattern = Constants.AccessLog.COMBINED_PATTERN;
    } else {
        this.pattern = pattern;
    }
    logElements = createLogElements();
}
 
Example #15
Source File: TestRemoteIpValve.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testRequestAttributesForAccessLog() throws Exception {

    // PREPARE
    RemoteIpValve remoteIpValve = new RemoteIpValve();
    remoteIpValve.setRemoteIpHeader("x-forwarded-for");
    remoteIpValve.setProtocolHeader("x-forwarded-proto");
    RemoteAddrAndHostTrackerValve remoteAddrAndHostTrackerValve = new RemoteAddrAndHostTrackerValve();
    remoteIpValve.setNext(remoteAddrAndHostTrackerValve);

    Request request = new MockRequest();
    request.setCoyoteRequest(new org.apache.coyote.Request());
    // client ip
    request.setRemoteAddr("192.168.0.10");
    request.setRemoteHost("192.168.0.10");
    request.getCoyoteRequest().getMimeHeaders().addValue("x-forwarded-for").setString("140.211.11.130");
    // protocol
    request.setServerPort(8080);
    request.getCoyoteRequest().scheme().setString("http");

    // TEST
    remoteIpValve.invoke(request, null);

    // VERIFY
    Assert.assertEquals("org.apache.catalina.AccessLog.ServerPort",
            Integer.valueOf(8080),
            request.getAttribute(AccessLog.SERVER_PORT_ATTRIBUTE));

    Assert.assertEquals("org.apache.catalina.AccessLog.RemoteAddr",
            "140.211.11.130",
            request.getAttribute(AccessLog.REMOTE_ADDR_ATTRIBUTE));

    Assert.assertEquals("org.apache.catalina.AccessLog.RemoteHost",
            "140.211.11.130",
            request.getAttribute(AccessLog.REMOTE_HOST_ATTRIBUTE));
}
 
Example #16
Source File: AccessLogValve.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Set the format pattern, first translating any recognized alias.
 *
 * @param pattern The new pattern
 */
public void setPattern(String pattern) {
    if (pattern == null) {
        this.pattern = "";
    } else if (pattern.equals(Constants.AccessLog.COMMON_ALIAS)) {
        this.pattern = Constants.AccessLog.COMMON_PATTERN;
    } else if (pattern.equals(Constants.AccessLog.COMBINED_ALIAS)) {
        this.pattern = Constants.AccessLog.COMBINED_PATTERN;
    } else {
        this.pattern = pattern;
    }
    logElements = createLogElements();
}
 
Example #17
Source File: TestRemoteIpFilter.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testRequestAttributesForAccessLog() throws Exception {
    // PREPARE
    FilterDef filterDef = new FilterDef();
    filterDef.addInitParameter("protocolHeader", "x-forwarded-proto");
    filterDef.addInitParameter("remoteIpHeader", "x-my-forwarded-for");
    filterDef.addInitParameter("httpServerPort", "8080");

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("192.168.0.10");
    request.setHeader("x-my-forwarded-for", "140.211.11.130");
    request.setHeader("x-forwarded-proto", "http");

    // TEST
    HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();

    // VERIFY
    Assert.assertEquals("org.apache.catalina.AccessLog.ServerPort",
            Integer.valueOf(8080),
            actualRequest.getAttribute(AccessLog.SERVER_PORT_ATTRIBUTE));

    Assert.assertEquals("org.apache.catalina.AccessLog.RemoteAddr",
            "140.211.11.130",
            actualRequest.getAttribute(AccessLog.REMOTE_ADDR_ATTRIBUTE));

    Assert.assertEquals("org.apache.catalina.AccessLog.RemoteHost",
            "140.211.11.130",
            actualRequest.getAttribute(AccessLog.REMOTE_HOST_ATTRIBUTE));
}
 
Example #18
Source File: AccessLogAdapter.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public void add(AccessLog log) {
    if (log == null) {
        throw new NullPointerException();
    }
    AccessLog newArray[] = Arrays.copyOf(logs, logs.length + 1);
    newArray[newArray.length - 1] = log;
    logs = newArray;
}
 
Example #19
Source File: TesterHost.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public AccessLog getAccessLog() {
    return null;
}
 
Example #20
Source File: AccessLogAdapter.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
public AccessLogAdapter(AccessLog log) {
    Objects.requireNonNull(log);
    logs = new AccessLog[] { log };
}
 
Example #21
Source File: AccessLogAdapter.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
public void add(AccessLog log) {
    Objects.requireNonNull(log);
    AccessLog newArray[] = Arrays.copyOf(logs, logs.length + 1);
    newArray[newArray.length - 1] = log;
    logs = newArray;
}
 
Example #22
Source File: TesterHost.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public AccessLog getAccessLog() {
    return null;
}
 
Example #23
Source File: TesterContext.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public AccessLog getAccessLog() {
    return null;
}
 
Example #24
Source File: TesterContext.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public AccessLog getAccessLog() {
    return null;
}
 
Example #25
Source File: FailedContext.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Override
public AccessLog getAccessLog() { return null; }
 
Example #26
Source File: AccessLogAdapter.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public AccessLogAdapter(AccessLog log) {
    if (log == null) {
        throw new NullPointerException();
    }
    logs = new AccessLog[] { log };
}
 
Example #27
Source File: FailedContext.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public AccessLog getAccessLog() { return null; }
 
Example #28
Source File: TesterContext.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Override
public AccessLog getAccessLog() {
    return null;
}
 
Example #29
Source File: FailedContext.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public AccessLog getAccessLog() { return null; }
 
Example #30
Source File: AccessLogAdapter.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
public AccessLogAdapter(AccessLog log) {
    if (log == null) {
        throw new NullPointerException();
    }
    logs = new AccessLog[] { log };
}