Search in sources :

Example 1 with Handler

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);
}
Also used : AsyncResponse(org.apache.servicecomb.swagger.invocation.AsyncResponse) Response(org.apache.servicecomb.swagger.invocation.Response) Invocation(org.apache.servicecomb.core.Invocation) Holder(javax.xml.ws.Holder) Handler(org.apache.servicecomb.core.Handler) AsyncResponse(org.apache.servicecomb.swagger.invocation.AsyncResponse) Test(org.junit.Test)

Example 2 with Handler

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;
}
Also used : Holder(org.apache.servicecomb.foundation.common.Holder) Handler(org.apache.servicecomb.core.Handler)

Example 3 with Handler

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;
}
Also used : Holder(org.apache.servicecomb.foundation.common.Holder) Handler(org.apache.servicecomb.core.Handler) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 4 with Handler

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;
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ConsumerProviderManager(org.apache.servicecomb.core.provider.consumer.ConsumerProviderManager) SimpleLoadBalanceHandler(org.apache.servicecomb.core.handler.impl.SimpleLoadBalanceHandler) Config(org.apache.servicecomb.core.handler.config.Config) SimpleLoadBalanceHandler(org.apache.servicecomb.core.handler.impl.SimpleLoadBalanceHandler) Handler(org.apache.servicecomb.core.Handler) ConsumerSchemaFactory(org.apache.servicecomb.core.definition.schema.ConsumerSchemaFactory)

Example 5 with Handler

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;
}
Also used : SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) Handler(org.apache.servicecomb.core.Handler)

Aggregations

Handler (org.apache.servicecomb.core.Handler)7 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 Invocation (org.apache.servicecomb.core.Invocation)3 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)3 Subscribe (com.google.common.eventbus.Subscribe)2 CONTENT_LENGTH (com.google.common.net.HttpHeaders.CONTENT_LENGTH)2 TRANSFER_ENCODING (com.google.common.net.HttpHeaders.TRANSFER_ENCODING)2 MultiMap (io.vertx.core.MultiMap)2 Buffer (io.vertx.core.buffer.Buffer)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Executor (java.util.concurrent.Executor)2 AsyncContext (javax.servlet.AsyncContext)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpHeaders (javax.ws.rs.core.HttpHeaders)2 MediaType (javax.ws.rs.core.MediaType)2 Status (javax.ws.rs.core.Response.Status)2 Deencapsulation (mockit.Deencapsulation)2