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


Java ClientHttpRequestExecution类代码示例

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


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

示例1: intercept

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

  if (omegaContext.globalTxId() != null) {
    request.getHeaders().add(GLOBAL_TX_ID_KEY, omegaContext.globalTxId());
    request.getHeaders().add(LOCAL_TX_ID_KEY, omegaContext.localTxId());

    LOG.debug("Added {} {} and {} {} to request header",
        GLOBAL_TX_ID_KEY,
        omegaContext.globalTxId(),
        LOCAL_TX_ID_KEY,
        omegaContext.localTxId());
  }
  return execution.execute(request, body);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-saga,代码行数:17,代码来源:TransactionClientHttpRequestInterceptor.java

示例2: interceptNeverRetry

import org.springframework.http.client.ClientHttpRequestExecution; //导入依赖的package包/类
@Test
public void interceptNeverRetry() throws Throwable {
    HttpRequest request = mock(HttpRequest.class);
    when(request.getURI()).thenReturn(new URI("http://foo"));
    ClientHttpResponse clientHttpResponse = new MockClientHttpResponse(new byte[]{}, HttpStatus.OK);
    LoadBalancedRetryPolicyFactory lbRetryPolicyFactory = mock(LoadBalancedRetryPolicyFactory.class);
    when(lbRetryPolicyFactory.create(eq("foo"), any(ServiceInstanceChooser.class))).thenReturn(null);
    ServiceInstance serviceInstance = mock(ServiceInstance.class);
    when(client.choose(eq("foo"))).thenReturn(serviceInstance);
    when(client.execute(eq("foo"), eq(serviceInstance), any(LoadBalancerRequest.class))).thenReturn(clientHttpResponse);
    when(this.lbRequestFactory.createRequest(any(), any(), any())).thenReturn(mock(LoadBalancerRequest.class));
    lbProperties.setEnabled(true);
    RetryLoadBalancerInterceptor interceptor = new RetryLoadBalancerInterceptor(client, lbProperties, lbRetryPolicyFactory,
            lbRequestFactory, backOffPolicyFactory, retryListenerFactory);
    byte[] body = new byte[]{};
    ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);
    interceptor.intercept(request, body, execution);
    verify(lbRequestFactory).createRequest(request, body, execution);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:20,代码来源:RetryLoadBalancerInterceptorTest.java

示例3: run

import org.springframework.http.client.ClientHttpRequestExecution; //导入依赖的package包/类
@Override
public void run() {
    MockClientHttpRequest request = new MockClientHttpRequest();
    MockClientHttpResponse response = new MockClientHttpResponse(new byte[0], HttpStatus.OK);
    ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);

    response.getHeaders().add("X-RateLimit-Remaining", "50");
    response.getHeaders().add("X-RateLimit-Reset", String.valueOf((System.currentTimeMillis() / 1000) + 1));

    try {
        when(execution.execute(request, new byte[0])).thenReturn(response);

        this.interceptor.intercept(request, new byte[0], execution);
    } catch (IOException e) {
    } finally {
        this.latch.countDown();
    }
}
 
开发者ID:pivotalsoftware,项目名称:github-cla-integration,代码行数:19,代码来源:RateLimitingClientHttpRequestInterceptorTest.java

示例4: intercept

import org.springframework.http.client.ClientHttpRequestExecution; //导入依赖的package包/类
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
	throws IOException
{
	if (log.isDebugEnabled())
	{
		log.debug(String.format("Request: %s %s %s", request.getMethod(), request.getURI(),
			new String(body, getCharset(request))));
	}
	
	ClientHttpResponse response = execution.execute(request, body);
	
	if (log.isDebugEnabled())
	{
		log.debug(String.format("Response: %s %s", response.getStatusCode().value(),
			copyToString(response.getBody(), getCharset(response))));
	}
	
	return response;
}
 
开发者ID:markhobson,项目名称:spring-rest-template-logger,代码行数:21,代码来源:LoggingInterceptor.java

示例5: setApiKey

import org.springframework.http.client.ClientHttpRequestExecution; //导入依赖的package包/类
/**
 * Sets the api key.
 *
 * @throws JsonParseException the json parse exception
 * @throws JsonMappingException the json mapping exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
private void setApiKey() throws JsonParseException, JsonMappingException, IOException{
	ArrayList<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
	interceptors.add((HttpRequest request, byte[] body, ClientHttpRequestExecution execution) -> {
		if(body.length > 0) {
			body = addTokenInObject(body, new JsonNodeFormatter());
		}else{
			try {
				request = addTokenInURI(request);
			} catch (URISyntaxException e) {
				e.printStackTrace();
			}
		}
		return execution.execute(request, body);
	});
	this.restTemplate.setInterceptors(interceptors);
}
 
开发者ID:ac-silva,项目名称:desafio-pagarme,代码行数:24,代码来源:Client.java

示例6: init

import org.springframework.http.client.ClientHttpRequestExecution; //导入依赖的package包/类
/**
 * Init
 */
@PostConstruct
protected void init() {

    restTemplateForAuthenticationFlow = new CookieStoreRestTemplate();
    cookieStore = restTemplateForAuthenticationFlow.getCookieStore();

    logger.debug("Inject cookie store used in the rest template for authentication flow into the authRestTemplate so that they will match");
    authRestTemplate.restTemplate.setCookieStoreAndUpdateRequestFactory(cookieStore);

    List<ClientHttpRequestInterceptor> interceptors = Collections
            .<ClientHttpRequestInterceptor>singletonList(new ClientHttpRequestInterceptor() {
                @Override
                public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
                    if (latestCsrfToken != null) {
                        // At the beginning of auth flow, there's no token yet
                        injectCsrfTokenIntoHeader(request, latestCsrfToken);
                    }
                    return execution.execute(request, body);
                }
            });

    restTemplateForAuthenticationFlow.setRequestFactory(new InterceptingClientHttpRequestFactory(restTemplateForAuthenticationFlow.getRequestFactory(), interceptors));
}
 
开发者ID:box,项目名称:mojito,代码行数:27,代码来源:FormLoginAuthenticationCsrfTokenInterceptor.java

示例7: intercept

import org.springframework.http.client.ClientHttpRequestExecution; //导入依赖的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

示例8: intercept

import org.springframework.http.client.ClientHttpRequestExecution; //导入依赖的package包/类
@Override
public ClientHttpResponse intercept(
    HttpRequest request, byte[] body, ClientHttpRequestExecution execution
) throws IOException {
    Tracer tracer = Tracer.getInstance();
    Span spanAroundCall = null;
    try {
        if (surroundCallsWithSubspan) {
            // Will start a new trace if necessary, or a subspan if a trace is already in progress.
            spanAroundCall = tracer.startSpanInCurrentContext(getSubspanSpanName(request), SpanPurpose.CLIENT);
        }

        HttpRequest wrapperRequest = new HttpRequestWrapperWithModifiableHeaders(request);
        propagateTracingHeaders(wrapperRequest, tracer.getCurrentSpan());

        return execution.execute(wrapperRequest, body);
    }
    finally {
        if (spanAroundCall != null) {
            // Span.close() contains the logic we want - if the spanAroundCall was an overall span (new trace)
            //      then tracer.completeRequestSpan() will be called, otherwise it's a subspan and
            //      tracer.completeSubSpan() will be called.
            spanAroundCall.close();
        }
    }
}
 
开发者ID:Nike-Inc,项目名称:wingtips,代码行数:27,代码来源:WingtipsClientHttpRequestInterceptor.java

示例9: intercept

import org.springframework.http.client.ClientHttpRequestExecution; //导入依赖的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

示例10: interceptSetsContentTypeAndAcceptHeaders

import org.springframework.http.client.ClientHttpRequestExecution; //导入依赖的package包/类
@Test
public void interceptSetsContentTypeAndAcceptHeaders() throws IOException {
	HttpRequest request = mock(HttpRequest.class);
	when(request.getHeaders()).thenReturn(new HttpHeaders());
	
	ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);
	
	interceptor.intercept(request, new byte[] {1}, execution);
	
	ArgumentCaptor<HttpRequest> finalRequest = ArgumentCaptor.forClass(HttpRequest.class);
	verify(execution).execute(finalRequest.capture(), aryEq(new byte[] {1}));
	
	HttpHeaders finalHeaders = finalRequest.getValue().getHeaders();
	assertThat(finalHeaders.getAccept(), contains(MediaType.valueOf("application/hal+json")));
	assertThat(finalHeaders.getContentType(), is(MediaType.valueOf("application/hal+json")));
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:17,代码来源:JsonClientHttpRequestInterceptorTest.java

示例11: intercept

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

	if (LOG.isTraceEnabled()) {
		LOG.trace(request.getMethod().name() + " " + request.getURI() + " : "
				+ new String(body, "UTF-8"));
	}

	ClientHttpResponse response = execution.execute(request, body);

	if (LOG.isTraceEnabled()) {
		LOG.trace("response " + response.getStatusCode().value() + " : "
				+ IOUtils.toString(response.getBody()));
	}

	return response;
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:19,代码来源:AbstractIT.java

示例12: intercept

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

   ClientHttpResponse response = execution.execute(request, body);

   long endTime = System.currentTimeMillis();

   if(useDebug)
   {
      LOG.debug("Request for {} took {} ms", request.getURI().toString(), endTime - startTime);
   }
   else
   {
      LOG.info("Request for {} took {} ms", request.getURI().toString(), endTime - startTime);
   }

   return response;
}
 
开发者ID:HomeAdvisor,项目名称:Robusto,代码行数:21,代码来源:ResponseTimeInterceptor.java

示例13: intercept

import org.springframework.http.client.ClientHttpRequestExecution; //导入依赖的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

示例14: intercept

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

    final RequestArguments arguments = toArguments(request, body);
    final RequestExecution requestExecution = () -> {
        final CompletableFuture<ClientHttpResponse> future = new CompletableFuture<>();

        try {
            future.complete(execution.execute(request, body));
        } catch (final Exception e) {
            future.completeExceptionally(e);
        }

        return future;
    };

    // since there is no routing to be done, we just call the plugin twice in succession
    final RequestExecution before = plugin.interceptBeforeRouting(arguments, requestExecution);
    final RequestExecution after = plugin.interceptAfterRouting(arguments, before);

    return Completion.join(after.execute());
}
 
开发者ID:zalando,项目名称:riptide,代码行数:24,代码来源:PluginInterceptors.java

示例15: intercept

import org.springframework.http.client.ClientHttpRequestExecution; //导入依赖的package包/类
/**
 * This isn't needed now - but was needed when trying to figure out why term extractor wasn't
 * returning data.
 */
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
        throws IOException {

    // HttpHeaders headers = request.getHeaders();
    // headers.add("Accept",
    // "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
    /*
     * headers.add("X-User-Agent",
     * "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 Query String Parametersview sourceview URL encoded"
     * );
     * headers.add("Accept-Encoding", "gzip, deflate, sdch");
     * headers.add("Accept-Language", "en-US,en;q=0.8");
     * headers.add("Cache-Control", "max-age=0");
     * headers.add("Connection", "keep-alive");
     * headers.add("Cookie",
     * "CTK=19asr9k230nph1f0; RF=\"TFTzyBUJoNr4wP5QpciSOn6ifEMTEVq4ARC0hGY5P-gkhvCY-D1UltWIqfxDhxhHqiN1UggLuPE=\"; IRF=\"1qRi-3v0F_uf-yOkOwHemehIPriDHeZ-AD_rnIAayJ8=\"; CSRF=RCTCj8Abxq9j3u0bL2cYybndr26rFwzL; LC=\"co=FR&hl=fr_FR\"; SHOE=\"uQsQNsQkFYUJ008ISZ8DRWVFtv6W_JMN4mdL-LLfXiJuOW0VoJAjjiVpkv4kQoV23Sg-_-1ytM1OqAz8ROZROJDcOAoDohJHdMU_EBqxbwMOyVIOjrryq7DH189GzMI=\"; PUB=1; BIGipServerjob_iad=!YlkJJm1KgDuhYWHnj+SL47ecq6aoxVInDdjtEnHOjpnVpzOxZBWTrFttjRp0eryuGzkmkx1TYdWHS2k=; INDEED_CSRF_TOKEN=ClPCTHOQ2zlw3egLg2bQl8WakmtEeWpf; _mkto_trk=id:699-SXJ-715&token:_mch-indeed.com-1420554563497-42566; TS01c598d3=0160a2beff09f16a3c10d0f0f0a6a553318c160463ca6c315ab349cad0aefb8dfaa95db17be5052c844f60ecad51ec7c72d952d440688e76cfdabdb3074ee99a7773918ac93d8b06d43de5f602f27582982fb39fbe34263631f197d1f19e0fb70752db8b562fd68ecd5716b3e3d26da06ac246cd6f060c5f347cb466bd53402f81a2506ff7ee638943466c4de4e47bb62d5ee23bd42ae6ba9a59c0ca38e446b40736cbc688; DCT=4; JSESSIONID=97208F039EED60B31A14EF12640B8D84.jasxB_iad-job18; TS016080f8=0160a2beff8af91efc651c51dff589379d71c19e188469c827f0265638b0194c2885f98c9fe455fc17b6ea59258cb631c44485df3e271eae4c2090e2cedce12f163b39094c07e6f01fc7144638866b7333691120a4c4648f7b3b8f00c08419b665958f61ce"
     * );
     * headers.add("DNT", "1");
     * headers.add("Host", "api.indeed.com");
     */
    return execution.execute(request, body);
}
 
开发者ID:jhaood,项目名称:github-job-keywords,代码行数:28,代码来源:XUserAgentInterceptor.java


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