Search in sources :

Example 16 with InvocationException

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

the class TestConfig method testResponse.

@Test
public void testResponse() {
    Response response = Response.create(400, "test", null);
    InvocationException exception = response.getResult();
    Assert.assertEquals(null, exception.getErrorData());
    response = Response.create(400, "test", "errorData");
    exception = response.getResult();
    Assert.assertEquals("errorData", exception.getErrorData());
}
Also used : Response(org.apache.servicecomb.swagger.invocation.Response) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) Test(org.junit.Test)

Example 17 with InvocationException

use of org.apache.servicecomb.swagger.invocation.exception.InvocationException 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 18 with InvocationException

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

the class AbstractRestInvocation method findRestOperation.

protected void findRestOperation(MicroserviceMeta microserviceMeta) {
    ServicePathManager servicePathManager = ServicePathManager.getServicePathManager(microserviceMeta);
    if (servicePathManager == null) {
        LOGGER.error("No schema defined for {}:{}.", microserviceMeta.getAppId(), microserviceMeta.getName());
        throw new InvocationException(Status.NOT_FOUND, Status.NOT_FOUND.getReasonPhrase());
    }
    OperationLocator locator = locateOperation(servicePathManager);
    requestEx.setAttribute(RestConst.PATH_PARAMETERS, locator.getPathVarMap());
    this.restOperationMeta = locator.getOperation();
}
Also used : OperationLocator(org.apache.servicecomb.common.rest.locator.OperationLocator) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) ServicePathManager(org.apache.servicecomb.common.rest.locator.ServicePathManager)

Example 19 with InvocationException

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

the class RestCodec method restToArgs.

public static Object[] restToArgs(HttpServletRequest request, RestOperationMeta restOperation) throws InvocationException {
    List<RestParam> paramList = restOperation.getParamList();
    try {
        Object[] paramValues = new Object[paramList.size()];
        for (int idx = 0; idx < paramList.size(); idx++) {
            RestParam param = paramList.get(idx);
            paramValues[idx] = param.getParamProcessor().getValue(request);
        }
        return paramValues;
    } catch (Exception e) {
        LOG.error("Parameter is not valid for operation {}. ", restOperation.getOperationMeta().getMicroserviceQualifiedName(), e);
        throw ExceptionFactory.convertProducerException(e, "Parameter is not valid.");
    }
}
Also used : InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) RestParam(org.apache.servicecomb.common.rest.definition.RestParam)

Example 20 with InvocationException

use of org.apache.servicecomb.swagger.invocation.exception.InvocationException 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)

Aggregations

InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)24 Test (org.junit.Test)16 Response (org.apache.servicecomb.swagger.invocation.Response)8 CommonExceptionData (org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData)8 MockUp (mockit.MockUp)5 Invocation (org.apache.servicecomb.core.Invocation)5 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)5 Expectations (mockit.Expectations)3 RestParam (org.apache.servicecomb.common.rest.definition.RestParam)3 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)3 HystrixCommandProperties (com.netflix.hystrix.HystrixCommandProperties)2 ArrayList (java.util.ArrayList)2 Holder (javax.xml.ws.Holder)2 AbstractTcpClientPackage (org.apache.servicecomb.foundation.vertx.client.tcp.AbstractTcpClientPackage)2 TcpResponseCallback (org.apache.servicecomb.foundation.vertx.client.tcp.TcpResponseCallback)2 Buffer (io.vertx.core.buffer.Buffer)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Status (javax.ws.rs.core.Response.Status)1 Mock (mockit.Mock)1 WrapSchema (org.apache.servicecomb.codec.protobuf.utils.WrapSchema)1