當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpHandler.handleRequest方法代碼示例

本文整理匯總了Java中io.undertow.server.HttpHandler.handleRequest方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpHandler.handleRequest方法的具體用法?Java HttpHandler.handleRequest怎麽用?Java HttpHandler.handleRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.undertow.server.HttpHandler的用法示例。


在下文中一共展示了HttpHandler.handleRequest方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: loadBalancerHttpToHttps

import io.undertow.server.HttpHandler; //導入方法依賴的package包/類
public static HttpHandler loadBalancerHttpToHttps(HttpHandler next) {
    return (HttpServerExchange exchange) -> {
        HttpUrl currentUrl = Exchange.urls().currentUrl(exchange);
        String protocolForward = Exchange.headers().getHeader(exchange, "X-Forwarded-Proto").orElse(null);
        if (null != protocolForward && protocolForward.equalsIgnoreCase("http")) {
            log.debug("non https switching to https {}", currentUrl.host());
            HttpUrl newUrl = currentUrl.newBuilder()
               .scheme("https")
               .port(443)
               .build();
            exchange.setStatusCode(301);
            exchange.getResponseHeaders().put(Headers.LOCATION, newUrl.toString());
            exchange.endExchange();
            return;
        }

        next.handleRequest(exchange);
    };
}
 
開發者ID:StubbornJava,項目名稱:StubbornJava,代碼行數:20,代碼來源:CustomHandlers.java

示例2: parse

import io.undertow.server.HttpHandler; //導入方法依賴的package包/類
@Override
public void parse(final HttpHandler handler) throws Exception {
    if (exchange.getAttachment(FORM_DATA) != null) {
        handler.handleRequest(exchange);
        return;
    }
    this.handler = handler;
    //we need to delegate to a thread pool
    //as we parse with blocking operations

    StreamSourceChannel requestChannel = exchange.getRequestChannel();
    if (requestChannel == null) {
        throw new IOException(UndertowMessages.MESSAGES.requestChannelAlreadyProvided());
    }
    if (executor == null) {
        exchange.dispatch(new NonBlockingParseTask(exchange.getConnection().getWorker(), requestChannel));
    } else {
        exchange.dispatch(executor, new NonBlockingParseTask(executor, requestChannel));
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:MultiPartParserDefinition.java

示例3: parse

import io.undertow.server.HttpHandler; //導入方法依賴的package包/類
@Override
public void parse(HttpHandler handler) throws Exception {
    if (exchange.getAttachment(FORM_DATA) != null) {
        handler.handleRequest(exchange);
        return;
    }
    this.handler = handler;
    StreamSourceChannel channel = exchange.getRequestChannel();
    if (channel == null) {
        throw new IOException(UndertowMessages.MESSAGES.requestChannelAlreadyProvided());
    } else {
        doParse(channel);
        if (state != 4) {
            channel.getReadSetter().set(this);
            channel.resumeReads();
        } else {
            exchange.dispatch(SameThreadExecutor.INSTANCE, handler);
        }
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:FormEncodedDataDefinition.java

示例4: handleRequest

import io.undertow.server.HttpHandler; //導入方法依賴的package包/類
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    final String hostHeader = exchange.getRequestHeaders().getFirst(Headers.HOST);
    if (hostHeader != null) {
        String host;
        if (hostHeader.contains(":")) { //header can be in host:port format
            host = hostHeader.substring(0, hostHeader.lastIndexOf(":"));
        } else {
            host = hostHeader;
        }
        final HttpHandler handler = hosts.get(host);
        if (handler != null) {
            handler.handleRequest(exchange);
            return;
        }
    }
    defaultHandler.handleRequest(exchange);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:NameVirtualHostHandler.java

示例5: handleRequest

import io.undertow.server.HttpHandler; //導入方法依賴的package包/類
public void handleRequest(final HttpServerExchange exchange, final HttpHandler next) throws Exception {
    long oldVal, newVal;
    do {
        oldVal = state;
        final long current = oldVal & MASK_CURRENT;
        final long max = (oldVal & MASK_MAX) >> 32L;
        if (current >= max) {
            exchange.dispatch(SameThreadExecutor.INSTANCE, new Runnable() {
                @Override
                public void run() {
                    if (!queue.offer(new SuspendedRequest(exchange, next))) {
                        Connectors.executeRootHandler(failureHandler, exchange);
                    }
                }
            });
            return;
        }
        newVal = oldVal + 1;
    } while (!stateUpdater.compareAndSet(this, oldVal, newVal));
    exchange.addExchangeCompleteListener(COMPLETION_LISTENER);
    next.handleRequest(exchange);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:RequestLimit.java

示例6: redirector

import io.undertow.server.HttpHandler; //導入方法依賴的package包/類
public static HttpHandler redirector(HttpHandler next) {
    return (HttpServerExchange exchange) -> {
        HttpUrl currentUrl = Exchange.urls().currentUrl(exchange);
        String protocolForward = Exchange.headers().getHeader(exchange, "X-Forwarded-Proto").orElse(null);
        String host = currentUrl.host();
        boolean redirect = false;

        Builder newUrlBuilder = currentUrl.newBuilder();

        if (host.equals("stubbornjava.com")) {
            host = "www." + host;
            newUrlBuilder.host(host);
            redirect = true;
            logger.debug("Host {} does not start with www redirecting to {}", currentUrl.host(), host);
        }

        if (null != protocolForward && protocolForward.equalsIgnoreCase("http")) {
            logger.debug("non https switching to https", currentUrl.host(), host);
            newUrlBuilder.scheme("https")
                         .port(443);
            redirect = true;
        }

        if (redirect) {
            HttpUrl newUrl = newUrlBuilder.build();
            exchange.setStatusCode(301);
            exchange.getResponseHeaders().put(Headers.LOCATION, newUrl.toString());
            exchange.endExchange();
            return;
        }
        next.handleRequest(exchange);
    };
}
 
開發者ID:StubbornJava,項目名稱:StubbornJava,代碼行數:34,代碼來源:PageRoutes.java

示例7: allowFromDynamicOrigin

import io.undertow.server.HttpHandler; //導入方法依賴的package包/類
public static HttpHandler allowFromDynamicOrigin(HttpHandler next,
                                    Function<HttpServerExchange, String> originExtractor) {
    // Since this is dynamic skip using the SetHeaderHandler
    return exchange -> {
        exchange.getResponseHeaders().put(X_FRAME_OPTIONS, originExtractor.apply(exchange));
        next.handleRequest(exchange);
    };
}
 
開發者ID:StubbornJava,項目名稱:StubbornJava,代碼行數:9,代碼來源:XFrameOptionsHandlers.java

示例8: handleRequest

import io.undertow.server.HttpHandler; //導入方法依賴的package包/類
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    HttpHandler next = predicate.resolve(exchange) ? trueHandler : falseHandler;
    next.handleRequest(exchange);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:6,代碼來源:PredicateHandler.java


注:本文中的io.undertow.server.HttpHandler.handleRequest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。