Search in sources :

Example 6 with CommonExceptionData

use of org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData in project incubator-servicecomb-java-chassis by apache.

the class TestDefaultHttpClientFilter method testAfterReceiveResponseNullProduceProcessor.

@Test
public void testAfterReceiveResponseNullProduceProcessor(@Mocked Invocation invocation, @Mocked HttpServletResponseEx responseEx, @Mocked OperationMeta operationMeta, @Mocked RestOperationMeta swaggerRestOperation) throws Exception {
    new Expectations() {

        {
            invocation.getOperationMeta();
            result = operationMeta;
            operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
            result = swaggerRestOperation;
        }
    };
    Response response = filter.afterReceiveResponse(invocation, responseEx);
    InvocationException exception = response.getResult();
    CommonExceptionData data = (CommonExceptionData) exception.getErrorData();
    Assert.assertEquals("method null, path null, statusCode 0, reasonPhrase null, response content-type null is not supported", data.getMessage());
}
Also used : Expectations(mockit.Expectations) Response(org.apache.servicecomb.swagger.invocation.Response) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) CommonExceptionData(org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData) Test(org.junit.Test)

Example 7 with CommonExceptionData

use of org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData in project incubator-servicecomb-java-chassis by apache.

the class TestRestCodec method testRestToArgsExcetpion.

@Test
public void testRestToArgsExcetpion(@Mocked HttpServletRequest request, @Mocked RestOperationMeta restOperation, @Mocked RestParam restParam, @Mocked ParamValueProcessor processer) throws Exception {
    List<RestParam> params = new ArrayList<>();
    params.add(restParam);
    new Expectations() {

        {
            restOperation.getParamList();
            result = params;
            restParam.getParamProcessor();
            result = processer;
            processer.getValue(request);
            result = new Exception("bad request parame");
        }
    };
    boolean success = false;
    try {
        RestCodec.restToArgs(request, restOperation);
        success = true;
    } catch (InvocationException e) {
        Assert.assertEquals(590, e.getStatusCode());
        Assert.assertEquals("Parameter is not valid.", ((CommonExceptionData) e.getErrorData()).getMessage());
    }
    Assert.assertEquals(success, false);
}
Also used : Expectations(mockit.Expectations) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) ArrayList(java.util.ArrayList) CommonExceptionData(org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) RestParam(org.apache.servicecomb.common.rest.definition.RestParam) Test(org.junit.Test)

Example 8 with CommonExceptionData

use of org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData in project incubator-servicecomb-java-chassis by apache.

the class ConsumerQpsFlowControlHandler method handle.

@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {
    if (!Config.INSTANCE.isConsumerEnabled()) {
        invocation.next(asyncResp);
        return;
    }
    QpsController qpsController = qpsControllerMgr.getOrCreate(invocation.getOperationMeta().getMicroserviceQualifiedName());
    if (qpsController.isLimitNewRequest()) {
        // return http status 429
        CommonExceptionData errorData = new CommonExceptionData("rejected by qps flowcontrol");
        asyncResp.consumerFail(new InvocationException(QpsConst.TOO_MANY_REQUESTS_STATUS, errorData));
        return;
    }
    invocation.next(asyncResp);
}
Also used : InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) CommonExceptionData(org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData)

Example 9 with CommonExceptionData

use of org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData in project incubator-servicecomb-java-chassis by apache.

the class ProviderQpsFlowControlHandler method isLimitNewRequest.

private boolean isLimitNewRequest(QpsController qpsController, AsyncResponse asyncResp) {
    if (qpsController.isLimitNewRequest()) {
        CommonExceptionData errorData = new CommonExceptionData("rejected by qps flowcontrol");
        asyncResp.producerFail(new InvocationException(QpsConst.TOO_MANY_REQUESTS_STATUS, errorData));
        return true;
    } else {
        return false;
    }
}
Also used : InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) CommonExceptionData(org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData)

Example 10 with CommonExceptionData

use of org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData in project incubator-servicecomb-java-chassis by apache.

the class TestException method testCommonExceptionData.

@Test
public void testCommonExceptionData() {
    CommonExceptionData oData = new CommonExceptionData();
    oData.setMessage("this is Common exception message");
    Assert.assertEquals("this is Common exception message", oData.getMessage());
    oData = new CommonExceptionData("this is a test");
    Assert.assertEquals("this is a test", oData.getMessage());
    Assert.assertEquals("CommonExceptionData [message=this is a test]", oData.toString());
}
Also used : CommonExceptionData(org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData) Test(org.junit.Test)

Aggregations

CommonExceptionData (org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData)10 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)8 Test (org.junit.Test)6 Response (org.apache.servicecomb.swagger.invocation.Response)4 Expectations (mockit.Expectations)2 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 Holder (javax.xml.ws.Holder)1 ProduceProcessor (org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor)1 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)1 RestParam (org.apache.servicecomb.common.rest.definition.RestParam)1 Invocation (org.apache.servicecomb.core.Invocation)1 SwaggerProducerOperation (org.apache.servicecomb.swagger.engine.SwaggerProducerOperation)1 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)1 ResponseMeta (org.apache.servicecomb.swagger.invocation.response.ResponseMeta)1