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());
}
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);
}
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);
}
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;
}
}
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());
}
Aggregations