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


Java HttpServerExchange.getRequestHeaders方法代码示例

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


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

示例1: handleRequest

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    if(exchange.getRequestMethod().equals(Methods.TRACE)) {
        exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "message/http");
        StringBuilder body = new StringBuilder("TRACE ");
        body.append(exchange.getRequestURI());
        if(!exchange.getQueryString().isEmpty()) {
            body.append('?');
            body.append(exchange.getQueryString());
        }
        body.append(exchange.getProtocol().toString());
        body.append("\r\n");
        for(HeaderValues header : exchange.getRequestHeaders()) {
            for(String value : header) {
                body.append(header.getHeaderName());
                body.append(": ");
                body.append(value);
                body.append("\r\n");
            }
        }
        body.append("\r\n");
        exchange.getResponseSender().send(body.toString());
    } else {
        handler.handleRequest(exchange);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:HttpTraceHandler.java

示例2: reservationCheck

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
protected boolean reservationCheck(HttpServerExchange exchange) {
    HeaderMap requestHeaders = exchange.getRequestHeaders();
    String origin = requestHeaders.getFirst(CorsHeaders.ORIGIN);
    if (cors.getAllowedOrigins().contains("*") || cors.getAllowedOrigins().contains(origin)) {
        HeaderMap responseHeaders = exchange.getResponseHeaders();
        responseHeaders.put(new HttpString(CorsHeaders.ACCESS_CONTROL_ALLOW_ORIGIN), origin);

        String value = requestHeaders.getFirst(CorsHeaders.ACCESS_CONTROL_REQUEST_HEADERS);
        if (value != null) {
            responseHeaders.put(new HttpString(CorsHeaders.ACCESS_CONTROL_ALLOW_HEADERS), value);
        }

        value = requestHeaders.getFirst(CorsHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS);
        if (value != null) {
            responseHeaders.put(new HttpString(CorsHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS), value);
        }

        value = requestHeaders.getFirst(CorsHeaders.ACCESS_CONTROL_REQUEST_METHOD);
        if (value != null) {
            responseHeaders.put(new HttpString(CorsHeaders.ACCESS_CONTROL_ALLOW_METHODS), value);
        }
    }

    String uri = exchange.getRequestURI();
    if (uri.indexOf(path + "/") != 0) {
        exchange.setStatusCode(404);
        return false;
    }

    final String subscriptionId = uri.substring(path.length() + 1);
    if (subscriptionId.isEmpty()) {
        exchange.setStatusCode(404);
        return false;
    }

    EventReservationsHandler.Reservation reservation = eventReservationsHandler.existsReservation(subscriptionId);
    if (reservation == null) {
        exchange.setStatusCode(404);
        return false;
    }
    return true;
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:43,代码来源:EventBusToServerSentEvents.java

示例3: trySaveRequest

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
public static void trySaveRequest(final HttpServerExchange exchange) {
    int maxSize = exchange.getConnection().getUndertowOptions().get(UndertowOptions.MAX_BUFFERED_REQUEST_SIZE, 16384);
    if (maxSize > 0) {
        //if this request has a body try and cache the response
        if (!exchange.isRequestComplete()) {
            final long requestContentLength = exchange.getRequestContentLength();
            if (requestContentLength > maxSize) {
                UndertowLogger.REQUEST_LOGGER.debugf("Request to %s was to large to save", exchange.getRequestURI());
                return;//failed to save the request, we just return
            }
            //TODO: we should really be used pooled buffers
            //TODO: we should probably limit the number of saved requests at any given time
            byte[] buffer = new byte[maxSize];
            int read = 0;
            int res = 0;
            InputStream in = exchange.getInputStream();
            try {
                while ((res = in.read(buffer, read, buffer.length - read)) > 0) {
                    read += res;
                    if (read == maxSize) {
                        UndertowLogger.REQUEST_LOGGER.debugf("Request to %s was to large to save", exchange.getRequestURI());
                        return;//failed to save the request, we just return
                    }
                }
                HeaderMap headers = new HeaderMap();
                for(HeaderValues entry : exchange.getRequestHeaders()) {
                    if(entry.getHeaderName().equals(Headers.CONTENT_LENGTH) ||
                            entry.getHeaderName().equals(Headers.TRANSFER_ENCODING) ||
                            entry.getHeaderName().equals(Headers.CONNECTION)) {
                        continue;
                    }
                    headers.putAll(entry.getHeaderName(), entry);
                }
                SavedRequest request = new SavedRequest(buffer, read, exchange.getRequestMethod(), exchange.getRequestPath(), exchange.getRequestHeaders());
                final ServletRequestContext sc = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
                HttpSessionImpl session = sc.getCurrentServletContext().getSession(exchange, true);
                Session underlyingSession;
                if(System.getSecurityManager() == null) {
                    underlyingSession = session.getSession();
                } else {
                    underlyingSession = AccessController.doPrivileged(new HttpSessionImpl.UnwrapSessionAction(session));
                }
                underlyingSession.setAttribute(SESSION_KEY, request);
            } catch (IOException e) {
                UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
            }
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:50,代码来源:SavedRequest.java

示例4: setupRequest

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
public static void setupRequest(final HttpServerExchange exchange) {
    final HeaderMap requestHeaders = exchange.getRequestHeaders();
    final String connectionHeader = requestHeaders.getFirst(Headers.CONNECTION);
    final String transferEncodingHeader = requestHeaders.getLast(Headers.TRANSFER_ENCODING);
    final String contentLengthHeader = requestHeaders.getFirst(Headers.CONTENT_LENGTH);

    final HttpServerConnection connection = (HttpServerConnection) exchange.getConnection();
    //if we are already using the pipelineing buffer add it to the exchange
    PipeliningBufferingStreamSinkConduit pipeliningBuffer = connection.getPipelineBuffer();
    if (pipeliningBuffer != null) {
        pipeliningBuffer.setupPipelineBuffer(exchange);
    }
    ConduitStreamSourceChannel sourceChannel = connection.getChannel().getSourceChannel();
    sourceChannel.setConduit(connection.getReadDataStreamSourceConduit());

    boolean persistentConnection = persistentConnection(exchange, connectionHeader);

    if (transferEncodingHeader == null && contentLengthHeader == null) {
        if (persistentConnection
                && connection.getExtraBytes() != null
                && pipeliningBuffer == null
                && connection.getUndertowOptions().get(UndertowOptions.BUFFER_PIPELINED_DATA, false)) {
            pipeliningBuffer = new PipeliningBufferingStreamSinkConduit(connection.getOriginalSinkConduit(), connection.getBufferPool());
            connection.setPipelineBuffer(pipeliningBuffer);
            pipeliningBuffer.setupPipelineBuffer(exchange);
        }
        // no content - immediately start the next request, returning an empty stream for this one
        Connectors.terminateRequest(exchange);
    } else {
        persistentConnection = handleRequestEncoding(exchange, transferEncodingHeader, contentLengthHeader, connection, pipeliningBuffer, persistentConnection);
    }

    exchange.setPersistent(persistentConnection);

    if (!exchange.isRequestComplete() || connection.getExtraBytes() != null) {
        //if there is more data we suspend reads
        sourceChannel.setReadListener(null);
        sourceChannel.suspendReads();
    }

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:42,代码来源:HttpTransferEncoding.java


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