org.jboss.resteasy.reactive.common.model.ResourceInterceptors Maven / Gradle / Ivy
package org.jboss.resteasy.reactive.common.model;
import java.util.function.Function;
import jakarta.ws.rs.container.ContainerRequestFilter;
import jakarta.ws.rs.container.ContainerResponseFilter;
import jakarta.ws.rs.ext.ReaderInterceptor;
import jakarta.ws.rs.ext.WriterInterceptor;
import org.jboss.resteasy.reactive.spi.BeanFactory;
public class ResourceInterceptors {
private InterceptorContainer containerResponseFilters = new InterceptorContainer.Reversed<>();
private PreMatchInterceptorContainer containerRequestFilters = new PreMatchInterceptorContainer<>();
private InterceptorContainer writerInterceptors = new InterceptorContainer<>();
private InterceptorContainer readerInterceptors = new InterceptorContainer<>();
public InterceptorContainer getContainerResponseFilters() {
return containerResponseFilters;
}
public ResourceInterceptors setContainerResponseFilters(
InterceptorContainer containerResponseFilters) {
this.containerResponseFilters = containerResponseFilters;
return this;
}
public PreMatchInterceptorContainer getContainerRequestFilters() {
return containerRequestFilters;
}
public ResourceInterceptors setContainerRequestFilters(
PreMatchInterceptorContainer containerRequestFilters) {
this.containerRequestFilters = containerRequestFilters;
return this;
}
public InterceptorContainer getWriterInterceptors() {
return writerInterceptors;
}
public ResourceInterceptors setWriterInterceptors(InterceptorContainer writerInterceptors) {
this.writerInterceptors = writerInterceptors;
return this;
}
public InterceptorContainer getReaderInterceptors() {
return readerInterceptors;
}
public ResourceInterceptors setReaderInterceptors(InterceptorContainer readerInterceptors) {
this.readerInterceptors = readerInterceptors;
return this;
}
public void initializeDefaultFactories(Function> factoryCreator) {
containerRequestFilters.initializeDefaultFactories(factoryCreator);
containerResponseFilters.initializeDefaultFactories(factoryCreator);
readerInterceptors.initializeDefaultFactories(factoryCreator);
writerInterceptors.initializeDefaultFactories(factoryCreator);
}
// we sort this at build time as the order of the elements in the lists is retained in generated bytecode
// therefore at runtime the elements are already properly sorted
public ResourceInterceptors sort() {
containerRequestFilters.sort();
containerResponseFilters.sort();
writerInterceptors.sort();
readerInterceptors.sort();
return this;
}
public void visitFilters(FiltersVisitor visitor) {
for (var f : containerRequestFilters.getPreMatchInterceptors()) {
var visitResult = visitor.visitPreMatchRequestFilter(f);
if (visitResult == FiltersVisitor.VisitResult.ABORT) {
return;
}
}
for (var f : containerRequestFilters.getGlobalResourceInterceptors()) {
var visitResult = visitor.visitGlobalRequestFilter(f);
if (visitResult == FiltersVisitor.VisitResult.ABORT) {
return;
}
}
for (var f : containerRequestFilters.getNameResourceInterceptors()) {
var visitResult = visitor.visitNamedRequestFilter(f);
if (visitResult == FiltersVisitor.VisitResult.ABORT) {
return;
}
}
for (var f : containerResponseFilters.getGlobalResourceInterceptors()) {
var visitResult = visitor.visitGlobalResponseFilter(f);
if (visitResult == FiltersVisitor.VisitResult.ABORT) {
return;
}
}
for (var f : containerResponseFilters.getNameResourceInterceptors()) {
var visitResult = visitor.visitNamedResponseFilter(f);
if (visitResult == FiltersVisitor.VisitResult.ABORT) {
return;
}
}
}
public interface FiltersVisitor {
VisitResult visitPreMatchRequestFilter(ResourceInterceptor interceptor);
VisitResult visitGlobalRequestFilter(ResourceInterceptor interceptor);
VisitResult visitNamedRequestFilter(ResourceInterceptor interceptor);
VisitResult visitGlobalResponseFilter(ResourceInterceptor interceptor);
VisitResult visitNamedResponseFilter(ResourceInterceptor interceptor);
enum VisitResult {
CONTINUE,
ABORT
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy