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)));
}
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));
}
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);
}
}
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())));
}
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"));
}
Aggregations