Search in sources :

Example 46 with RestOperationMeta

use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.

the class TestDefaultHttpClientFilter method extractResult_decodeError200.

@Test
public void extractResult_decodeError200(@Mocked Invocation invocation, @Mocked ReadStreamPart part, @Mocked OperationMeta operationMeta, @Mocked RestOperationMeta swaggerRestOperation, @Mocked HttpServletResponseEx responseEx) {
    Map<String, Object> handlerContext = new HashMap<>();
    new Expectations() {

        {
            invocation.getHandlerContext();
            result = handlerContext;
            invocation.getOperationMeta();
            result = operationMeta;
            invocation.findResponseType(200);
            result = SimpleType.constructUnsafe(Date.class);
            operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
            result = swaggerRestOperation;
            responseEx.getStatus();
            result = 200;
            responseEx.getBodyBuffer();
            result = new BufferImpl().appendString("abc");
        }
    };
    new MockUp<DefaultHttpClientFilter>() {

        @Mock
        ProduceProcessor findProduceProcessor(RestOperationMeta restOperation, HttpServletResponseEx responseEx) {
            return new ProduceJsonProcessor();
        }
    };
    Response response = filter.extractResponse(invocation, responseEx);
    Assert.assertEquals(400, response.getStatusCode());
    Assert.assertEquals(InvocationException.class, response.<InvocationException>getResult().getClass());
    InvocationException invocationException = response.getResult();
    Assert.assertEquals("InvocationException: code=400;msg=CommonExceptionData [message=method null, path null, statusCode 200, reasonPhrase null, response content-type null is not supported]", invocationException.getMessage());
    Assert.assertEquals("Unrecognized token 'abc': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n" + " at [Source: (org.apache.servicecomb.foundation.vertx.stream.BufferInputStream); line: 1, column: 4]", invocationException.getCause().getMessage());
    Assert.assertEquals(CommonExceptionData.class, invocationException.getErrorData().getClass());
    CommonExceptionData commonExceptionData = (CommonExceptionData) invocationException.getErrorData();
    Assert.assertEquals("method null, path null, statusCode 200, reasonPhrase null, response content-type null is not supported", commonExceptionData.getMessage());
}
Also used : Expectations(mockit.Expectations) ProduceJsonProcessor(org.apache.servicecomb.common.rest.codec.produce.ProduceJsonProcessor) HashMap(java.util.HashMap) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) MockUp(mockit.MockUp) BufferImpl(io.vertx.core.buffer.impl.BufferImpl) Date(java.util.Date) Response(org.apache.servicecomb.swagger.invocation.Response) HttpServletResponseEx(org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) CommonExceptionData(org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData) Test(org.junit.Test)

Example 47 with RestOperationMeta

use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.

the class RestServerCodecFilter method decodeRequest.

protected Void decodeRequest(Invocation invocation) {
    HttpServletRequestEx requestEx = invocation.getRequestEx();
    OperationMeta operationMeta = invocation.getOperationMeta();
    RestOperationMeta restOperationMeta = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
    Map<String, Object> swaggerArguments = RestCodec.restToArgs(requestEx, restOperationMeta);
    invocation.setSwaggerArguments(swaggerArguments);
    return null;
}
Also used : RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) HttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx)

Example 48 with RestOperationMeta

use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project incubator-servicecomb-java-chassis by apache.

the class ServerRestArgsFilter method afterReceiveRequest.

@Override
public Response afterReceiveRequest(Invocation invocation, HttpServletRequestEx requestEx) {
    OperationMeta operationMeta = invocation.getOperationMeta();
    RestOperationMeta restOperationMeta = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
    Map<String, Object> swaggerArguments = RestCodec.restToArgs(requestEx, restOperationMeta);
    invocation.setSwaggerArguments(swaggerArguments);
    return null;
}
Also used : RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta)

Example 49 with RestOperationMeta

use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project incubator-servicecomb-java-chassis by apache.

the class ServicePathManager method addSchema.

private void addSchema(SchemaMeta schemaMeta) {
    for (OperationMeta operationMeta : schemaMeta.getOperations().values()) {
        RestOperationMeta restOperationMeta = new RestOperationMeta();
        restOperationMeta.init(operationMeta);
        operationMeta.putExtData(RestConst.SWAGGER_REST_OPERATION, restOperationMeta);
        addResource(restOperationMeta);
    }
    LOGGER.info("add schema to service paths. {}:{}:{}.", schemaMeta.getAppId(), schemaMeta.getMicroserviceName(), schemaMeta.getSchemaId());
}
Also used : RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta)

Example 50 with RestOperationMeta

use of org.apache.servicecomb.common.rest.definition.RestOperationMeta in project incubator-servicecomb-java-chassis by apache.

the class RestServerCodecFilter method decodeRequest.

protected Void decodeRequest(Invocation invocation) {
    HttpServletRequestEx requestEx = invocation.getRequestEx();
    OperationMeta operationMeta = invocation.getOperationMeta();
    RestOperationMeta restOperationMeta = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
    Map<String, Object> swaggerArguments = RestCodec.restToArgs(requestEx, restOperationMeta);
    invocation.setSwaggerArguments(swaggerArguments);
    return null;
}
Also used : RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) HttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx)

Aggregations

RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)55 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)24 Test (org.junit.Test)20 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)10 Response (org.apache.servicecomb.swagger.invocation.Response)9 CommonExceptionData (org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData)9 InvocationStageTrace (org.apache.servicecomb.core.invocation.InvocationStageTrace)8 HttpClientWithContext (org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext)7 Invocation (org.apache.servicecomb.core.Invocation)6 URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)6 HttpServletResponseEx (org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx)6 HttpClientRequest (io.vertx.core.http.HttpClientRequest)5 HttpMethod (io.vertx.core.http.HttpMethod)5 HashMap (java.util.HashMap)5 RestClientRequestImpl (org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl)5 ProduceProcessor (org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor)5 HttpServletRequestEx (org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx)5 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)5 HttpClientResponse (io.vertx.core.http.HttpClientResponse)4 RequestOptions (io.vertx.core.http.RequestOptions)4