Java Code Examples for org.springframework.http.HttpHeaders#entrySet()

The following examples show how to use org.springframework.http.HttpHeaders#entrySet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Netty4ClientHttpRequest.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private FullHttpRequest createFullHttpRequest(HttpHeaders headers) {
	io.netty.handler.codec.http.HttpMethod nettyMethod =
			io.netty.handler.codec.http.HttpMethod.valueOf(this.method.name());

	FullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
			nettyMethod, this.uri.toString(), this.body.buffer());

	nettyRequest.headers().set(HttpHeaders.HOST, uri.getHost());
	nettyRequest.headers().set(HttpHeaders.CONNECTION, io.netty.handler.codec.http.HttpHeaders.Values.CLOSE);

	for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
		nettyRequest.headers().add(entry.getKey(), entry.getValue());
	}

	return nettyRequest;
}
 
Example 2
Source File: RequestLoggingInterceptor.java    From sinavi-jfw with Apache License 2.0 6 votes vote down vote up
private void dumpHttpHeader(StringBuilder sb, final String prefix, HttpHeaders headers) {
    for (Map.Entry<String, List<String>> e : headers.entrySet()) {
        String key = e.getKey();
        List<String> value = e.getValue();
        if (value.size() == 1) {
            sb.append(prefix).append(key).append(DELIMITER).append(value.get(0)).append(LS);
        } else {
            StringBuilder b = new StringBuilder();
            boolean add = false;
            for (String s : value) {
                if (add) b.append(',');
                add = true;
                b.append(s);
            }
            sb.append(prefix).append(key).append(DELIMITER).append(b.toString()).append(LS);
        }
    }
}
 
Example 3
Source File: Netty4ClientHttpRequest.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private FullHttpRequest createFullHttpRequest(HttpHeaders headers) {
	io.netty.handler.codec.http.HttpMethod nettyMethod =
			io.netty.handler.codec.http.HttpMethod.valueOf(this.method.name());

	String authority = this.uri.getRawAuthority();
	String path = this.uri.toString().substring(this.uri.toString().indexOf(authority) + authority.length());
	FullHttpRequest nettyRequest = new DefaultFullHttpRequest(
			HttpVersion.HTTP_1_1, nettyMethod, path, this.body.buffer());

	nettyRequest.headers().set(HttpHeaders.HOST, this.uri.getHost() + ":" + getPort(uri));
	nettyRequest.headers().set(HttpHeaders.CONNECTION, "close");
	for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
		nettyRequest.headers().add(entry.getKey(), entry.getValue());
	}
	if (!nettyRequest.headers().contains(HttpHeaders.CONTENT_LENGTH) && this.body.buffer().readableBytes() > 0) {
		nettyRequest.headers().set(HttpHeaders.CONTENT_LENGTH, this.body.buffer().readableBytes());
	}

	return nettyRequest;
}
 
Example 4
Source File: NettyRequest.java    From haven-platform with Apache License 2.0 6 votes vote down vote up
private FullHttpRequest createFullHttpRequest(HttpHeaders headers) {
    io.netty.handler.codec.http.HttpMethod nettyMethod =
      io.netty.handler.codec.http.HttpMethod.valueOf(this.method.name());

    FullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
      nettyMethod, this.uri.toString(), this.body.buffer());

    io.netty.handler.codec.http.HttpHeaders nettyHeaders = nettyRequest.headers();
    nettyHeaders.set(HttpHeaders.HOST, this.uri.getHost());
    nettyHeaders.set(HttpHeaders.CONNECTION, "close");

    for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
        nettyHeaders.add(entry.getKey(), entry.getValue());
    }

    return nettyRequest;
}
 
Example 5
Source File: ResponseStatusExceptionMapper.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private void addHeaders(Response.ResponseBuilder responseBuilder, HttpHeaders springHeaders) {
    for (Map.Entry<String, List<String>> entry : springHeaders.entrySet()) {
        for (String headerValue : entry.getValue()) {
            responseBuilder.header(entry.getKey(), headerValue);
        }
    }
}
 
Example 6
Source File: ApiClient.java    From tutorials with MIT License 5 votes vote down vote up
/**
 * Add headers to the request that is being built
 * @param headers The headers to add
 * @param requestBuilder The current request
 */
protected void addHeadersToRequest(HttpHeaders headers, BodyBuilder requestBuilder) {
    for (Entry<String, List<String>> entry : headers.entrySet()) {
        List<String> values = entry.getValue();
        for(String value : values) {
            if (value != null) {
                requestBuilder.header(entry.getKey(), value);
            }
        }
    }
}
 
Example 7
Source File: ApiClient.java    From tutorials with MIT License 5 votes vote down vote up
/**
 * Add headers to the request that is being built
 * @param headers The headers to add
 * @param requestBuilder The current request
 */
protected void addHeadersToRequest(HttpHeaders headers, BodyBuilder requestBuilder) {
    for (Entry<String, List<String>> entry : headers.entrySet()) {
        List<String> values = entry.getValue();
        for(String value : values) {
            if (value != null) {
                requestBuilder.header(entry.getKey(), value);
            }
        }
    }
}
 
Example 8
Source File: RestTemplateEurekaHttpClient.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
private static Map<String, String> headersOf(ResponseEntity<?> response) {
	HttpHeaders httpHeaders = response.getHeaders();
	if (httpHeaders == null || httpHeaders.isEmpty()) {
		return Collections.emptyMap();
	}
	Map<String, String> headers = new HashMap<>();
	for (Entry<String, List<String>> entry : httpHeaders.entrySet()) {
		if (!entry.getValue().isEmpty()) {
			headers.put(entry.getKey(), entry.getValue().get(0));
		}
	}
	return headers;
}
 
Example 9
Source File: ApiClient.java    From tutorials with MIT License 5 votes vote down vote up
private String headersToString(HttpHeaders headers) {
    StringBuilder builder = new StringBuilder();
    for(Entry<String, List<String>> entry : headers.entrySet()) {
        builder.append(entry.getKey()).append("=[");
        for(String value : entry.getValue()) {
            builder.append(value).append(",");
        }
        builder.setLength(builder.length() - 1); // Get rid of trailing comma
        builder.append("],");
    }
    builder.setLength(builder.length() - 1); // Get rid of trailing comma
    return builder.toString();
}
 
Example 10
Source File: ResponseEntityConverter.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static Headers<Object> toJaxRsHeaders(HttpHeaders springHeaders) {
    Headers<Object> jaxRsHeaders = new Headers<>();
    for (Map.Entry<String, List<String>> entry : springHeaders.entrySet()) {
        jaxRsHeaders.addAll(entry.getKey(), entry.getValue().toArray(new Object[0]));
    }
    return jaxRsHeaders;
}
 
Example 11
Source File: AbstractRequestMappingIntegrationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void addHeaders(RequestEntity.HeadersBuilder<?> builder, HttpHeaders headers) {
	for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
		for (String value : entry.getValue()) {
			builder.header(entry.getKey(), value);
		}
	}
}
 
Example 12
Source File: MultipartBatchHttpMessageConverter.java    From documentum-rest-client-java with Apache License 2.0 5 votes vote down vote up
private void writeHeaders(OutputStream os, HttpHeaders headers) throws IOException {
    for(Map.Entry<String, List<String>> entry : headers.entrySet()) {
        for(String value : entry.getValue()) {
            os.write(entry.getKey().getBytes("UTF-8"));
            os.write(':');
            os.write(' ');
            os.write(value.getBytes("UTF-8"));
            writeNewLine(os);
        }
    }
    writeNewLine(os);
}
 
Example 13
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
private String headersToString(HttpHeaders headers) {
    StringBuilder builder = new StringBuilder();
    for(Entry<String, List<String>> entry : headers.entrySet()) {
        builder.append(entry.getKey()).append("=[");
        for(String value : entry.getValue()) {
            builder.append(value).append(",");
        }
        builder.setLength(builder.length() - 1); // Get rid of trailing comma
        builder.append("],");
    }
    builder.setLength(builder.length() - 1); // Get rid of trailing comma
    return builder.toString();
}
 
Example 14
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Add headers to the request that is being built
 * @param headers The headers to add
 * @param requestBuilder The current request
 */
protected void addHeadersToRequest(HttpHeaders headers, BodyBuilder requestBuilder) {
    for (Entry<String, List<String>> entry : headers.entrySet()) {
        List<String> values = entry.getValue();
        for(String value : values) {
            if (value != null) {
                requestBuilder.header(entry.getKey(), value);
            }
        }
    }
}
 
Example 15
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
private String headersToString(HttpHeaders headers) {
    StringBuilder builder = new StringBuilder();
    for(Entry<String, List<String>> entry : headers.entrySet()) {
        builder.append(entry.getKey()).append("=[");
        for(String value : entry.getValue()) {
            builder.append(value).append(",");
        }
        builder.setLength(builder.length() - 1); // Get rid of trailing comma
        builder.append("],");
    }
    builder.setLength(builder.length() - 1); // Get rid of trailing comma
    return builder.toString();
}
 
Example 16
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Add headers to the request that is being built
 * @param headers The headers to add
 * @param requestBuilder The current request
 */
protected void addHeadersToRequest(HttpHeaders headers, BodyBuilder requestBuilder) {
    for (Entry<String, List<String>> entry : headers.entrySet()) {
        List<String> values = entry.getValue();
        for(String value : values) {
            if (value != null) {
                requestBuilder.header(entry.getKey(), value);
            }
        }
    }
}
 
Example 17
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
private String headersToString(HttpHeaders headers) {
    StringBuilder builder = new StringBuilder();
    for(Entry<String, List<String>> entry : headers.entrySet()) {
        builder.append(entry.getKey()).append("=[");
        for(String value : entry.getValue()) {
            builder.append(value).append(",");
        }
        builder.setLength(builder.length() - 1); // Get rid of trailing comma
        builder.append("],");
    }
    builder.setLength(builder.length() - 1); // Get rid of trailing comma
    return builder.toString();
}
 
Example 18
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Add headers to the request that is being built
 * @param headers The headers to add
 * @param requestBuilder The current request
 */
protected void addHeadersToRequest(HttpHeaders headers, WebClient.RequestBodySpec requestBuilder) {
    for (Entry<String, List<String>> entry : headers.entrySet()) {
        List<String> values = entry.getValue();
        for(String value : values) {
            if (value != null) {
                requestBuilder.header(entry.getKey(), value);
            }
        }
    }
}
 
Example 19
Source File: FeignUtils.java    From spring-cloud-openfeign with Apache License 2.0 5 votes vote down vote up
static Map<String, Collection<String>> getHeaders(HttpHeaders httpHeaders) {
	LinkedHashMap<String, Collection<String>> headers = new LinkedHashMap<>();

	for (Map.Entry<String, List<String>> entry : httpHeaders.entrySet()) {
		headers.put(entry.getKey(), entry.getValue());
	}

	return headers;
}
 
Example 20
Source File: AbstractRequestMappingIntegrationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void addHeaders(RequestEntity.HeadersBuilder<?> builder, HttpHeaders headers) {
	for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
		for (String value : entry.getValue()) {
			builder.header(entry.getKey(), value);
		}
	}
}