use of io.servicecomb.core.exception.InvocationException in project java-chassis by ServiceComb.
the class AbstractRestServer method findRestOperation.
protected RestOperationMeta findRestOperation(RestServerRequestInternal restRequest) {
String selfName = RegistryUtils.getMicroservice().getServiceName();
MicroserviceMeta selfMicroserviceMeta = CseContext.getInstance().getMicroserviceMetaManager().ensureFindValue(selfName);
ServicePathManager servicePathManager = ServicePathManager.getServicePathManager(selfMicroserviceMeta);
if (servicePathManager == null) {
LOGGER.error("No schema in microservice");
throw new InvocationException(Status.NOT_FOUND, Status.NOT_FOUND.getReasonPhrase());
}
OperationLocator locator = servicePathManager.locateOperation(restRequest.getPath(), restRequest.getMethod());
restRequest.setPathParamMap(locator.getPathVarMap());
return locator.getOperation();
}
use of io.servicecomb.core.exception.InvocationException in project java-chassis by ServiceComb.
the class RestCodec method restToArgs.
public static Object[] restToArgs(RestServerRequest 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, cause " + e.getMessage());
throw ExceptionFactory.convertProducerException(e, "Parameter is not valid.");
}
}
use of io.servicecomb.core.exception.InvocationException in project java-chassis by ServiceComb.
the class AbstractRestServer method locateProduceProcessor.
protected ProduceProcessor locateProduceProcessor(RestServerRequestInternal restRequest, HTTP_RESPONSE httpResponse, RestOperationMeta restOperation, String acceptType) {
ProduceProcessor produceProcessor = restOperation.ensureFindProduceProcessor(acceptType);
if (produceProcessor != null) {
return produceProcessor;
}
String msg = String.format("Accept %s is not supported", acceptType);
InvocationException exception = new InvocationException(Status.NOT_ACCEPTABLE, msg);
sendFailResponse(restRequest, httpResponse, exception);
return null;
}
use of io.servicecomb.core.exception.InvocationException in project java-chassis by ServiceComb.
the class TestRestCodec method testRestToArgsInstanceExcetpion.
@Test
public void testRestToArgsInstanceExcetpion(@Mocked RestServerRequest request, @Mocked RestOperationMeta restOperation, @Mocked RestParam restParam, @Mocked ParamValueProcessor processer) throws Exception {
List<RestParam> params = new ArrayList<>();
params.add(restParam);
InvocationException exception = new InvocationException(Status.BAD_REQUEST, "Parameter is not valid.");
new Expectations() {
{
restOperation.getParamList();
result = params;
restParam.getParamProcessor();
result = processer;
processer.getValue(request);
result = exception;
}
};
boolean success = false;
try {
RestCodec.restToArgs(request, restOperation);
success = true;
} catch (InvocationException e) {
Assert.assertEquals(e.getStatusCode(), Status.BAD_REQUEST.getStatusCode());
}
Assert.assertEquals(success, false);
}
use of io.servicecomb.core.exception.InvocationException in project java-chassis by ServiceComb.
the class TestRestCodec method testRestToArgsExcetpion.
@Test
public void testRestToArgsExcetpion(@Mocked RestServerRequest 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);
}
Aggregations