Search in sources :

Example 1 with StandardHttpServletRequestEx

use of org.apache.servicecomb.foundation.vertx.http.StandardHttpServletRequestEx in project incubator-servicecomb-java-chassis by apache.

the class TestRestServletProducerInvocation method findRestOperationCacheTrue.

@Test
public void findRestOperationCacheTrue(@Mocked HttpServletRequest request, @Mocked HttpServerFilter f1) {
    HttpServletRequestEx requestEx = new StandardHttpServletRequestEx(request);
    Deencapsulation.setField(restInvocation, "requestEx", requestEx);
    new MockUp<RestProducerInvocation>() {

        @Mock
        void findRestOperation() {
            Deencapsulation.setField(getMockInstance(), "restOperationMeta", restOperationMeta);
        }
    };
    List<HttpServerFilter> httpServerFilters = Arrays.asList(f1);
    new Expectations() {

        {
            f1.needCacheRequest(operationMeta);
            result = true;
        }
    };
    restInvocation.setHttpServerFilters(httpServerFilters);
    restInvocation.findRestOperation();
    Assert.assertTrue(Deencapsulation.getField(requestEx, "cacheRequest"));
}
Also used : Expectations(mockit.Expectations) HttpServerFilter(org.apache.servicecomb.common.rest.filter.HttpServerFilter) MockUp(mockit.MockUp) StandardHttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.StandardHttpServletRequestEx) HttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx) StandardHttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.StandardHttpServletRequestEx) Test(org.junit.Test)

Example 2 with StandardHttpServletRequestEx

use of org.apache.servicecomb.foundation.vertx.http.StandardHttpServletRequestEx in project incubator-servicecomb-java-chassis by apache.

the class ServletRestDispatcher method service.

public void service(HttpServletRequest request, HttpServletResponse response) {
    if (transport == null) {
        transport = CseContext.getInstance().getTransportManager().findTransport(Const.RESTFUL);
    }
    // 异步场景
    final AsyncContext asyncCtx = request.startAsync();
    asyncCtx.addListener(restAsyncListener);
    asyncCtx.setTimeout(ServletConfig.getServerTimeout());
    HttpServletRequestEx requestEx = new StandardHttpServletRequestEx(request);
    HttpServletResponseEx responseEx = new StandardHttpServletResponseEx(response);
    RestServletProducerInvocation restProducerInvocation = new RestServletProducerInvocation();
    restProducerInvocation.invoke(transport, requestEx, responseEx, httpServerFilters);
}
Also used : HttpServletResponseEx(org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx) StandardHttpServletResponseEx(org.apache.servicecomb.foundation.vertx.http.StandardHttpServletResponseEx) StandardHttpServletResponseEx(org.apache.servicecomb.foundation.vertx.http.StandardHttpServletResponseEx) AsyncContext(javax.servlet.AsyncContext) StandardHttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.StandardHttpServletRequestEx) HttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx) StandardHttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.StandardHttpServletRequestEx)

Example 3 with StandardHttpServletRequestEx

use of org.apache.servicecomb.foundation.vertx.http.StandardHttpServletRequestEx in project java-chassis by ServiceComb.

the class ServletRestDispatcher method service.

public void service(HttpServletRequest request, HttpServletResponse response) {
    if (transport == null) {
        transport = SCBEngine.getInstance().getTransportManager().findTransport(Const.RESTFUL);
        microserviceMeta = SCBEngine.getInstance().getProducerMicroserviceMeta();
    }
    // 异步场景
    AsyncContext asyncCtx = request.startAsync();
    asyncCtx.addListener(restAsyncListener);
    asyncCtx.setTimeout(ServletConfig.getAsyncServletTimeout());
    HttpServletRequestEx requestEx = new StandardHttpServletRequestEx(request);
    HttpServletResponseEx responseEx = new StandardHttpServletResponseEx(response);
    if (SCBEngine.getInstance().isFilterChainEnabled()) {
        ((StandardHttpServletRequestEx) requestEx).setCacheRequest(true);
        InvocationCreator creator = new RestServletProducerInvocationCreator(microserviceMeta, transport.getEndpoint(), requestEx, responseEx);
        new RestProducerInvocationFlow(creator, requestEx, responseEx).run();
        return;
    }
    RestServletProducerInvocation restProducerInvocation = new RestServletProducerInvocation();
    restProducerInvocation.invoke(transport, requestEx, responseEx, httpServerFilters);
}
Also used : RestProducerInvocationFlow(org.apache.servicecomb.common.rest.RestProducerInvocationFlow) HttpServletResponseEx(org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx) StandardHttpServletResponseEx(org.apache.servicecomb.foundation.vertx.http.StandardHttpServletResponseEx) StandardHttpServletResponseEx(org.apache.servicecomb.foundation.vertx.http.StandardHttpServletResponseEx) InvocationCreator(org.apache.servicecomb.core.invocation.InvocationCreator) AsyncContext(javax.servlet.AsyncContext) StandardHttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.StandardHttpServletRequestEx) HttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx) StandardHttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.StandardHttpServletRequestEx)

Example 4 with StandardHttpServletRequestEx

use of org.apache.servicecomb.foundation.vertx.http.StandardHttpServletRequestEx in project java-chassis by ServiceComb.

the class TestRestServletProducerInvocation method findRestOperationCacheTrue.

@Test
public void findRestOperationCacheTrue(@Mocked HttpServletRequest request, @Mocked HttpServerFilter f1) {
    HttpServletRequestEx requestEx = new StandardHttpServletRequestEx(request);
    Deencapsulation.setField(restInvocation, "requestEx", requestEx);
    new MockUp<RestProducerInvocation>() {

        @Mock
        void findRestOperation() {
            Deencapsulation.setField(getMockInstance(), "restOperationMeta", restOperationMeta);
        }
    };
    List<HttpServerFilter> httpServerFilters = Arrays.asList(f1);
    new Expectations() {

        {
            f1.needCacheRequest(operationMeta);
            result = true;
        }
    };
    restInvocation.setHttpServerFilters(httpServerFilters);
    restInvocation.findRestOperation();
    Assert.assertTrue(Deencapsulation.getField(requestEx, "cacheRequest"));
}
Also used : Expectations(mockit.Expectations) HttpServerFilter(org.apache.servicecomb.common.rest.filter.HttpServerFilter) MockUp(mockit.MockUp) StandardHttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.StandardHttpServletRequestEx) HttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx) StandardHttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.StandardHttpServletRequestEx) Test(org.junit.Test)

Aggregations

HttpServletRequestEx (org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx)4 StandardHttpServletRequestEx (org.apache.servicecomb.foundation.vertx.http.StandardHttpServletRequestEx)4 AsyncContext (javax.servlet.AsyncContext)2 Expectations (mockit.Expectations)2 MockUp (mockit.MockUp)2 HttpServerFilter (org.apache.servicecomb.common.rest.filter.HttpServerFilter)2 HttpServletResponseEx (org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx)2 StandardHttpServletResponseEx (org.apache.servicecomb.foundation.vertx.http.StandardHttpServletResponseEx)2 Test (org.junit.Test)2 RestProducerInvocationFlow (org.apache.servicecomb.common.rest.RestProducerInvocationFlow)1 InvocationCreator (org.apache.servicecomb.core.invocation.InvocationCreator)1