Search in sources :

Example 36 with ServerAccessLogEvent

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();
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) ServerAccessLogEvent(org.apache.servicecomb.core.event.ServerAccessLogEvent) InvocationFinishEvent(org.apache.servicecomb.core.event.InvocationFinishEvent) Invocation(org.apache.servicecomb.core.Invocation) HttpServerRequest(io.vertx.core.http.HttpServerRequest) Before(org.junit.Before)

Example 37 with ServerAccessLogEvent

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();
    });
}
Also used : ServerAccessLogEvent(org.apache.servicecomb.core.event.ServerAccessLogEvent)

Example 38 with ServerAccessLogEvent

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();
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) InvocationFinishEvent(org.apache.servicecomb.core.event.InvocationFinishEvent) ServerAccessLogEvent(org.apache.servicecomb.core.event.ServerAccessLogEvent) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Before(org.junit.Before)

Example 39 with ServerAccessLogEvent

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();
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) ServerAccessLogEvent(org.apache.servicecomb.core.event.ServerAccessLogEvent) InvocationFinishEvent(org.apache.servicecomb.core.event.InvocationFinishEvent) Invocation(org.apache.servicecomb.core.Invocation) HttpServerRequest(io.vertx.core.http.HttpServerRequest) Before(org.junit.Before)

Example 40 with ServerAccessLogEvent

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);
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) ServerAccessLogEvent(org.apache.servicecomb.core.event.ServerAccessLogEvent) HttpServerRequest(io.vertx.core.http.HttpServerRequest) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Aggregations

ServerAccessLogEvent (org.apache.servicecomb.core.event.ServerAccessLogEvent)48 Before (org.junit.Before)44 InvocationFinishEvent (org.apache.servicecomb.core.event.InvocationFinishEvent)42 RoutingContext (io.vertx.ext.web.RoutingContext)36 Invocation (org.apache.servicecomb.core.Invocation)34 HttpServerRequest (io.vertx.core.http.HttpServerRequest)20 RestClientRequestImpl (org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl)16 HttpClientRequest (io.vertx.core.http.HttpClientRequest)14 Endpoint (org.apache.servicecomb.core.Endpoint)10 HashMap (java.util.HashMap)8 URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)8 HttpServerResponse (io.vertx.core.http.HttpServerResponse)6 SocketAddress (io.vertx.core.net.SocketAddress)6 InvocationStageTrace (org.apache.servicecomb.core.invocation.InvocationStageTrace)6 HttpConnection (io.vertx.core.http.HttpConnection)4 Response (org.apache.servicecomb.swagger.invocation.Response)4 Swagger (io.swagger.models.Swagger)2 MultiMap (io.vertx.core.MultiMap)2 HeadersMultiMap (io.vertx.core.http.impl.headers.HeadersMultiMap)2 SimpleDateFormat (java.text.SimpleDateFormat)2