use of io.undertow.predicate.Predicate in project spring-boot by spring-projects.
the class UndertowServletWebServer method getCompressionPredicates.
private Predicate[] getCompressionPredicates(Compression compression) {
List<Predicate> predicates = new ArrayList<>();
predicates.add(new MaxSizePredicate(compression.getMinResponseSize()));
predicates.add(new CompressibleMimeTypePredicate(compression.getMimeTypes()));
if (compression.getExcludedUserAgents() != null) {
for (String agent : compression.getExcludedUserAgents()) {
RequestHeaderAttribute agentHeader = new RequestHeaderAttribute(new HttpString(HttpHeaders.USER_AGENT));
predicates.add(Predicates.not(Predicates.regex(agentHeader, agent)));
}
}
return predicates.toArray(new Predicate[predicates.size()]);
}
use of io.undertow.predicate.Predicate in project wildfly by wildfly.
the class AccessLogAdd method performRuntime.
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final PathAddress address = context.getCurrentAddress();
final PathAddress hostAddress = address.getParent();
final PathAddress serverAddress = hostAddress.getParent();
final String worker = AccessLogDefinition.WORKER.resolveModelAttribute(context, model).asString();
final String pattern = AccessLogDefinition.PATTERN.resolveModelAttribute(context, model).asString();
final String directory = AccessLogDefinition.DIRECTORY.resolveModelAttribute(context, model).asString();
final String filePrefix = AccessLogDefinition.PREFIX.resolveModelAttribute(context, model).asString();
final String fileSuffix = AccessLogDefinition.SUFFIX.resolveModelAttribute(context, model).asString();
final boolean useServerLog = AccessLogDefinition.USE_SERVER_LOG.resolveModelAttribute(context, model).asBoolean();
final boolean rotate = AccessLogDefinition.ROTATE.resolveModelAttribute(context, model).asBoolean();
final boolean extended = AccessLogDefinition.EXTENDED.resolveModelAttribute(context, model).asBoolean();
final ModelNode relativeToNode = AccessLogDefinition.RELATIVE_TO.resolveModelAttribute(context, model);
final String relativeTo = relativeToNode.isDefined() ? relativeToNode.asString() : null;
Predicate predicate = null;
ModelNode predicateNode = AccessLogDefinition.PREDICATE.resolveModelAttribute(context, model);
if (predicateNode.isDefined()) {
predicate = Predicates.parse(predicateNode.asString(), getClass().getClassLoader());
}
final AccessLogService service;
if (useServerLog) {
service = new AccessLogService(pattern, extended, predicate);
} else {
service = new AccessLogService(pattern, directory, relativeTo, filePrefix, fileSuffix, rotate, extended, predicate);
}
final String serverName = serverAddress.getLastElement().getValue();
final String hostName = hostAddress.getLastElement().getValue();
final ServiceName serviceName = UndertowService.accessLogServiceName(serverName, hostName);
final ServiceBuilder<AccessLogService> builder = context.getServiceTarget().addService(serviceName, service).addDependency(IOServices.WORKER.append(worker), XnioWorker.class, service.getWorker()).addDependency(PathManagerService.SERVICE_NAME, PathManager.class, service.getPathManager()).addDependency(UndertowService.virtualHostName(serverName, hostName), Host.class, service.getHost());
builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
}
use of io.undertow.predicate.Predicate in project undertow by undertow-io.
the class PredicatedHandlersParser method handlePredicateOperatorNode.
private static PredicatedHandler handlePredicateOperatorNode(String contents, PredicateOperatorNode node, Map<String, PredicateBuilder> predicateBuilders, Map<String, HandlerBuilder> handlerBuilders, ExchangeAttributeParser parser) {
Predicate predicate = handlePredicateNode(contents, node.getLeft(), predicateBuilders, parser);
HandlerWrapper ret = handlePredicatedAction(contents, node.getRight(), predicateBuilders, handlerBuilders, parser);
HandlerWrapper elseBranch = null;
if (node.getElseBranch() != null) {
elseBranch = handlePredicatedAction(contents, node.getElseBranch(), predicateBuilders, handlerBuilders, parser);
}
return new PredicatedHandler(predicate, ret, elseBranch);
}
use of io.undertow.predicate.Predicate in project undertow by undertow-io.
the class HttpContinueAcceptingHandlerTestCase method setup.
@BeforeClass
public static void setup() {
final BlockingHandler blockingHandler = new BlockingHandler();
final HttpContinueAcceptingHandler handler = new HttpContinueAcceptingHandler(blockingHandler, new Predicate() {
@Override
public boolean resolve(HttpServerExchange value) {
return accept;
}
});
DefaultServer.setRootHandler(handler);
blockingHandler.setRootHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) {
try {
byte[] buffer = new byte[1024];
final ByteArrayOutputStream b = new ByteArrayOutputStream();
int r = 0;
final OutputStream outputStream = exchange.getOutputStream();
final InputStream inputStream = exchange.getInputStream();
while ((r = inputStream.read(buffer)) > 0) {
b.write(buffer, 0, r);
}
outputStream.write(b.toByteArray());
outputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
}
use of io.undertow.predicate.Predicate in project wildfly by wildfly.
the class GlobalRequestControllerHandler method handleRequest.
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
RunResult result = entryPoint.beginRequest();
try {
if (result == RunResult.RUN) {
next.handleRequest(exchange);
} else {
boolean allowed = false;
for (Predicate allow : allowSuspendedRequests) {
if (allow.resolve(exchange)) {
allowed = true;
ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (src != null) {
src.getServletRequest().setAttribute(ORG_WILDFLY_SUSPENDED, "true");
}
next.handleRequest(exchange);
break;
}
}
if (!allowed) {
exchange.setStatusCode(503);
exchange.endExchange();
}
}
} finally {
if (result == RunResult.RUN && (exchange.isComplete() || !exchange.isDispatched())) {
entryPoint.requestComplete();
} else if (result == RunResult.RUN) {
exchange.addExchangeCompleteListener(listener);
}
}
}
Aggregations