Search in sources :

Example 1 with AccessLogEntry

use of com.yahoo.container.logging.AccessLogEntry in project vespa by vespa-engine.

the class ProcessingHandlerTestCase method processing_handler_stores_trace_log_values_in_the_access_log_entry.

@Test
public void processing_handler_stores_trace_log_values_in_the_access_log_entry() throws InterruptedException {
    ArgumentCaptor<AccessLogEntry> accessLogEntryCaptor = ArgumentCaptor.forClass(AccessLogEntry.class);
    AccessLogInterface accessLog = Mockito.mock(AccessLogInterface.class);
    driver = new ProcessingTestDriver(logValueChain, accessLog);
    driver.sendRequest("http://localhost/?chain=log-value").readAll();
    Mockito.verify(accessLog, times(1)).log(accessLogEntryCaptor.capture());
    AccessLogEntry entry = accessLogEntryCaptor.getValue();
    assertNotNull(entry);
    assertThat(entry.getKeyValues().get(LOG_KEY), is(Collections.singletonList(LOG_VALUE)));
}
Also used : AccessLogInterface(com.yahoo.container.logging.AccessLogInterface) AccessLogEntry(com.yahoo.container.logging.AccessLogEntry) Test(org.junit.Test)

Example 2 with AccessLogEntry

use of com.yahoo.container.logging.AccessLogEntry in project vespa by vespa-engine.

the class AccessLogRequestLogTest method raw_path_and_query_are_set_from_request.

@Test
public void raw_path_and_query_are_set_from_request() {
    HttpServletRequest httpServletRequest = mock(HttpServletRequest.class);
    String rawPath = "//search/";
    when(httpServletRequest.getRequestURI()).thenReturn(rawPath);
    String rawQuery = "q=%%2";
    when(httpServletRequest.getQueryString()).thenReturn(rawQuery);
    AccessLogEntry accessLogEntry = new AccessLogEntry();
    AccessLogRequestLog.populateAccessLogEntryFromHttpServletRequest(httpServletRequest, accessLogEntry);
    assertThat(accessLogEntry.getRawPath(), is(rawPath));
    Optional<String> actualRawQuery = accessLogEntry.getRawQuery();
    assertThat(actualRawQuery.isPresent(), is(true));
    assertThat(actualRawQuery.get(), is(rawQuery));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AccessLogEntry(com.yahoo.container.logging.AccessLogEntry) Test(org.testng.annotations.Test)

Example 3 with AccessLogEntry

use of com.yahoo.container.logging.AccessLogEntry in project vespa by vespa-engine.

the class AccessLogRequestLog method log.

@Override
public void log(final Request request, final Response response) {
    try {
        final AccessLogEntry accessLogEntryFromServletRequest = (AccessLogEntry) request.getAttribute(JDiscHttpServlet.ATTRIBUTE_NAME_ACCESS_LOG_ENTRY);
        final AccessLogEntry accessLogEntry;
        if (accessLogEntryFromServletRequest != null) {
            accessLogEntry = accessLogEntryFromServletRequest;
        } else {
            accessLogEntry = new AccessLogEntry();
            populateAccessLogEntryFromHttpServletRequest(request, accessLogEntry);
        }
        final long startTime = request.getTimeStamp();
        final long endTime = System.currentTimeMillis();
        accessLogEntry.setTimeStamp(startTime);
        accessLogEntry.setDurationBetweenRequestResponse(endTime - startTime);
        accessLogEntry.setReturnedContentSize(response.getContentCount());
        accessLogEntry.setStatusCode(response.getStatus());
        accessLog.log(accessLogEntry);
    } catch (Exception e) {
        // Catching any exceptions here as it is unclear how Jetty handles exceptions from a RequestLog.
        logger.log(Level.SEVERE, "Failed to log access log entry: " + e.getMessage(), e);
    }
}
Also used : AccessLogEntry(com.yahoo.container.logging.AccessLogEntry) URISyntaxException(java.net.URISyntaxException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with AccessLogEntry

use of com.yahoo.container.logging.AccessLogEntry in project vespa by vespa-engine.

the class AccessLogRequestLogTest method requireThatQueryWithUnquotedSpecialCharactersIsHandled.

@Test
public void requireThatQueryWithUnquotedSpecialCharactersIsHandled() {
    final HttpServletRequest httpServletRequest = mock(HttpServletRequest.class);
    when(httpServletRequest.getRequestURI()).thenReturn("/search/");
    when(httpServletRequest.getQueryString()).thenReturn("query=year:>2010");
    final AccessLogEntry accessLogEntry = new AccessLogEntry();
    AccessLogRequestLog.populateAccessLogEntryFromHttpServletRequest(httpServletRequest, accessLogEntry);
    assertThat(accessLogEntry.getURI(), is(not(nullValue())));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AccessLogEntry(com.yahoo.container.logging.AccessLogEntry) Test(org.testng.annotations.Test)

Example 5 with AccessLogEntry

use of com.yahoo.container.logging.AccessLogEntry in project vespa by vespa-engine.

the class AccessLogRequestLogTest method invalid_percent_escape_patterns_in_query_string_are_escaped.

@Test
public void invalid_percent_escape_patterns_in_query_string_are_escaped() {
    HttpServletRequest httpServletRequest = mock(HttpServletRequest.class);
    when(httpServletRequest.getRequestURI()).thenReturn("/search/");
    when(httpServletRequest.getQueryString()).thenReturn("q=%%2");
    AccessLogEntry accessLogEntry = new AccessLogEntry();
    AccessLogRequestLog.populateAccessLogEntryFromHttpServletRequest(httpServletRequest, accessLogEntry);
    assertThat(accessLogEntry.getURI().toString(), is("/search/?q=%25%252"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AccessLogEntry(com.yahoo.container.logging.AccessLogEntry) Test(org.testng.annotations.Test)

Aggregations

AccessLogEntry (com.yahoo.container.logging.AccessLogEntry)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Test (org.testng.annotations.Test)5 AccessLogInterface (com.yahoo.container.logging.AccessLogInterface)1 OverloadException (com.yahoo.jdisc.handler.OverloadException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URISyntaxException (java.net.URISyntaxException)1 Test (org.junit.Test)1