Search in sources :

Example 1 with PathParamMeta

use of eu.okaeri.platform.web.meta.PathParamMeta in project okaeri-platform by OkaeriPoland.

the class RequestHandlerComponentResolver method getCall.

private Object[] getCall(@NonNull Map<Integer, Object[]> prefilledCallCache, @NonNull RequestHandlerMeta handlerMeta, @NonNull Context context, @NonNull Injector injector) {
    Object[] prefilledCall = prefilledCallCache.computeIfAbsent(Thread.currentThread().hashCode(), (hash) -> {
        OkaeriInjector okaeriInjector = (OkaeriInjector) injector;
        Parameter[] parameters = handlerMeta.getMethod().getParameters();
        return okaeriInjector.fillParameters(parameters, false);
    });
    int[] contextIndexes = handlerMeta.getContextIndexes();
    for (int contextIndex : contextIndexes) {
        prefilledCall[contextIndex] = context;
    }
    Map<Integer, PathParamMeta> pathParams = handlerMeta.getPathParams();
    for (PathParamMeta pathParam : pathParams.values()) {
        Object paramValue;
        String paramName = pathParam.getName();
        Class<?> paramType = pathParam.getType();
        try {
            paramValue = context.pathParamAsClass(paramName, paramType).get();
        } catch (Exception exception) {
            throw new RuntimeException("Failed resolving path parameter (" + paramName + ") of type " + paramType, exception);
        }
        prefilledCall[pathParam.getIndex()] = paramValue;
    }
    return prefilledCall;
}
Also used : OkaeriInjector(eu.okaeri.injector.OkaeriInjector) InvocationTargetException(java.lang.reflect.InvocationTargetException) PathParamMeta(eu.okaeri.platform.web.meta.PathParamMeta) Parameter(java.lang.reflect.Parameter)

Aggregations

OkaeriInjector (eu.okaeri.injector.OkaeriInjector)1 PathParamMeta (eu.okaeri.platform.web.meta.PathParamMeta)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Parameter (java.lang.reflect.Parameter)1