use of org.apache.servicecomb.core.Handler in project incubator-servicecomb-java-chassis by apache.
the class TestAbstractRestInvocation method doInvoke.
@Test
public void doInvoke(@Mocked Endpoint endpoint, @Mocked OperationMeta operationMeta, @Mocked Object[] swaggerArguments, @Mocked SchemaMeta schemaMeta) throws Throwable {
Response response = Response.ok("ok");
Handler handler = new Handler() {
@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) {
asyncResp.complete(response);
}
};
List<Handler> handlerChain = Arrays.asList(handler);
Deencapsulation.setField(invocation, "handlerList", handlerChain);
Holder<Response> result = new Holder<>();
restInvocation = new AbstractRestInvocationForTest() {
@Override
protected void sendResponseQuietly(Response response) {
result.value = response;
}
};
restInvocation.invocation = invocation;
restInvocation.doInvoke();
Assert.assertSame(response, result.value);
}
use of org.apache.servicecomb.core.Handler in project java-chassis by ServiceComb.
the class AbstractRestInvocation method checkQpsFlowControl.
private Holder<Boolean> checkQpsFlowControl(OperationMeta operationMeta) {
Holder<Boolean> qpsFlowControlReject = new Holder<>(false);
@SuppressWarnings("deprecation") Handler providerQpsFlowControlHandler = operationMeta.getProviderQpsFlowControlHandler();
if (null != providerQpsFlowControlHandler) {
try {
providerQpsFlowControlHandler.handle(invocation, response -> {
qpsFlowControlReject.value = true;
produceProcessor = ProduceProcessorManager.INSTANCE.findDefaultJsonProcessor();
sendResponse(response);
});
} catch (Throwable e) {
LOGGER.error("failed to execute ProviderQpsFlowControlHandler", e);
qpsFlowControlReject.value = true;
sendFailResponse(e);
}
}
return qpsFlowControlReject;
}
use of org.apache.servicecomb.core.Handler in project java-chassis by ServiceComb.
the class HighwayServerInvoke method checkQpsFlowControl.
private Holder<Boolean> checkQpsFlowControl(OperationMeta operationMeta) {
Holder<Boolean> qpsFlowControlReject = new Holder<>(false);
@SuppressWarnings("deprecation") Handler providerQpsFlowControlHandler = operationMeta.getProviderQpsFlowControlHandler();
if (null != providerQpsFlowControlHandler) {
try {
providerQpsFlowControlHandler.handle(invocation, response -> {
qpsFlowControlReject.value = true;
sendResponse(header.getContext(), response);
});
} catch (Exception e) {
LOGGER.error("failed to execute ProviderQpsFlowControlHandler", e);
qpsFlowControlReject.value = true;
sendResponse(header.getContext(), Response.providerFailResp(e));
}
}
return qpsFlowControlReject;
}
use of org.apache.servicecomb.core.Handler in project incubator-servicecomb-java-chassis by apache.
the class UnitTestMeta method init.
@SuppressWarnings("unchecked")
public static synchronized void init() {
if (inited) {
return;
}
ConsumerProviderManager consumerProviderManager = new ConsumerProviderManager();
ConsumerSchemaFactory consumerSchemaFactory = new ConsumerSchemaFactory();
consumerSchemaFactory.setMicroserviceMetaManager(microserviceMetaManager);
consumerSchemaFactory.setSchemaListenerManager(schemaListenerManager);
consumerProviderManager.setConsumerSchemaFactory(consumerSchemaFactory);
CseContext.getInstance().setConsumerProviderManager(consumerProviderManager);
CseContext.getInstance().setConsumerSchemaFactory(consumerSchemaFactory);
CseContext.getInstance().setSchemaListenerManager(schemaListenerManager);
Config config = new Config();
Class<?> cls = SimpleLoadBalanceHandler.class;
config.getHandlerClassMap().put("simpleLB", (Class<Handler>) cls);
ProducerHandlerManager.INSTANCE.init(new Config());
ConsumerHandlerManager.INSTANCE.init(config);
ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
Mockito.when(applicationContext.getBean(Mockito.anyString())).thenReturn(null);
BeanUtils.setContext(applicationContext);
inited = true;
}
use of org.apache.servicecomb.core.Handler in project incubator-servicecomb-java-chassis by apache.
the class SchemaLoader method registerSchema.
public SchemaMeta registerSchema(MicroserviceMeta microserviceMeta, String schemaId, Swagger swagger) {
String microserviceName = microserviceMeta.getName();
LOGGER.info("register schema {}/{}/{}", microserviceMeta.getAppId(), microserviceName, schemaId);
SchemaMeta schemaMeta = new SchemaMeta(swagger, microserviceMeta, schemaId);
List<Handler> producerHandlerChain = ProducerHandlerManager.INSTANCE.getOrCreate(microserviceName);
schemaMeta.setProviderHandlerChain(producerHandlerChain);
List<Handler> consumerHandlerChain = ConsumerHandlerManager.INSTANCE.getOrCreate(microserviceName);
schemaMeta.setConsumerHandlerChain(consumerHandlerChain);
microserviceMeta.regSchemaMeta(schemaMeta);
putSelfBasePathIfAbsent(microserviceName, swagger.getBasePath());
return schemaMeta;
}
Aggregations