Search in sources :

Example 1 with HttpServletResponseEx

use of org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx 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)

Example 2 with HttpServletResponseEx

use of org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx 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 HttpServletResponseEx

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

the class TestAbstractRestInvocation method testDoSendResponseResultOKFilter.

@Test
public void testDoSendResponseResultOKFilter(@Mocked Response response) throws Exception {
    Headers headers = new Headers();
    headers.addHeader("Content-Type", "application/json");
    new Expectations() {

        {
            response.getHeaders();
            result = headers;
            response.getStatusCode();
            result = 123;
            response.getReasonPhrase();
            result = "reason";
            response.getResult();
            result = "ok";
        }
    };
    Buffer buffer = Buffer.buffer();
    responseEx = new MockUp<HttpServletResponseEx>() {

        private Map<String, Object> attributes = new HashMap<>();

        @Mock
        public void setAttribute(String key, Object value) {
            this.attributes.put(key, value);
        }

        @Mock
        public Object getAttribute(String key) {
            return this.attributes.get(key);
        }

        @Mock
        void setBodyBuffer(Buffer bodyBuffer) {
            buffer.appendBuffer(bodyBuffer);
        }
    }.getMockInstance();
    HttpServerFilter filter = new MockUp<HttpServerFilter>() {

        @Mock
        void beforeSendResponse(Invocation invocation, HttpServletResponseEx responseEx) {
            buffer.appendString("-filter");
        }
    }.getMockInstance();
    initRestInvocation();
    List<HttpServerFilter> httpServerFilters = SPIServiceUtils.loadSortedService(HttpServerFilter.class);
    httpServerFilters.add(filter);
    restInvocation.setHttpServerFilters(httpServerFilters);
    restInvocation.sendResponse(response);
    Assert.assertEquals("\"ok\"-filter", buffer.toString());
}
Also used : Expectations(mockit.Expectations) Buffer(io.vertx.core.buffer.Buffer) HttpServerFilter(org.apache.servicecomb.common.rest.filter.HttpServerFilter) Invocation(org.apache.servicecomb.core.Invocation) Headers(org.apache.servicecomb.swagger.invocation.response.Headers) MockUp(mockit.MockUp) Mock(mockit.Mock) HttpServletResponseEx(org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

HttpServletResponseEx (org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx)3 HttpServletRequestEx (org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx)2 Buffer (io.vertx.core.buffer.Buffer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AsyncContext (javax.servlet.AsyncContext)1 Expectations (mockit.Expectations)1 Mock (mockit.Mock)1 MockUp (mockit.MockUp)1 RestProducerInvocation (org.apache.servicecomb.common.rest.RestProducerInvocation)1 HttpServerFilter (org.apache.servicecomb.common.rest.filter.HttpServerFilter)1 Invocation (org.apache.servicecomb.core.Invocation)1 StandardHttpServletRequestEx (org.apache.servicecomb.foundation.vertx.http.StandardHttpServletRequestEx)1 StandardHttpServletResponseEx (org.apache.servicecomb.foundation.vertx.http.StandardHttpServletResponseEx)1 VertxServerRequestToHttpServletRequest (org.apache.servicecomb.foundation.vertx.http.VertxServerRequestToHttpServletRequest)1 VertxServerResponseToHttpServletResponse (org.apache.servicecomb.foundation.vertx.http.VertxServerResponseToHttpServletResponse)1 Headers (org.apache.servicecomb.swagger.invocation.response.Headers)1 Test (org.junit.Test)1