All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.resteasy.reactive.common.model.PreMatchInterceptorContainer Maven / Gradle / Ivy

There is a newer version: 3.17.0.CR1
Show newest version
package org.jboss.resteasy.reactive.common.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;

import org.jboss.resteasy.reactive.spi.BeanFactory;

public class PreMatchInterceptorContainer extends InterceptorContainer {
    private final List> preMatchInterceptors = new ArrayList<>();

    public void addPreMatchInterceptor(ResourceInterceptor interceptor) {
        preMatchInterceptors.add(interceptor);
    }

    public List> getPreMatchInterceptors() {
        return preMatchInterceptors;
    }

    public void initializeDefaultFactories(Function> factoryCreator) {
        super.initializeDefaultFactories(factoryCreator);
        for (ResourceInterceptor i : preMatchInterceptors) {
            if (i.getFactory() == null) {
                i.setFactory((BeanFactory) factoryCreator.apply(i.getClassName()));
            }
        }
    }

    @Override
    public void sort() {
        super.sort();
        Collections.sort(preMatchInterceptors);
    }

    /**
     * Validates that any {@code ContainerRequestFilter} that has {@code nonBlockingRequired} set, comes before any other filter
     */
    public void validateThreadModel() {
        boolean unsetNonBlockingInterceptorFound = false;
        List> allNonNamedInterceptors = new ArrayList<>(
                preMatchInterceptors.size() + getGlobalResourceInterceptors().size());
        allNonNamedInterceptors.addAll(preMatchInterceptors);
        allNonNamedInterceptors.addAll(getGlobalResourceInterceptors());
        for (ResourceInterceptor filter : allNonNamedInterceptors) {
            if (filter.isNonBlockingRequired()) {
                if (unsetNonBlockingInterceptorFound) {
                    throw new RuntimeException(
                            "ContainerRequestFilters that are marked as '@NonBlocking' must be executed before any other filters. Offending class is '"
                                    + filter.getClassName() + "'");
                }
            } else {
                unsetNonBlockingInterceptorFound = true;
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy