Search in sources :

Example 1 with RestProducerInvocation

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);
}
Also used : Expectations(mockit.Expectations) RestProducerInvocation(org.apache.servicecomb.common.rest.RestProducerInvocation) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) ErrorDataDecoderException(io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.ErrorDataDecoderException) ErrorDataDecoderException(io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.ErrorDataDecoderException) Test(org.junit.Test)

Example 2 with RestProducerInvocation

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));
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) RestProducerInvocation(org.apache.servicecomb.common.rest.RestProducerInvocation) Invocation(org.apache.servicecomb.core.Invocation) HashMap(java.util.HashMap) AccessLogParam(org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam) RestProducerInvocation(org.apache.servicecomb.common.rest.RestProducerInvocation) Test(org.junit.Test)

Example 3 with RestProducerInvocation

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("-"));
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) RestProducerInvocation(org.apache.servicecomb.common.rest.RestProducerInvocation) Invocation(org.apache.servicecomb.core.Invocation) HashMap(java.util.HashMap) AccessLogParam(org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam) RestProducerInvocation(org.apache.servicecomb.common.rest.RestProducerInvocation) Test(org.junit.Test)

Example 4 with RestProducerInvocation

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;
}
Also used : RestProducerInvocation(org.apache.servicecomb.common.rest.RestProducerInvocation)

Example 5 with RestProducerInvocation

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);
}
Also used : VertxServerResponseToHttpServletResponse(org.apache.servicecomb.foundation.vertx.http.VertxServerResponseToHttpServletResponse) HttpServletResponseEx(org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx) RestProducerInvocation(org.apache.servicecomb.common.rest.RestProducerInvocation) HttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx) VertxServerRequestToHttpServletRequest(org.apache.servicecomb.foundation.vertx.http.VertxServerRequestToHttpServletRequest)

Aggregations

RestProducerInvocation (org.apache.servicecomb.common.rest.RestProducerInvocation)10 Test (org.junit.Test)8 ErrorDataDecoderException (io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.ErrorDataDecoderException)6 Expectations (mockit.Expectations)6 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)4 RoutingContext (io.vertx.ext.web.RoutingContext)2 HashMap (java.util.HashMap)2 Invocation (org.apache.servicecomb.core.Invocation)2 AccessLogParam (org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam)2 HttpServletRequestEx (org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx)1 HttpServletResponseEx (org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx)1 VertxServerRequestToHttpServletRequest (org.apache.servicecomb.foundation.vertx.http.VertxServerRequestToHttpServletRequest)1 VertxServerResponseToHttpServletResponse (org.apache.servicecomb.foundation.vertx.http.VertxServerResponseToHttpServletResponse)1