Search in sources :

Example 1 with RestServerRequestInternal

use of io.servicecomb.common.rest.codec.RestServerRequestInternal in project java-chassis by ServiceComb.

the class MockUtil method mockAbstactRestServer.

public void mockAbstactRestServer() {
    new MockUp<AbstractRestServer<HttpServletResponse>>() {

        @Mock
        protected RestOperationMeta findRestOperation(RestServerRequestInternal restRequest) {
            RestOperationMeta restOperationMeta = Mockito.mock(RestOperationMeta.class);
            OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
            Executor executor = Mockito.mock(Executor.class);
            operationMeta.setExecutor(executor);
            return restOperationMeta;
        }
    };
}
Also used : Executor(java.util.concurrent.Executor) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) RestServerRequestInternal(io.servicecomb.common.rest.codec.RestServerRequestInternal) HttpServletResponse(javax.servlet.http.HttpServletResponse) MockUp(mockit.MockUp) OperationMeta(io.servicecomb.core.definition.OperationMeta) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta)

Example 2 with RestServerRequestInternal

use of io.servicecomb.common.rest.codec.RestServerRequestInternal in project java-chassis by ServiceComb.

the class VertxRestServer method failureHandler.

private void failureHandler(RoutingContext context) {
    LOGGER.error("http server failed.", context.failure());
    RestServerRequestInternal restRequest = context.get(REST_REQUEST);
    Throwable e = context.failure();
    if (ErrorDataDecoderException.class.isInstance(e)) {
        Throwable cause = e.getCause();
        if (InvocationException.class.isInstance(cause)) {
            e = cause;
        }
    }
    sendFailResponse(restRequest, context.response(), e);
    // 走到这里,应该都是不可控制的异常,直接关闭连接
    context.response().close();
}
Also used : RestServerRequestInternal(io.servicecomb.common.rest.codec.RestServerRequestInternal)

Example 3 with RestServerRequestInternal

use of io.servicecomb.common.rest.codec.RestServerRequestInternal in project java-chassis by ServiceComb.

the class TestVertxRestServer method testSetHttpRequestContext.

@Test
public void testSetHttpRequestContext() {
    boolean status = false;
    try {
        Invocation invocation = Mockito.mock(Invocation.class);
        RestServerRequestInternal restRequest = Mockito.mock(RestServerRequestInternal.class);
        instance.setHttpRequestContext(invocation, restRequest);
        Assert.assertNotNull(instance);
    } catch (Exception e) {
        status = true;
    }
    Assert.assertFalse(status);
}
Also used : Invocation(io.servicecomb.core.Invocation) RestServerRequestInternal(io.servicecomb.common.rest.codec.RestServerRequestInternal) Test(org.junit.Test)

Example 4 with RestServerRequestInternal

use of io.servicecomb.common.rest.codec.RestServerRequestInternal in project java-chassis by ServiceComb.

the class TestServletRestServer method testSetHttpRequestContext.

@Test
public void testSetHttpRequestContext() {
    boolean status = true;
    try {
        Invocation invocation = Mockito.mock(Invocation.class);
        RestServerRequestInternal restRequest = Mockito.mock(RestServerRequestInternal.class);
        servletRestServer.setHttpRequestContext(invocation, restRequest);
    } catch (Exception exce) {
        Assert.assertNotNull(exce);
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : Invocation(io.servicecomb.core.Invocation) RestServerRequestInternal(io.servicecomb.common.rest.codec.RestServerRequestInternal) Test(org.junit.Test)

Example 5 with RestServerRequestInternal

use of io.servicecomb.common.rest.codec.RestServerRequestInternal in project java-chassis by ServiceComb.

the class ServletRestServer method service.

public void service(HttpServletRequest request, HttpServletResponse response) {
    // 异步场景
    final AsyncContext asyncCtx = request.startAsync();
    asyncCtx.addListener(restAsyncListener);
    asyncCtx.setTimeout(ServletConfig.getServerTimeout());
    RestServerRequestInternal restRequest = new RestServletHttpRequest(request, asyncCtx);
    handleRequest(restRequest, response);
}
Also used : RestServerRequestInternal(io.servicecomb.common.rest.codec.RestServerRequestInternal) AsyncContext(javax.servlet.AsyncContext)

Aggregations

RestServerRequestInternal (io.servicecomb.common.rest.codec.RestServerRequestInternal)7 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)2 Invocation (io.servicecomb.core.Invocation)2 Test (org.junit.Test)2 OperationMeta (io.servicecomb.core.definition.OperationMeta)1 HttpServerResponse (io.vertx.core.http.HttpServerResponse)1 Router (io.vertx.ext.web.Router)1 Executor (java.util.concurrent.Executor)1 AsyncContext (javax.servlet.AsyncContext)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 MockUp (mockit.MockUp)1 Before (org.junit.Before)1