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


Java HttpRequest.getHeaders方法代码示例

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


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

示例1: intercept

import org.springframework.http.HttpRequest; //导入方法依赖的package包/类
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution clientHttpRequestExecution) throws IOException {

    HttpHeaders headers = request.getHeaders();
    String hybrisRequestId = headers.getFirst(YaasAwareTrait.Headers.REQUEST_ID);
    LOGGER.debug(CHECKING_IF_IS_PRESENT, YaasAwareTrait.Headers.REQUEST_ID, hybrisRequestId);
    if (StringUtils.isEmpty(hybrisRequestId)) {
        headers.set(YaasAwareTrait.Headers.REQUEST_ID, StringUtils.EMPTY);
        LOGGER.debug(ADDING_UPDATING_WITH, YaasAwareTrait.Headers.REQUEST_ID, StringUtils.EMPTY);
    }

    String hybrisHop = headers.getFirst(YaasAwareTrait.Headers.HOP);
    LOGGER.debug(CHECKING_IF_IS_PRESENT, YaasAwareTrait.Headers.HOP, hybrisHop);
    String newHybrisHop = "0";
    if (NumberUtils.isDigits(hybrisHop)) {
        int hop = NumberUtils.toInt(hybrisHop);
        hop++;
        newHybrisHop = Integer.toString(hop);
    }
    headers.set(YaasAwareTrait.Headers.HOP, newHybrisHop);
    LOGGER.debug(ADDING_UPDATING_WITH, YaasAwareTrait.Headers.HOP, newHybrisHop);

    return clientHttpRequestExecution.execute(request, body);
}
 
开发者ID:fdlessard,项目名称:YaasRestClientProject,代码行数:25,代码来源:YaasRequestInterceptor.java

示例2: verifyExpectedTracingHeaders

import org.springframework.http.HttpRequest; //导入方法依赖的package包/类
public static void verifyExpectedTracingHeaders(HttpRequest executedRequest, Span expectedSpanForHeaders) {
    HttpHeaders headers = executedRequest.getHeaders();

    List<String> actualTraceIdHeaderVal = headers.get(TRACE_ID);
    List<String> actualSpanIdHeaderVal = headers.get(SPAN_ID);
    List<String> actualSampledHeaderVal = headers.get(TRACE_SAMPLED);
    List<String> actualParentSpanIdHeaderVal = headers.get(PARENT_SPAN_ID);

    if (expectedSpanForHeaders == null) {
        verifyExpectedTracingHeaderValue(actualTraceIdHeaderVal, null);
        verifyExpectedTracingHeaderValue(actualSpanIdHeaderVal, null);
        verifyExpectedTracingHeaderValue(actualSampledHeaderVal, null);
        verifyExpectedTracingHeaderValue(actualParentSpanIdHeaderVal, null);

    }
    else {
        verifyExpectedTracingHeaderValue(actualTraceIdHeaderVal, expectedSpanForHeaders.getTraceId());
        verifyExpectedTracingHeaderValue(actualSpanIdHeaderVal, expectedSpanForHeaders.getSpanId());
        verifyExpectedTracingHeaderValue(
            actualSampledHeaderVal,
            convertSampleableBooleanToExpectedB3Value(expectedSpanForHeaders.isSampleable())
        );
        verifyExpectedTracingHeaderValue(actualParentSpanIdHeaderVal, expectedSpanForHeaders.getParentSpanId());
    }
}
 
开发者ID:Nike-Inc,项目名称:wingtips,代码行数:26,代码来源:TestUtils.java

示例3: intercept

import org.springframework.http.HttpRequest; //导入方法依赖的package包/类
@Override
public ClientHttpResponse intercept(final HttpRequest request, final byte[] body,
                                    final ClientHttpRequestExecution execution) throws IOException {
    final HttpHeaders headers = request.getHeaders();
    ClientHttpResponse execute = execution.execute(request, body);

    if (execute.getStatusCode() == HttpStatus.UNAUTHORIZED) {
        List<String> list = execute.getHeaders().get("Www-Authenticate");
        if (!CollectionUtils.isEmpty(list)) {
            String tokenString = list.get(0);
            RegistryAuthAdapter.AuthContext ctx = new RegistryAuthAdapter.AuthContext(headers,
              HttpHeaders.readOnlyHttpHeaders(headers),
              tokenString);
            adapter.handle(ctx);
            return execution.execute(request, body);
        }
    }
    return execute;
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:20,代码来源:RegistryAuthInterceptor.java

示例4: invokeBeforeSendRequest

import org.springframework.http.HttpRequest; //导入方法依赖的package包/类
private void invokeBeforeSendRequest(HttpRequest httpRequest, String identifier) throws IOException {
	SpringCloudBeanRegistry beanRegistry = SpringCloudBeanRegistry.getInstance();
	CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
	CompensableManager compensableManager = beanFactory.getCompensableManager();
	TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor();

	CompensableTransactionImpl compensable = //
			(CompensableTransactionImpl) compensableManager.getCompensableTransactionQuietly();

	TransactionContext transactionContext = compensable.getTransactionContext();

	byte[] reqByteArray = CommonUtils.serializeObject(transactionContext);
	String reqTransactionStr = ByteUtils.byteArrayToString(reqByteArray);

	HttpHeaders reqHeaders = httpRequest.getHeaders();
	reqHeaders.add(HEADER_TRANCACTION_KEY, reqTransactionStr);
	reqHeaders.add(HEADER_PROPAGATION_KEY, this.identifier);

	TransactionRequestImpl request = new TransactionRequestImpl();
	request.setTransactionContext(transactionContext);
	RemoteCoordinator coordinator = beanRegistry.getConsumeCoordinator(identifier);
	request.setTargetTransactionCoordinator(coordinator);

	transactionInterceptor.beforeSendRequest(request);
}
 
开发者ID:liuyangming,项目名称:ByteTCC,代码行数:26,代码来源:CompensableRequestInterceptor.java

示例5: intercept

import org.springframework.http.HttpRequest; //导入方法依赖的package包/类
@Override
public ClientHttpResponse intercept(final HttpRequest request, final byte[] body,
		final ClientHttpRequestExecution execution) throws IOException {

	final HttpHeaders requestHeaders = request.getHeaders();

	for (final Entry<String, String> entry : headers.entrySet()) {
		requestHeaders.add(entry.getKey(), entry.getValue());
	}

	return execution.execute(request, body);
}
 
开发者ID:JanLoebel,项目名称:uaa-service,代码行数:13,代码来源:HttpHeaderInterceptor.java

示例6: intercept

import org.springframework.http.HttpRequest; //导入方法依赖的package包/类
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
        throws IOException {
    HttpHeaders headers = request.getHeaders();
    headers.add(AUTHORIZATION_HEADER, gitHubToken);
    headers.add(USER_AGENT_HEADER, USER_AGENT_VALUE);
    headers.setContentType(MediaType.APPLICATION_JSON);
    return execution.execute(request, body);
}
 
开发者ID:redhat-developer,项目名称:che-starter,代码行数:10,代码来源:GitHubInterceptor.java

示例7: intercept

import org.springframework.http.HttpRequest; //导入方法依赖的package包/类
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
        throws IOException {
    HttpHeaders headers = request.getHeaders();
    headers.add(AUTHORIZATION_HEADER, keycloakToken);
    headers.add(REQUEST_ID_HEADER, getRequestId());
    return execution.execute(request, body);
}
 
开发者ID:redhat-developer,项目名称:che-starter,代码行数:9,代码来源:KeycloakInterceptor.java

示例8: intercept

import org.springframework.http.HttpRequest; //导入方法依赖的package包/类
@Override
public ClientHttpResponse intercept(
        HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
        throws IOException {

    HttpHeaders headers = request.getHeaders();
    headers.add("jwt", getJwt());
    return execution.execute(request, body);
}
 
开发者ID:WASdev,项目名称:sample.microservices.security.jwt,代码行数:10,代码来源:JWTAuthenticationInterceptor.java

示例9: intercept

import org.springframework.http.HttpRequest; //导入方法依赖的package包/类
@Override
public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, ClientHttpRequestExecution clientHttpRequestExecution) throws IOException {
  HttpHeaders headers = httpRequest.getHeaders();
  for (Map.Entry<String, String> entry : HeaderPropagationHolder.entries()) {
    headers.set(entry.getKey(), entry.getValue());
  }
  return clientHttpRequestExecution.execute(httpRequest, bytes);
}
 
开发者ID:saturnism,项目名称:istio-by-example-java,代码行数:9,代码来源:HeaderPropagationClientHttpRequestInterceptor.java

示例10: intercept

import org.springframework.http.HttpRequest; //导入方法依赖的package包/类
@Override
public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes,
                                    ClientHttpRequestExecution clientHttpRequestExecution) throws IOException {
    HttpHeaders headers = httpRequest.getHeaders();
    headers.add(HttpHeaders.AUTHORIZATION,
            encodeCredentialsForBasicAuth(username, password));

    return clientHttpRequestExecution.execute(httpRequest, bytes);
}
 
开发者ID:peavers,项目名称:swordfish-service,代码行数:10,代码来源:RestTemplateConfig.java

示例11: intercept

import org.springframework.http.HttpRequest; //导入方法依赖的package包/类
@Override
public ClientHttpResponse intercept(final HttpRequest request, final byte[] body,
        final ClientHttpRequestExecution execution) throws IOException {
    HttpHeaders headers = request.getHeaders();
    headers.add("X-Subject-Token", currentToken);
    headers.add("X-Auth-Token", currentToken);
    return execution.execute(request, body);
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:9,代码来源:SelfRevokingKeystoneV3Provider.java

示例12: intercept

import org.springframework.http.HttpRequest; //导入方法依赖的package包/类
@Override
public ClientHttpResponse intercept(final HttpRequest request, final byte[] body,
        final ClientHttpRequestExecution execution) throws IOException {
    HttpHeaders headers = request.getHeaders();
    headers.add("X-Auth-Token", tokenManager.getTokenHolder(userName).getUnscoped());
    return execution.execute(request, body);
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:8,代码来源:KeystoneCollector.java

示例13: intercept

import org.springframework.http.HttpRequest; //导入方法依赖的package包/类
@Override
public ClientHttpResponse intercept(final HttpRequest request, final byte[] body,
        final ClientHttpRequestExecution execution) throws IOException {
    HttpHeaders headers = request.getHeaders();
    headers.add("X-Auth-Token", tokenManager.getTokenHolder().getUnscoped());
    headers.add("X-Subject-Token", tokenManager.getTokenHolder().getUnscoped());
    return execution.execute(request, body);
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:9,代码来源:UnscopedAndSubjectClientHttpRequestInterceptor.java

示例14: intercept

import org.springframework.http.HttpRequest; //导入方法依赖的package包/类
@Override
public ClientHttpResponse intercept(final HttpRequest request, final byte[] body,
        final ClientHttpRequestExecution execution) throws IOException {
    HttpHeaders headers = request.getHeaders();
    headers.add("X-Auth-Token", tokenManager.getTokenHolder().getUnscoped());
    if (LOG.isInfoEnabled()) {
        LOG.info("X-Auth-Token: " + tokenManager.getTokenHolder().getUnscoped());
    }
    return execution.execute(request, body);
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:11,代码来源:UnscopedClientHttpRequestInterceptor.java

示例15: intercept

import org.springframework.http.HttpRequest; //导入方法依赖的package包/类
@Override
public ClientHttpResponse intercept(final HttpRequest request, final byte[] body,
        final ClientHttpRequestExecution execution) throws IOException {
    HttpHeaders headers = request.getHeaders();
    headers.add("X-Auth-Token", tokenManager.getTokenHolder().getScopedToken(projectId));
    if (LOG.isInfoEnabled()) {
        LOG.info("X-Auth-Token: " + tokenManager.getTokenHolder().getScopedToken(projectId));
    }
    return execution.execute(request, body);
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:11,代码来源:ScopedClientHttpRequestInterceptor.java


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