use of io.gravitee.gateway.api.context.SimpleExecutionContext in project gravitee-api-management by gravitee-io.
the class TraceContextProcessorTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
context = new SimpleExecutionContext(request, response);
Mockito.when(request.headers()).thenReturn(HttpHeaders.create());
Mockito.when(response.headers()).thenReturn(HttpHeaders.create());
Mockito.when(request.metrics()).thenReturn(Metrics.on(System.currentTimeMillis()).build());
}
use of io.gravitee.gateway.api.context.SimpleExecutionContext in project gravitee-access-management by gravitee-io.
the class PolicyChainHandlerImpl method prepareContext.
private void prepareContext(RoutingContext routingContext, Handler<AsyncResult<ExecutionContext>> handler) {
try {
io.vertx.core.http.HttpServerRequest request = routingContext.request().getDelegate();
Request serverRequest = new VertxHttpServerRequest(request);
Response serverResponse = new VertxHttpServerResponse(request, serverRequest.metrics());
ExecutionContext simpleExecutionContext = new SimpleExecutionContext(serverRequest, serverResponse);
ExecutionContext executionContext = executionContextFactory.create(simpleExecutionContext);
// add current context attributes
executionContext.getAttributes().putAll(getEvaluableAttributes(routingContext));
handler.handle(Future.succeededFuture(executionContext));
} catch (Exception ex) {
handler.handle(Future.failedFuture(ex));
}
}
use of io.gravitee.gateway.api.context.SimpleExecutionContext in project gravitee-access-management by gravitee-io.
the class TokenServiceImpl method createExecutionContext.
private ExecutionContext createExecutionContext(OAuth2Request request, Client client, User user) {
ExecutionContext simpleExecutionContext = new SimpleExecutionContext(request, null);
ExecutionContext executionContext = executionContextFactory.create(simpleExecutionContext);
executionContext.setAttribute("client", new ClientProperties(client));
if (user != null) {
executionContext.setAttribute("user", new UserProperties(user));
}
// put authorization request in context
if (request.getResponseType() != null && !request.getResponseType().isEmpty()) {
executionContext.setAttribute("authorizationRequest", request);
} else {
executionContext.setAttribute("tokenRequest", request);
}
Object authFlowAttributes = request.getContext().get(ConstantKeys.AUTH_FLOW_CONTEXT_ATTRIBUTES_KEY);
if (authFlowAttributes != null) {
executionContext.setAttribute(ConstantKeys.AUTH_FLOW_CONTEXT_ATTRIBUTES_KEY, authFlowAttributes);
request.getContext().remove(ConstantKeys.AUTH_FLOW_CONTEXT_ATTRIBUTES_KEY);
}
return executionContext;
}
use of io.gravitee.gateway.api.context.SimpleExecutionContext in project gravitee-gateway by gravitee-io.
the class DefaultReactor method route.
@Override
public void route(Request serverRequest, Response serverResponse, Handler<ExecutionContext> handler) {
LOGGER.debug("Receiving a request {} for path {}", serverRequest.id(), serverRequest.path());
// Prepare invocation execution context
ExecutionContext context = new SimpleExecutionContext(serverRequest, serverResponse);
// Set gateway tenant
gatewayConfiguration.tenant().ifPresent(tenant -> serverRequest.metrics().setTenant(tenant));
// Set gateway zone
gatewayConfiguration.zone().ifPresent(zone -> serverRequest.metrics().setZone(zone));
// Prepare handler chain
requestProcessorChainFactory.create().handler(ctx -> {
HandlerEntrypoint entrypoint = entrypointResolver.resolve(ctx);
if (entrypoint != null) {
entrypoint.target().handler(context1 -> {
// Ensure that response has been ended before going further
context1.response().endHandler(avoid -> processResponse(context1, handler)).end();
}).handle(ctx);
} else {
processNotFound(ctx, handler);
}
}).errorHandler(__ -> processResponse(context, handler)).exitHandler(__ -> processResponse(context, handler)).handle(context);
}
use of io.gravitee.gateway.api.context.SimpleExecutionContext in project gravitee-gateway by gravitee-io.
the class PathParametersProcessorBenchmark method bench_processorIndex.
@Benchmark
public void bench_processorIndex() {
ExecutionContext context = new SimpleExecutionContext(new SimpleRequest("/store/myStore/order/190783"), null);
processorIndex.handle(context);
}
Aggregations