use of org.apache.servicecomb.core.event.ServerAccessLogEvent in project java-chassis by ServiceComb.
the class UrlPathWithQueryItemTest method initStrBuilder.
@Before
public void initStrBuilder() {
accessLogEvent = new ServerAccessLogEvent();
routingContext = Mockito.mock(RoutingContext.class);
finishEvent = Mockito.mock(InvocationFinishEvent.class);
invocation = Mockito.mock(Invocation.class);
serverRequest = Mockito.mock(HttpServerRequest.class);
accessLogEvent.setRoutingContext(routingContext);
strBuilder = new StringBuilder();
}
use of org.apache.servicecomb.core.event.ServerAccessLogEvent in project incubator-servicecomb-java-chassis by apache.
the class RestServerVerticle method mountAccessLogHandler.
private void mountAccessLogHandler(Router mainRouter) {
if (!AccessLogConfig.INSTANCE.isServerLogEnabled()) {
return;
}
LOGGER.info("access log enabled, pattern = {}", AccessLogConfig.INSTANCE.getServerLogPattern());
mainRouter.route().handler(context -> {
ServerAccessLogEvent accessLogEvent = new ServerAccessLogEvent().setRoutingContext(context).setMilliStartTime(System.currentTimeMillis()).setLocalAddress(LocalHostAccessItem.getLocalAddress(context));
context.response().endHandler(event -> EventManager.post(accessLogEvent.setMilliEndTime(System.currentTimeMillis())));
context.next();
});
}
use of org.apache.servicecomb.core.event.ServerAccessLogEvent in project incubator-servicecomb-java-chassis by apache.
the class ResponseSizeItemTest method initStrBuilder.
@Before
public void initStrBuilder() {
routingContext = Mockito.mock(RoutingContext.class);
finishEvent = Mockito.mock(InvocationFinishEvent.class);
serverResponse = Mockito.mock(HttpServerResponse.class);
accessLogEvent = new ServerAccessLogEvent();
accessLogEvent.setRoutingContext(routingContext);
strBuilder = new StringBuilder();
}
use of org.apache.servicecomb.core.event.ServerAccessLogEvent in project incubator-servicecomb-java-chassis by apache.
the class UrlPathWithQueryItemTest method initStrBuilder.
@Before
public void initStrBuilder() {
accessLogEvent = new ServerAccessLogEvent();
routingContext = Mockito.mock(RoutingContext.class);
finishEvent = Mockito.mock(InvocationFinishEvent.class);
invocation = Mockito.mock(Invocation.class);
serverRequest = Mockito.mock(HttpServerRequest.class);
accessLogEvent.setRoutingContext(routingContext);
strBuilder = new StringBuilder();
}
use of org.apache.servicecomb.core.event.ServerAccessLogEvent in project incubator-servicecomb-java-chassis by apache.
the class AccessLogGeneratorTest method testServerLog.
@Test
public void testServerLog() {
RoutingContext context = Mockito.mock(RoutingContext.class);
HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
long startMillisecond = 1416863450581L;
ServerAccessLogEvent serverAccessLogEvent = new ServerAccessLogEvent();
serverAccessLogEvent.setMilliStartTime(startMillisecond).setRoutingContext(context);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(ConfigurableDatetimeAccessItem.DEFAULT_DATETIME_PATTERN, ConfigurableDatetimeAccessItem.DEFAULT_LOCALE);
simpleDateFormat.setTimeZone(TimeZone.getDefault());
when(context.request()).thenReturn(request);
when(request.method()).thenReturn(HttpMethod.DELETE);
String log = LOG_GENERATOR.generateServerLog(serverAccessLogEvent);
Assert.assertEquals("DELETE" + " - " + simpleDateFormat.format(startMillisecond), log);
}
Aggregations