当前位置: 首页>>代码示例>>Java>>正文


Java HttpServerExchange.startBlocking方法代码示例

本文整理汇总了Java中io.undertow.server.HttpServerExchange.startBlocking方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServerExchange.startBlocking方法的具体用法?Java HttpServerExchange.startBlocking怎么用?Java HttpServerExchange.startBlocking使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.undertow.server.HttpServerExchange的用法示例。


在下文中一共展示了HttpServerExchange.startBlocking方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendContinueResponseBlocking

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
/**
 * Sends a continue response using blocking IO
 *
 * @param exchange The exchange
 */
public static void sendContinueResponseBlocking(final HttpServerExchange exchange) throws IOException {
    if (!exchange.isResponseChannelAvailable()) {
        throw UndertowMessages.MESSAGES.cannotSendContinueResponse();
    }
    if(exchange.getAttachment(ALREADY_SENT) != null) {
        return;
    }
    HttpServerExchange newExchange = exchange.getConnection().sendOutOfBandResponse(exchange);
    exchange.putAttachment(ALREADY_SENT, true);
    newExchange.setResponseCode(StatusCodes.CONTINUE);
    newExchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, 0);
    newExchange.startBlocking();
    newExchange.getOutputStream().close();
    newExchange.getInputStream().close();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:HttpContinue.java

示例2: handleRequest

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {

    exchange.startBlocking();
    if (exchange.isInIoThread()) {
        exchange.dispatch(handler);
    } else {
        handler.handleRequest(exchange);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:BlockingHandler.java

示例3: dispatchMockRequest

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void dispatchMockRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException {

    final ByteBufferSlicePool bufferPool = new ByteBufferSlicePool(BufferAllocator.BYTE_BUFFER_ALLOCATOR, 1024, 1024);
    MockServerConnection connection = new MockServerConnection(bufferPool);
    HttpServerExchange exchange = new HttpServerExchange(connection);
    exchange.setRequestScheme(request.getScheme());
    exchange.setRequestMethod(new HttpString(request.getMethod()));
    exchange.setProtocol(Protocols.HTTP_1_0);
    exchange.setResolvedPath(request.getContextPath());
    String relative;
    if (request.getPathInfo() == null) {
        relative = request.getServletPath();
    } else {
        relative = request.getServletPath() + request.getPathInfo();
    }
    exchange.setRelativePath(relative);
    final ServletPathMatch info = paths.getServletHandlerByPath(request.getServletPath());
    final HttpServletResponseImpl oResponse = new HttpServletResponseImpl(exchange, servletContext);
    final HttpServletRequestImpl oRequest = new HttpServletRequestImpl(exchange, servletContext);
    final ServletRequestContext servletRequestContext = new ServletRequestContext(servletContext.getDeployment(), oRequest, oResponse, info);
    servletRequestContext.setServletRequest(request);
    servletRequestContext.setServletResponse(response);
    //set the max request size if applicable
    if (info.getServletChain().getManagedServlet().getMaxRequestSize() > 0) {
        exchange.setMaxEntitySize(info.getServletChain().getManagedServlet().getMaxRequestSize());
    }
    exchange.putAttachment(ServletRequestContext.ATTACHMENT_KEY, servletRequestContext);

    exchange.startBlocking(new ServletBlockingHttpExchange(exchange));
    servletRequestContext.setServletPathMatch(info);

    try {
        dispatchRequest(exchange, servletRequestContext, info.getServletChain(), DispatcherType.REQUEST);
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        throw new ServletException(e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:42,代码来源:ServletInitialHandler.java

示例4: createAdminApp

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
private HttpHandler createAdminApp(WebApplication application) {
    return new HttpHandler() {
        @Override
        public void handleRequest(HttpServerExchange exchange) throws Exception {
            if (exchange.isInIoThread()) {
                exchange.dispatch(this);
                return;
            }
            HttpRequest request = new DefaultHttpRequest();
            request.setRequestMethod(exchange.getRequestMethod().toString());
            request.setUri(exchange.getRequestURI());
            request.setProtocol(exchange.getProtocol().toString());
            request.setQueryString(exchange.getQueryString());
            request.setCharacterEncoding(exchange.getRequestCharset());
            request.setBody(new ChannelInputStream(exchange.getRequestChannel()));
            request.setContentLength(exchange.getRequestContentLength());
            request.setRemoteAddr(exchange.getSourceAddress()
                    .getAddress()
                    .getHostAddress());
            request.setScheme(exchange.getRequestScheme());
            request.setServerName(exchange.getHostName());
            request.setServerPort(exchange.getHostPort());

            Headers headers = Headers.empty();
            exchange.getRequestHeaders().forEach(e -> {
                String headerName = e.getHeaderName().toString();
                e.forEach(v -> headers.put(headerName, v));
            });
            some(exchange.getSecurityContext(),
                    SecurityContext::getAuthenticatedAccount,
                    Account::getPrincipal,
                    principal -> headers.put("X-Client-DN", principal.getName()));
            request.setHeaders(headers);

            try {
                HttpResponse response = application.handle(request);
                exchange.setStatusCode(response.getStatus());
                setResponseHeaders(response.getHeaders(), exchange);
                exchange.startBlocking();
                setBody(exchange.getResponseSender(), response.getBody());
            } catch (ServiceUnavailableException ex) {
                exchange.setStatusCode(503);
            } finally {
                exchange.endExchange();
            }
        }
    };
}
 
开发者ID:kawasima,项目名称:bouncr,代码行数:49,代码来源:ReverseProxyComponent.java


注:本文中的io.undertow.server.HttpServerExchange.startBlocking方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。