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