當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。