use of io.servicecomb.core.exception.CommonExceptionData in project java-chassis by ServiceComb.
the class ClientVerticle method send.
protected void send(Long event) {
User user = new User();
TestRequest request = new TestRequest();
request.setUser(user);
request.setIndex(idx);
request.setData(PojoClient.buffer);
SchemaMeta schemaMeta = config.getMicroserviceMeta().ensureFindSchemaMeta("server");
Object[] args = new Object[] { request };
Invocation invocation = InvocationFactory.forConsumer(config, schemaMeta, "wrapParam", args);
InvokerUtils.reactiveInvoke(invocation, ar -> {
if (ar.isSuccessed()) {
User result = ar.getResult();
if (result.getIndex() != idx) {
System.out.printf("error result:%s, expect idx %d\n", result, idx);
}
} else {
CommonExceptionData data = (CommonExceptionData) ((InvocationException) ar.getResult()).getErrorData();
System.out.println(data.getMessage());
}
send(null);
});
}
use of io.servicecomb.core.exception.CommonExceptionData in project java-chassis by ServiceComb.
the class ConsumerQpsFlowControlHandler method handle.
@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {
if (!Config.INSTANCE.isConsumerEnabled()) {
invocation.next(asyncResp);
return;
}
OperationMeta operationMeta = invocation.getOperationMeta();
QpsController qpsController = qpsControllerMgr.getOrCreate(operationMeta);
if (qpsController.isLimitNewRequest()) {
// 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 io.servicecomb.core.exception.CommonExceptionData in project java-chassis by ServiceComb.
the class ProviderQpsFlowControlHandler method handle.
@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {
if (!Config.INSTANCE.isProviderEnabled()) {
invocation.next(asyncResp);
return;
}
String microServiceName = (String) invocation.getContext(Const.SRC_MICROSERVICE);
if (microServiceName != null && !microServiceName.isEmpty()) {
QpsController qpsController = qpsControllerMgr.getOrCreate(microServiceName);
if (qpsController.isLimitNewRequest()) {
// 429
CommonExceptionData errorData = new CommonExceptionData("rejected by qps flowcontrol");
asyncResp.producerFail(new InvocationException(QpsConst.TOO_MANY_REQUESTS_STATUS, errorData));
return;
}
}
invocation.next(asyncResp);
}
use of io.servicecomb.core.exception.CommonExceptionData in project java-chassis by ServiceComb.
the class TestResponse method testAr.
@Test
public void testAr() {
ar.success(Status.ACCEPTED, 1);
Assert.assertEquals(true, response.isSuccessed());
Assert.assertEquals(false, response.isFailed());
Assert.assertEquals(1, (int) response.getResult());
Assert.assertEquals(Status.ACCEPTED.getStatusCode(), response.getStatusCode());
Assert.assertEquals(Status.ACCEPTED.getReasonPhrase(), response.getReasonPhrase());
Assert.assertEquals(Status.ACCEPTED, response.getStatus());
ar.success(2);
Assert.assertEquals(2, (int) response.getResult());
Assert.assertEquals(Status.OK.getStatusCode(), response.getStatusCode());
Response r = Response.succResp(3);
ar.complete(r);
Assert.assertEquals(r, response);
ar.consumerFail(new Error("abc"));
CommonExceptionData data = (CommonExceptionData) ((InvocationException) response.getResult()).getErrorData();
Assert.assertEquals("Cse Internal Bad Request", data.getMessage());
Assert.assertEquals(ExceptionFactory.CONSUMER_INNER_STATUS_CODE, response.getStatusCode());
ar.fail(InvocationType.CONSUMER, new Error("abc"));
data = (CommonExceptionData) ((InvocationException) response.getResult()).getErrorData();
Assert.assertEquals("Cse Internal Bad Request", data.getMessage());
Assert.assertEquals(ExceptionFactory.CONSUMER_INNER_STATUS_CODE, response.getStatusCode());
InvocationException consumerException = new InvocationException(300, "abc", "def");
ar.consumerFail(consumerException);
Assert.assertEquals("def", ((InvocationException) response.getResult()).getErrorData());
Assert.assertEquals(300, response.getStatusCode());
ar.fail(InvocationType.CONSUMER, consumerException);
Assert.assertEquals("def", ((InvocationException) response.getResult()).getErrorData());
Assert.assertEquals(300, response.getStatusCode());
ar.producerFail(new Error("abc"));
data = (CommonExceptionData) ((InvocationException) response.getResult()).getErrorData();
Assert.assertEquals("Cse Internal Server Error", data.getMessage());
Assert.assertEquals(ExceptionFactory.PRODUCER_INNER_STATUS_CODE, response.getStatusCode());
ar.fail(InvocationType.PRODUCER, new Error("abc"));
data = (CommonExceptionData) ((InvocationException) response.getResult()).getErrorData();
Assert.assertEquals("Cse Internal Server Error", data.getMessage());
Assert.assertEquals(ExceptionFactory.PRODUCER_INNER_STATUS_CODE, response.getStatusCode());
InvocationException producerException = new InvocationException(500, "abc", "def");
ar.producerFail(producerException);
Assert.assertEquals("def", ((InvocationException) response.getResult()).getErrorData());
Assert.assertEquals(500, response.getStatusCode());
ar.fail(InvocationType.PRODUCER, producerException);
Assert.assertEquals("def", ((InvocationException) response.getResult()).getErrorData());
Assert.assertEquals(500, response.getStatusCode());
}
use of io.servicecomb.core.exception.CommonExceptionData in project java-chassis by ServiceComb.
the class TestLocator method testLocateStatic.
@Test
public void testLocateStatic() {
MicroserviceMeta msm = new MicroserviceMeta("app:ms");
ServicePathManager spm = new ServicePathManager(msm);
RestOperationMeta rom = createRestOperatonMeta("GET", "abc/");
spm.addResource(rom);
rom = createRestOperatonMeta("POST", "abc/");
spm.addResource(rom);
try {
spm.addResource(rom);
} catch (Throwable e) {
Assert.assertEquals("operation with url abc/, method POST is duplicated", e.getMessage());
}
Assert.assertEquals(1, spm.getStaticPathOperationMap().size());
Assert.assertEquals(2, spm.getStaticPathOperationMap().get("abc/").values().size());
try {
spm.locateOperation("abcd", "GET");
} catch (InvocationException e) {
Assert.assertEquals("Not Found", ((CommonExceptionData) e.getErrorData()).getMessage());
}
try {
spm.locateOperation("abc/", "PUT");
} catch (InvocationException e) {
Assert.assertEquals("Method Not Allowed", ((CommonExceptionData) e.getErrorData()).getMessage());
}
OperationLocator locator = spm.locateOperation("abc/", "GET");
Assert.assertEquals(Collections.emptyMap(), locator.getPathVarMap());
locator.locate(spm, "abc/", "POST");
Assert.assertEquals(Collections.emptyMap(), locator.getPathVarMap());
}
Aggregations