Skip to content

Commit

Permalink
[SCB-1108]when timeout, the access log status is 200
Browse files Browse the repository at this point in the history
  • Loading branch information
liubao68 committed Jan 10, 2019
1 parent 5f618ab commit c3f21d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@

import org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam;
import org.apache.servicecomb.transport.rest.vertx.accesslog.element.AccessLogItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.vertx.core.http.HttpServerResponse;
import io.vertx.ext.web.RoutingContext;

public class HttpStatusItem implements AccessLogItem<RoutingContext> {
private static Logger LOGGER = LoggerFactory.getLogger(HttpStatusItem.class);

public static final String EMPTY_RESULT = "-";

Expand All @@ -33,7 +36,12 @@ public String getFormattedItem(AccessLogParam<RoutingContext> accessLogParam) {
if (null == response) {
return EMPTY_RESULT;
}

if (response.closed() && !response.ended()) {
LOGGER.warn(
"Response is closed before sending any data. "
+ "Please check idle connection timeout for provider is properly configured.");
return EMPTY_RESULT;
}
return String.valueOf(response.getStatusCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import io.vertx.core.http.HttpServerResponse;
import io.vertx.ext.web.RoutingContext;

public class StatusItemTest {
public class HttpStatusItemTest {

private static final HttpStatusItem STATUS_ELEMENT = new HttpStatusItem();

Expand All @@ -51,12 +51,20 @@ public void getFormattedElement() {
public void getFormattedElementOnResponseIsNull() {
AccessLogParam<RoutingContext> param = new AccessLogParam<>();
RoutingContext context = Mockito.mock(RoutingContext.class);
HttpServerResponse response = Mockito.mock(HttpServerResponse.class);

param.setContextData(context);
Mockito.when(context.response()).thenReturn(null);

String result = STATUS_ELEMENT.getFormattedItem(param);

assertEquals("-", result);

Mockito.when(context.response()).thenReturn(response);
Mockito.when(response.closed()).thenReturn(true);
Mockito.when(response.ended()).thenReturn(false);
result = STATUS_ELEMENT.getFormattedItem(param);

assertEquals("-", result);
}
}

0 comments on commit c3f21d6

Please sign in to comment.