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


Java HeaderMap.put方法代码示例

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


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

示例1: handleExplicitTransferEncoding

import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
private static StreamSinkConduit handleExplicitTransferEncoding(HttpServerExchange exchange, StreamSinkConduit channel, ConduitListener<StreamSinkConduit> finishListener, HeaderMap responseHeaders, String transferEncodingHeader, boolean headRequest) {
    HttpString transferEncoding = new HttpString(transferEncodingHeader);
    if (transferEncoding.equals(Headers.CHUNKED)) {
        if (headRequest) {
            return channel;
        }
        Boolean preChunked = exchange.getAttachment(HttpAttachments.PRE_CHUNKED_RESPONSE);
        if(preChunked != null && preChunked) {
            return new PreChunkedStreamSinkConduit(channel, finishListener, exchange);
        } else {
            return new ChunkedStreamSinkConduit(channel, exchange.getConnection().getBufferPool(), true, !exchange.isPersistent(), responseHeaders, finishListener, exchange);
        }
    } else {

        if (headRequest) {
            return channel;
        }
        log.trace("Cancelling persistence because response is identity with no content length");
        // make it not persistent - very unfortunate for the next request handler really...
        exchange.setPersistent(false);
        responseHeaders.put(Headers.CONNECTION, Headers.CLOSE.toString());
        return new FinishableStreamSinkConduit(channel, terminateResponseListener(exchange));
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:HttpTransferEncoding.java

示例2: writeResponse

import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
public static void writeResponse(final HttpServerExchange exchange, final int status, ModelNode response,
        OperationParameter operationParameter) {

    exchange.setStatusCode(status);

    final HeaderMap responseHeaders = exchange.getResponseHeaders();
    final String contentType = operationParameter.isEncode() ? Common.APPLICATION_DMR_ENCODED : Common.APPLICATION_JSON;
    responseHeaders.put(Headers.CONTENT_TYPE, contentType + "; charset=" + Common.UTF_8);

    writeCacheHeaders(exchange, status, operationParameter);

    if (operationParameter.isGet() && status == 200) {
        // For GET request the response is purely the model nodes result. The outcome
        // is not send as part of the response but expressed with the HTTP status code.
        response = response.get(RESULT);
    }
    try {
        byte[] data = getResponseBytes(response, operationParameter);
        responseHeaders.put(Headers.CONTENT_LENGTH, data.length);
        exchange.getResponseSender().send(ByteBuffer.wrap(data));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:25,代码来源:DomainUtil.java

示例3: handleResponseConduit

import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
private static StreamSinkConduit handleResponseConduit(HttpServerExchange exchange, boolean headRequest, StreamSinkConduit channel, HeaderMap responseHeaders, ConduitListener<StreamSinkConduit> finishListener, String transferEncodingHeader) {

        if (transferEncodingHeader == null) {
            if (exchange.isHttp11()) {
                if (exchange.isPersistent()) {
                    responseHeaders.put(Headers.TRANSFER_ENCODING, Headers.CHUNKED.toString());

                    if (headRequest) {
                        return channel;
                    }
                    return new ChunkedStreamSinkConduit(channel, exchange.getConnection().getBufferPool(), true, !exchange.isPersistent(), responseHeaders, finishListener, exchange);
                } else {
                    if (headRequest) {
                        return channel;
                    }
                    return new FinishableStreamSinkConduit(channel, finishListener);
                }
            } else {
                exchange.setPersistent(false);
                responseHeaders.put(Headers.CONNECTION, Headers.CLOSE.toString());
                if (headRequest) {
                    return channel;
                }
                return new FinishableStreamSinkConduit(channel, finishListener);
            }
        } else {
            //moved outside because this is rarely used
            //and makes the method small enough to be inlined
            return handleExplicitTransferEncoding(exchange, channel, finishListener, responseHeaders, transferEncodingHeader, headRequest);
        }
    }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:32,代码来源:HttpTransferEncoding.java

示例4: upgradeChannel

import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
/**
 * Upgrade the channel to a raw socket. This method set the response code to 101, and then marks both the
 * request and response as terminated, which means that once the current request is completed the raw channel
 * can be obtained from {@link io.undertow.server.protocol.http.HttpServerConnection#getChannel()}
 *
 * @param productName the product name to report to the client
 * @throws IllegalStateException if a response or upgrade was already sent, or if the request body is already being
 *                               read
 */
public HttpServerExchange upgradeChannel(String productName, final HttpUpgradeListener listener) {
    if (!connection.isUpgradeSupported()) {
        throw UndertowMessages.MESSAGES.upgradeNotSupported();
    }
    connection.setUpgradeListener(listener);
    setResponseCode(StatusCodes.SWITCHING_PROTOCOLS);
    final HeaderMap headers = getResponseHeaders();
    headers.put(Headers.UPGRADE, productName);
    headers.put(Headers.CONNECTION, Headers.UPGRADE_STRING);
    return this;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:HttpServerExchange.java

示例5: testIsJsonRequest

import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
@Test
public void testIsJsonRequest() {
       //given
	HttpServerExchange mockedExchange = Mockito.mock(HttpServerExchange.class);
   		RequestHelper helper = Application.getInstance(RequestHelper.class);
   		HeaderMap headerMap = new HeaderMap();
   		headerMap.put(Header.CONTENT_TYPE.toHttpString(), MediaType.JSON_UTF_8.withoutParameters().toString());
   		
   		//when
   		when(mockedExchange.getRequestHeaders()).thenReturn(headerMap);
   		boolean isJson = helper.isJsonRequest(mockedExchange);
   	
       //then
       assertThat(isJson, equalTo(true));
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:16,代码来源:RequestHelperTest.java

示例6: testIsNonJsonRequest

import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
@Test
public void testIsNonJsonRequest() {
       //given
	HttpServerExchange mockedExchange = Mockito.mock(HttpServerExchange.class);
   		RequestHelper helper = Application.getInstance(RequestHelper.class);
   		HeaderMap headerMap = new HeaderMap();
   		headerMap.put(Header.CONTENT_TYPE.toHttpString(), MediaType.CSS_UTF_8.withoutParameters().toString());
   		
   		//when
   		when(mockedExchange.getRequestHeaders()).thenReturn(headerMap);
   		boolean isJson = helper.isJsonRequest(mockedExchange);
   	
       //then
       assertThat(isJson, equalTo(false));
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:16,代码来源:RequestHelperTest.java

示例7: writeCacheHeaders

import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
static void writeCacheHeaders(final HttpServerExchange exchange, final int status, final OperationParameter operationParameter) {
    final HeaderMap responseHeaders = exchange.getResponseHeaders();

    // No need to send this in a 304
    // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
    if (operationParameter.getMaxAge() > 0 && status != 304) {
        responseHeaders.put(Headers.CACHE_CONTROL, "max-age=" + operationParameter.getMaxAge() + ", private, must-revalidate");
    }
    if (operationParameter.getEtag() != null) {
        responseHeaders.put(Headers.ETAG, operationParameter.getEtag().toString());
    }
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:13,代码来源:DomainUtil.java

示例8: reservationCheck

import io.undertow.util.HeaderMap; //导入方法依赖的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

示例9: createSinkConduit

import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
static StreamSinkConduit createSinkConduit(final HttpServerExchange exchange) {
    DateUtils.addDateHeaderIfRequired(exchange);

    boolean headRequest = exchange.getRequestMethod().equals(Methods.HEAD);
    HttpServerConnection serverConnection = (HttpServerConnection) exchange.getConnection();

    HttpResponseConduit responseConduit = serverConnection.getResponseConduit();
    responseConduit.reset(exchange);
    StreamSinkConduit channel = responseConduit;
    if (headRequest) {
        //if this is a head request we add a head channel underneath the content encoding channel
        //this will just discard the data
        //we still go through with the rest of the logic, to make sure all headers are set correctly
        channel = new HeadStreamSinkConduit(channel, terminateResponseListener(exchange));
    } else if(!Connectors.isEntityBodyAllowed(exchange)) {
        //we are not allowed to send an entity body for some requests
        exchange.getResponseHeaders().remove(Headers.CONTENT_LENGTH);
        exchange.getResponseHeaders().remove(Headers.TRANSFER_ENCODING);
        channel = new HeadStreamSinkConduit(channel, terminateResponseListener(exchange));
    }

    final HeaderMap responseHeaders = exchange.getResponseHeaders();
    // test to see if we're still persistent
    String connection = responseHeaders.getFirst(Headers.CONNECTION);
    if (!exchange.isPersistent()) {
        responseHeaders.put(Headers.CONNECTION, Headers.CLOSE.toString());
    } else if (exchange.isPersistent() && connection != null) {
        if (HttpString.tryFromString(connection).equals(Headers.CLOSE)) {
            exchange.setPersistent(false);
        }
    } else if (exchange.getConnection().getUndertowOptions().get(UndertowOptions.ALWAYS_SET_KEEP_ALIVE, true)) {
        responseHeaders.put(Headers.CONNECTION, Headers.KEEP_ALIVE.toString());
    }
    //according to the HTTP RFC we should ignore content length if a transfer coding is specified
    final String transferEncodingHeader = responseHeaders.getLast(Headers.TRANSFER_ENCODING);
    if(transferEncodingHeader == null) {
        final String contentLengthHeader = responseHeaders.getFirst(Headers.CONTENT_LENGTH);
        if (contentLengthHeader != null) {
            StreamSinkConduit res = handleFixedLength(exchange, headRequest, channel, responseHeaders, contentLengthHeader, serverConnection);
            if (res != null) {
                return res;
            }
        }
    }
    return handleResponseConduit(exchange, headRequest, channel, responseHeaders, terminateResponseListener(exchange), transferEncodingHeader);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:47,代码来源:HttpTransferEncoding.java


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