use of eu.okaeri.platform.web.meta.RequestHandlerMeta in project okaeri-platform by OkaeriPoland.
the class RequestHandlerComponentResolver method make.
@Override
public Object make(@NonNull ComponentCreator creator, @NonNull BeanManifest manifest, @NonNull Injector injector) {
long start = System.currentTimeMillis();
BeanManifest parent = manifest.getParent();
Class<?> parentClass = parent.getType();
Method method = manifest.getMethod();
RequestHandlerMeta handlerMeta = RequestHandlerMeta.of(parentClass, method);
int[] contextIndexes = handlerMeta.getContextIndexes();
Map<Integer, Object[]> prefilledCallCache = new CacheMap<>(256);
Handler handler = context -> {
Object[] call = null;
try {
call = this.getCall(prefilledCallCache, handlerMeta, context, injector);
method.invoke(parent.getObject(), call);
this.flushCall(call, contextIndexes, handlerMeta);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) {
this.logger.error("Handler (" + method + ") failure [" + Arrays.toString(call) + "]", exception);
}
};
HandlerType handlerType = handlerMeta.getType();
String handlerPath = handlerMeta.getPath();
SimpleRouteRole[] handlerPermittedRoles = handlerMeta.getPermittedRoles();
this.javalin.addHandler(handlerType, handlerPath, handler, handlerPermittedRoles);
long took = System.currentTimeMillis() - start;
creator.log(ComponentHelper.buildComponentMessage().type("Added handler").name(parentClass.getSimpleName() + "#" + method.getName()).took(took).meta("path", handlerPath).meta("type", handlerType).meta("permittedRoles", Arrays.stream(handlerPermittedRoles).map(SimpleRouteRole::getName).collect(Collectors.toList())).build());
creator.increaseStatistics("handlers", 1);
return handler;
}
Aggregations