Search in sources :

Example 6 with ReactorHandler

use of io.gravitee.gateway.reactor.handler.ReactorHandler in project gravitee-gateway by gravitee-io.

the class ApiContextHandlerFactoryTest method shouldCreateContext.

@Test
public void shouldCreateContext() {
    apiContextHandlerFactory = spy(apiContextHandlerFactory);
    AbstractApplicationContext ctx = mock(AbstractApplicationContext.class);
    when(api.isEnabled()).thenReturn(true);
    when(ctx.getBean(ApiReactorHandler.class)).thenReturn(mock(ApiReactorHandler.class));
    doReturn(ctx).when(apiContextHandlerFactory).createApplicationContext(api);
    ReactorHandler handler = apiContextHandlerFactory.create(api);
    assertNotNull(handler);
    assertTrue(ApiReactorHandler.class.isAssignableFrom(handler.getClass()));
}
Also used : ReactorHandler(io.gravitee.gateway.reactor.handler.ReactorHandler) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) Test(org.junit.Test)

Example 7 with ReactorHandler

use of io.gravitee.gateway.reactor.handler.ReactorHandler in project gravitee-gateway by gravitee-io.

the class DefaultReactorHandlerRegistry method create.

@Override
public void create(Reactable reactable) {
    logger.info("Creating a new handler for {}", reactable.item());
    ReactorHandler handler = prepare(reactable);
    if (handler != null) {
        register(handler);
    }
}
Also used : ReactorHandler(io.gravitee.gateway.reactor.handler.ReactorHandler)

Example 8 with ReactorHandler

use of io.gravitee.gateway.reactor.handler.ReactorHandler in project gravitee-gateway by gravitee-io.

the class DefaultReactorHandlerRegistry method update.

@Override
public void update(Reactable reactable) {
    logger.info("Updating handler for {}", reactable);
    String contextPath = contextPaths.get(reactable);
    if (contextPath != null) {
        logger.info("Handler was previously map to {}", contextPath);
        ReactorHandler newHandler = prepare(reactable);
        // Do not update handler if the new is not correctly initialized
        if (newHandler != null) {
            ReactorHandler previousHandler = handlers.get(contextPath);
            register(newHandler);
            if (previousHandler != null) {
                try {
                    logger.info("Stopping previous handler for path {}", contextPath);
                    previousHandler.stop();
                } catch (Exception ex) {
                    logger.error("Unable to stop handler", ex);
                }
            }
        }
    } else {
        create(reactable);
    }
}
Also used : ReactorHandler(io.gravitee.gateway.reactor.handler.ReactorHandler)

Example 9 with ReactorHandler

use of io.gravitee.gateway.reactor.handler.ReactorHandler in project gravitee-gateway by gravitee-io.

the class DefaultReactorHandlerRegistry method remove.

@Override
public void remove(Reactable reactable) {
    String contextPath = contextPaths.remove(reactable);
    if (contextPath != null) {
        ReactorHandler handler = handlers.remove(contextPath);
        if (handler != null) {
            try {
                handler.stop();
                handlers.remove(handler.contextPath());
                logger.info("API has been unregistered");
            } catch (Exception e) {
                logger.error("Unable to un-register handler", e);
            }
        }
    }
}
Also used : ReactorHandler(io.gravitee.gateway.reactor.handler.ReactorHandler)

Example 10 with ReactorHandler

use of io.gravitee.gateway.reactor.handler.ReactorHandler in project gravitee-gateway by gravitee-io.

the class DefaultReactor method route.

@Override
public void route(Request serverRequest, Response serverResponse, final Handler<Response> handler) {
    LOGGER.debug("Receiving a request {} for path {}", serverRequest.id(), serverRequest.path());
    // Prepare handler chain
    Handler<Request> requestHandlerChain = transactionHandlerFactory.create(request -> {
        ReactorHandler reactorHandler = reactorHandlerResolver.resolve(request);
        if (reactorHandler != null) {
            // Prepare the handler chain
            Handler<Response> responseHandlerChain = new ResponseTimeHandler(request, new ReporterHandler(reporterService, request, handler));
            reactorHandler.handle(request, serverResponse, responseHandlerChain);
        } else {
            LOGGER.debug("No handler can be found for request {}, returning NOT_FOUND (404)", request.path());
            sendNotFound(serverResponse, handler);
        }
    }, serverResponse);
    // Set gateway tenant
    serverRequest.metrics().setTenant(gatewayConfiguration.tenant().orElse(null));
    // And handle the request
    requestHandlerChain.handle(serverRequest);
}
Also used : Response(io.gravitee.gateway.api.Response) ReactorHandler(io.gravitee.gateway.reactor.handler.ReactorHandler) ReporterHandler(io.gravitee.gateway.reactor.handler.reporter.ReporterHandler) ResponseTimeHandler(io.gravitee.gateway.reactor.handler.ResponseTimeHandler) Request(io.gravitee.gateway.api.Request)

Aggregations

ReactorHandler (io.gravitee.gateway.reactor.handler.ReactorHandler)10 Reactable (io.gravitee.gateway.reactor.Reactable)2 PluginClassLoader (io.gravitee.plugin.core.api.PluginClassLoader)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 Policy (io.gravitee.definition.model.Policy)1 Resource (io.gravitee.definition.model.plugins.resources.Resource)1 Request (io.gravitee.gateway.api.Request)1 Response (io.gravitee.gateway.api.Response)1 ResponseTimeHandler (io.gravitee.gateway.reactor.handler.ResponseTimeHandler)1 ReporterHandler (io.gravitee.gateway.reactor.handler.reporter.ReporterHandler)1 ResourceConfigurationFactory (io.gravitee.gateway.resource.ResourceConfigurationFactory)1 ResourceLifecycleManager (io.gravitee.gateway.resource.ResourceLifecycleManager)1 PolicyClassLoaderFactory (io.gravitee.plugin.policy.PolicyClassLoaderFactory)1 PolicyPlugin (io.gravitee.plugin.policy.PolicyPlugin)1 PolicyPluginManager (io.gravitee.plugin.policy.PolicyPluginManager)1 PolicyMethodResolver (io.gravitee.plugin.policy.internal.PolicyMethodResolver)1 ResourceClassLoaderFactory (io.gravitee.plugin.resource.ResourceClassLoaderFactory)1 ResourcePlugin (io.gravitee.plugin.resource.ResourcePlugin)1 ResourcePluginManager (io.gravitee.plugin.resource.ResourcePluginManager)1