use of org.apache.servicecomb.common.rest.RestProducerInvocation in project incubator-servicecomb-java-chassis by apache.
the class TestVertxRestDispatcher method failureHandlerErrorDataWithNormal.
@Test
public void failureHandlerErrorDataWithNormal(@Mocked RoutingContext context) {
RestProducerInvocation restProducerInvocation = new RestProducerInvocation();
Exception e = new Exception();
ErrorDataDecoderException edde = new ErrorDataDecoderException(e);
new Expectations() {
{
context.get(RestConst.REST_PRODUCER_INVOCATION);
result = restProducerInvocation;
context.failure();
returns(edde, edde);
}
};
Deencapsulation.invoke(dispatcher, "failureHandler", context);
Assert.assertSame(edde, this.throwable);
}
use of org.apache.servicecomb.common.rest.RestProducerInvocation in project incubator-servicecomb-java-chassis by apache.
the class TraceIdItemTest method testGetFormattedElement.
@Test
public void testGetFormattedElement() {
AccessLogParam<RoutingContext> param = new AccessLogParam<>();
RoutingContext routingContext = Mockito.mock(RoutingContext.class);
Map<String, Object> data = new HashMap<>();
RestProducerInvocation restProducerInvocation = new RestProducerInvocation();
Invocation invocation = Mockito.mock(Invocation.class);
String traceIdTest = "traceIdTest";
Mockito.when(invocation.getContext(Const.TRACE_ID_NAME)).thenReturn(traceIdTest);
Deencapsulation.setField(restProducerInvocation, "invocation", invocation);
Mockito.when(routingContext.data()).thenReturn(data);
data.put("servicecomb-rest-producer-invocation", restProducerInvocation);
param.setContextData(routingContext);
String result = ELEMENT.getFormattedItem(param);
Assert.assertThat(result, is(traceIdTest));
}
use of org.apache.servicecomb.common.rest.RestProducerInvocation in project incubator-servicecomb-java-chassis by apache.
the class TraceIdItemTest method testGetFormattedElementOnTraceIdNotFound.
@Test
public void testGetFormattedElementOnTraceIdNotFound() {
AccessLogParam<RoutingContext> param = new AccessLogParam<>();
RoutingContext routingContext = Mockito.mock(RoutingContext.class);
Map<String, Object> data = new HashMap<>();
RestProducerInvocation restProducerInvocation = new RestProducerInvocation();
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getContext(Const.TRACE_ID_NAME)).thenReturn("");
Deencapsulation.setField(restProducerInvocation, "invocation", invocation);
Mockito.when(routingContext.data()).thenReturn(data);
data.put("servicecomb-rest-producer-invocation", restProducerInvocation);
param.setContextData(routingContext);
String result = ELEMENT.getFormattedItem(param);
Assert.assertThat(result, is("-"));
Mockito.when(invocation.getContext(Const.TRACE_ID_NAME)).thenReturn(null);
result = ELEMENT.getFormattedItem(param);
Assert.assertThat(result, is("-"));
}
use of org.apache.servicecomb.common.rest.RestProducerInvocation in project incubator-servicecomb-java-chassis by apache.
the class TraceIdItem method getFormattedItem.
@Override
public String getFormattedItem(AccessLogParam<RoutingContext> accessLogParam) {
Map<String, Object> data = accessLogParam.getContextData().data();
if (null == data) {
return TRACE_ID_NOT_FOUND;
}
RestProducerInvocation restProducerInvocation = (RestProducerInvocation) data.get("servicecomb-rest-producer-invocation");
if (null == restProducerInvocation) {
return TRACE_ID_NOT_FOUND;
}
String traceId = restProducerInvocation.getContext("X-B3-TraceId");
if (StringUtils.isEmpty(traceId)) {
return TRACE_ID_NOT_FOUND;
}
return traceId;
}
use of org.apache.servicecomb.common.rest.RestProducerInvocation in project incubator-servicecomb-java-chassis by apache.
the class VertxRestDispatcher method onRequest.
private void onRequest(RoutingContext context) {
if (transport == null) {
transport = CseContext.getInstance().getTransportManager().findTransport(Const.RESTFUL);
}
HttpServletRequestEx requestEx = new VertxServerRequestToHttpServletRequest(context);
HttpServletResponseEx responseEx = new VertxServerResponseToHttpServletResponse(context.response());
RestProducerInvocation restProducerInvocation = new RestProducerInvocation();
context.put(RestConst.REST_PRODUCER_INVOCATION, restProducerInvocation);
restProducerInvocation.invoke(transport, requestEx, responseEx, httpServerFilters);
}
Aggregations