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


Java HeaderMap类代码示例

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


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

示例1: handleFixedLength

import io.undertow.util.HeaderMap; //导入依赖的package包/类
private static StreamSinkConduit handleFixedLength(HttpServerExchange exchange, boolean headRequest, StreamSinkConduit channel, HeaderMap responseHeaders, String contentLengthHeader, HttpServerConnection connection) {
    try {
        final long contentLength = parsePositiveLong(contentLengthHeader);
        if (headRequest) {
            return channel;
        }
        // fixed-length response
        ServerFixedLengthStreamSinkConduit fixed = connection.getFixedLengthStreamSinkConduit();
        fixed.reset(contentLength, exchange);
        return fixed;
    } catch (NumberFormatException e) {
        //we just fix it for them
        responseHeaders.remove(Headers.CONTENT_LENGTH);
    }
    return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:HttpTransferEncoding.java

示例2: 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

示例3: beginPart

import io.undertow.util.HeaderMap; //导入依赖的package包/类
@Override
public void beginPart(final HeaderMap headers) {
    this.currentFileSize = 0;
    this.headers = headers;
    final String disposition = headers.getFirst(Headers.CONTENT_DISPOSITION);
    if (disposition != null) {
        if (disposition.startsWith("form-data")) {
            currentName = Headers.extractQuotedValueFromHeader(disposition, "name");
            fileName = Headers.extractQuotedValueFromHeader(disposition, "filename");
            if (fileName != null) {
                try {
                    file = File.createTempFile("undertow", "upload", tempFileLocation);
                    createdFiles.add(file);
                    fileChannel = exchange.getConnection().getWorker().getXnio().openFile(file, FileAccess.READ_WRITE);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:MultiPartParserDefinition.java

示例4: setCorsResponseHeaders

import io.undertow.util.HeaderMap; //导入依赖的package包/类
private void setCorsResponseHeaders(HttpServerExchange exchange) throws Exception {
    HeaderMap headers = exchange.getRequestHeaders();
    if (headers.contains(Headers.ORIGIN)) {
        if(matchOrigin(exchange, allowedOrigins) != null) {
            exchange.getResponseHeaders().addAll(ACCESS_CONTROL_ALLOW_ORIGIN, headers.get(Headers.ORIGIN));
            exchange.getResponseHeaders().add(Headers.VARY, Headers.ORIGIN_STRING);
        }
    }
    exchange.getResponseHeaders().addAll(ACCESS_CONTROL_ALLOW_METHODS, allowedMethods);
    HeaderValues requestedHeaders = headers.get(ACCESS_CONTROL_REQUEST_HEADERS);
    if (requestedHeaders != null && !requestedHeaders.isEmpty()) {
        exchange.getResponseHeaders().addAll(ACCESS_CONTROL_ALLOW_HEADERS, requestedHeaders);
    } else {
        exchange.getResponseHeaders().add(ACCESS_CONTROL_ALLOW_HEADERS, Headers.CONTENT_TYPE_STRING);
        exchange.getResponseHeaders().add(ACCESS_CONTROL_ALLOW_HEADERS, Headers.WWW_AUTHENTICATE_STRING);
        exchange.getResponseHeaders().add(ACCESS_CONTROL_ALLOW_HEADERS, Headers.AUTHORIZATION_STRING);
    }
    exchange.getResponseHeaders().add(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
    exchange.getResponseHeaders().add(ACCESS_CONTROL_MAX_AGE, ONE_HOUR_IN_SECONDS);
}
 
开发者ID:networknt,项目名称:light-4j,代码行数:21,代码来源:CorsHttpHandler.java

示例5: testMatchOrigin

import io.undertow.util.HeaderMap; //导入依赖的package包/类
/**
 * Test of matchOrigin method, of class CorsUtil.
 */
@Test
public void testMatchOrigin() throws Exception {
    HeaderMap headerMap = new HeaderMap();
    headerMap.add(HOST, "localhost:80");
    headerMap.add(ORIGIN, "http://localhost");
    HttpServerExchange exchange = new HttpServerExchange(null, headerMap, new HeaderMap(), 10);
    exchange.setRequestScheme("http");
    exchange.setRequestMethod(HttpString.EMPTY);
    Collection<String> allowedOrigins = null;
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://localhost"));
    allowedOrigins = Collections.singletonList("http://www.example.com:9990");
    //Default origin
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://localhost"));
    headerMap.clear();
    headerMap.add(HOST, "localhost:80");
    headerMap.add(ORIGIN, "http://www.example.com:9990");
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://www.example.com:9990"));
    headerMap.clear();
    headerMap.add(HOST, "localhost:80");
    headerMap.add(ORIGIN, "http://www.example.com");
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is(nullValue()));
    headerMap.addAll(ORIGIN, Arrays.asList("http://localhost:8080", "http://www.example.com:9990", "http://localhost"));
    allowedOrigins = Arrays.asList("http://localhost", "http://www.example.com:9990");
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://localhost"));
}
 
开发者ID:networknt,项目名称:light-4j,代码行数:29,代码来源:CorsUtilTest.java

示例6: testDefaultOrigin

import io.undertow.util.HeaderMap; //导入依赖的package包/类
/**
 * Test of defaultOrigin method, of class CorsUtil.
 */
@Test
public void testDefaultOrigin() {
    HeaderMap headerMap = new HeaderMap();
    headerMap.add(HOST, "localhost:80");
    HttpServerExchange exchange = new HttpServerExchange(null, headerMap, new HeaderMap(), 10);
    exchange.setRequestScheme("http");
    assertThat(CorsUtil.defaultOrigin(exchange), is("http://localhost"));
    headerMap.clear();
    headerMap.add(HOST, "www.example.com:8080");
    assertThat(CorsUtil.defaultOrigin(exchange), is("http://www.example.com:8080"));
    headerMap.clear();
    headerMap.add(HOST, "www.example.com:443");
    exchange.setRequestScheme("https");
    assertThat(CorsUtil.defaultOrigin(exchange), is("https://www.example.com"));
    headerMap.clear();
    exchange.setRequestScheme("http");
    headerMap.add(HOST, "[::1]:80");
    assertThat(CorsUtil.defaultOrigin(exchange), is("http://[::1]"));
}
 
开发者ID:networknt,项目名称:light-4j,代码行数:23,代码来源:CorsUtilTest.java

示例7: validateHeader

import io.undertow.util.HeaderMap; //导入依赖的package包/类
private void validateHeader(final UaiHeader uaiHeader, final HeaderMap requestHeaderMap, final RequestValidatorFacade.RequestAnalysisResult result) {
    final HeaderValues headerValueList = requestHeaderMap.get(uaiHeader.getName());

    if (headerValueList == null) {
        Log.infoFormatted(OPTIONAL_HEADER_NOT_FOUND, uaiHeader.getName());
        result.setInvalid();
        return;
    }

    if (uaiHeader.isUsingWildCard()) {
        Log.infoFormatted(WILD_CARD_USED, uaiHeader.getName());
        return;
    }

    if (!headerValueList.containsAll(uaiHeader.getValueList())) {
        Log.warnFormatted(HEADER_VALUE_NOT_FOUND_MESSAGE, uaiHeader.getValueList(), uaiHeader.getName());
        result.abortTheRequest();
    }
}
 
开发者ID:uaihebert,项目名称:uaiMockServer,代码行数:20,代码来源:OptionalHeaderValidator.java

示例8: validateHeader

import io.undertow.util.HeaderMap; //导入依赖的package包/类
private void validateHeader(final UaiHeader uaiHeader, final HeaderMap requestHeaderMap, final RequestValidatorFacade.RequestAnalysisResult result) {
    final HeaderValues headerValueList = requestHeaderMap.get(uaiHeader.getName());

    if (headerValueList == null) {
        Log.warnFormatted(REQUIRED_HEADER_NOT_FOUND, uaiHeader.getName());
        result.setInvalid();
        return;
    }

    if (uaiHeader.isUsingWildCard()) {
        Log.infoFormatted(WILD_CARD_USED, uaiHeader.getName());
        return;
    }

    if (!headerValueList.containsAll(uaiHeader.getValueList())) {
        Log.warnFormatted(HEADER_VALUE_NOT_FOUND_MESSAGE, uaiHeader.getValueList(), uaiHeader.getName());
        result.setInvalid();
    }
}
 
开发者ID:uaihebert,项目名称:uaiMockServer,代码行数:20,代码来源:RequiredHeaderValidator.java

示例9: handleRequest

import io.undertow.util.HeaderMap; //导入依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
  if(exchange.isInIoThread()) {
    exchange.dispatch(this);
    return;
  }

  if(logger.isTraceEnabled()) {
    logger.trace("Attach CORS headers");
  }

  HeaderMap httpHeaders = exchange.getResponseHeaders();
  HeaderMap requestHeaders = exchange.getRequestHeaders();

  String methods = requestHeaders.getFirst("Access-Control-Request-Method");
  if(methods != null) {
    httpHeaders.addFirst(new HttpString("Access-Control-Allow-Methods"), methods);
  }

  String headers = requestHeaders.getFirst("Access-Control-Request-Headers");
  if(headers != null) {
    httpHeaders.addFirst(new HttpString("Access-Control-Allow-Headers"), headers);
  }

  httpHeaders.addFirst(new HttpString("Access-Control-Allow-Credentials"), "true");
}
 
开发者ID:vvergnolle,项目名称:vas,代码行数:27,代码来源:CorsHttpHandler.java

示例10: handleRequest

import io.undertow.util.HeaderMap; //导入依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    HeaderMap responseHeader = exchange.getResponseHeaders();
    responseHeader.add(PROCESSED_BY, "ResponseHandler");
    String undertowUser = getUndertowUser(exchange);
    if (undertowUser != null) {
        responseHeader.add(UNDERTOW_USER, undertowUser);
    }
    String elytronUser = getElytronUser();
    if (elytronUser != null) {
        responseHeader.add(ELYTRON_USER, elytronUser);
    }
    if (exchange.getQueryParameters().get("logout") != null) {
        exchange.getSecurityContext().logout();
    }

    exchange.endExchange();
}
 
开发者ID:wildfly-security,项目名称:elytron-web,代码行数:19,代码来源:TestResponseHandler.java

示例11: exchangeEvent

import io.undertow.util.HeaderMap; //导入依赖的package包/类
@Override
public void exchangeEvent(HttpServerExchange exchange, NextListener nextListener) {
    try {
        long end = System.currentTimeMillis();
        long duration = end - start;
        if (duration > this.timeThreshold) {
            String method = exchange.getRequestMethod().toString();
            String query = exchange.getQueryString();
            String request_url = exchange.getRequestURI() + (query.isEmpty() ? "" : ("?" + query));
            HeaderMap headers = exchange.getRequestHeaders();
            if (headers.contains(tenantHeader)) {
                String tenantId = headers.get(tenantHeader, 0);
                log.warnf("Request %s %s took: %d ms, exceeds %d ms threshold, tenant-id: %s",
                        method, request_url, duration, timeThreshold, tenantId);
            } else {
                log.warnf("Request %s %s took: %d ms, exceeds %d ms threshold, no tenant",
                        method, request_url, duration, timeThreshold);
            }

        }
    } finally {
        if (nextListener != null) {
            nextListener.proceed();
        }
    }
}
 
开发者ID:hawkular,项目名称:hawkular-metrics,代码行数:27,代码来源:RequestTimeLogger.java

示例12: 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

示例13: setCorsResponseHeaders

import io.undertow.util.HeaderMap; //导入依赖的package包/类
private void setCorsResponseHeaders(HttpServerExchange exchange) throws Exception {
    HeaderMap headers = exchange.getRequestHeaders();
    if (headers.contains(Headers.ORIGIN)) {
        if(matchOrigin(exchange, allowedOrigins) != null) {
            exchange.getResponseHeaders().addAll(ACCESS_CONTROL_ALLOW_ORIGIN, headers.get(Headers.ORIGIN));
            exchange.getResponseHeaders().add(Headers.VARY, Headers.ORIGIN_STRING);
        }
    }
    HeaderValues requestedMethods = headers.get(ACCESS_CONTROL_REQUEST_METHOD);
    if (requestedMethods != null && !requestedMethods.isEmpty()) {
        exchange.getResponseHeaders().addAll(ACCESS_CONTROL_ALLOW_METHODS, requestedMethods);
    } else {
        exchange.getResponseHeaders().addAll(ACCESS_CONTROL_ALLOW_METHODS, Arrays.asList(new String[]{Methods.GET_STRING, Methods.POST_STRING}));
    }
    HeaderValues requestedHeaders = headers.get(ACCESS_CONTROL_REQUEST_HEADERS);
    if (requestedHeaders != null && !requestedHeaders.isEmpty()) {
        exchange.getResponseHeaders().addAll(ACCESS_CONTROL_ALLOW_HEADERS, requestedHeaders);
    } else {
        exchange.getResponseHeaders().add(ACCESS_CONTROL_ALLOW_HEADERS, Headers.CONTENT_TYPE_STRING);
        exchange.getResponseHeaders().add(ACCESS_CONTROL_ALLOW_HEADERS, Headers.WWW_AUTHENTICATE_STRING);
        exchange.getResponseHeaders().add(ACCESS_CONTROL_ALLOW_HEADERS, Headers.AUTHORIZATION_STRING);
    }
    exchange.getResponseHeaders().add(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
    exchange.getResponseHeaders().add(ACCESS_CONTROL_MAX_AGE, ONE_HOUR_IN_SECONDS);
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:26,代码来源:CorsHttpHandler.java

示例14: testMatchOrigin

import io.undertow.util.HeaderMap; //导入依赖的package包/类
/**
 * Test of matchOrigin method, of class CorsUtil.
 */
@Test
public void testMatchOrigin() throws Exception {
    HeaderMap headerMap = new HeaderMap();
    headerMap.add(HOST, "localhost:80");
    headerMap.add(ORIGIN, "http://localhost");
    HttpServerExchange exchange = new HttpServerExchange(null, headerMap, new HeaderMap(), 10);
    exchange.setRequestScheme("http");
    Collection<String> allowedOrigins = null;
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://localhost"));
    allowedOrigins = Collections.singletonList("http://www.example.com:9990");
    //Default origin
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://localhost"));
    headerMap.clear();
    headerMap.add(HOST, "localhost:80");
    headerMap.add(ORIGIN, "http://www.example.com:9990");
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://www.example.com:9990"));
    headerMap.clear();
    headerMap.add(HOST, "localhost:80");
    headerMap.add(ORIGIN, "http://www.example.com");
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is(nullValue()));
    headerMap.addAll(ORIGIN, Arrays.asList("http://localhost:8080", "http://www.example.com:9990", "http://localhost"));
    allowedOrigins = Arrays.asList("http://localhost", "http://www.example.com:9990");
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://localhost"));
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:28,代码来源:CorsUtilTest.java

示例15: testNotOverride

import io.undertow.util.HeaderMap; //导入依赖的package包/类
@Test
public void testNotOverride() throws Exception {
	HttpServerExchange exchange = new MockUp<HttpServerExchange>() {
		@Mock
		public HeaderMap getRequestHeaders() {
			throw new AssertionError();
		}

		@Mock
		public <T> T getAttachment(final AttachmentKey<T> key) {
			throw new AssertionError();
		}
	}.getMockInstance();

	exchange.setRequestMethod(Methods.GET);

	this.target.handleRequest(exchange);
}
 
开发者ID:taichi,项目名称:siden,代码行数:19,代码来源:MethodOverrideHandlerTest.java


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