當前位置: 首頁>>代碼示例>>Java>>正文


Java RestTemplate.setInterceptors方法代碼示例

本文整理匯總了Java中org.springframework.web.client.RestTemplate.setInterceptors方法的典型用法代碼示例。如果您正苦於以下問題:Java RestTemplate.setInterceptors方法的具體用法?Java RestTemplate.setInterceptors怎麽用?Java RestTemplate.setInterceptors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.web.client.RestTemplate的用法示例。


在下文中一共展示了RestTemplate.setInterceptors方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import org.springframework.web.client.RestTemplate; //導入方法依賴的package包/類
private void init(ApplicationContext ctx) {
	loadBalancedRestTemplate = new RestTemplate();
	SpringClientFactory springClientFactory = springClientFactory();
	springClientFactory.setApplicationContext(ctx);
	
	loadBalancerClient = new RibbonLoadBalancerClient(springClientFactory);
	
	//custom restTemplate
	LoadBalancerRequestFactory requestFactory = new LoadBalancerRequestFactory(loadBalancerClient, Collections.emptyList());
	LoadBalancerInterceptor interceptor = new LoadBalancerInterceptor(loadBalancerClient, requestFactory);
	
	List<ClientHttpRequestInterceptor> interceptors = loadBalancedRestTemplate.getInterceptors();
	ArrayList<ClientHttpRequestInterceptor> customedInterceptors = new ArrayList<>(interceptors.size() + 1);
	customedInterceptors.addAll(interceptors);
	customedInterceptors.add(interceptor);
	
	loadBalancedRestTemplate.setInterceptors(customedInterceptors);
}
 
開發者ID:QNJR-GROUP,項目名稱:EasyTransaction,代碼行數:19,代碼來源:RestRibbonEasyTransRpcConsumerImpl.java

示例2: getTemplate

import org.springframework.web.client.RestTemplate; //導入方法依賴的package包/類
public static RestTemplate getTemplate(ClientHttpRequestInterceptor interceptor) {
    RestTemplate restTemplate = new RestTemplate();

    List<ClientHttpRequestInterceptor> ris = new ArrayList<>();
    ris.add(interceptor);
    restTemplate.setInterceptors(ris);
    SimpleClientHttpRequestFactory httpFactory = new SimpleClientHttpRequestFactory();
    httpFactory.setOutputStreaming(false);
    restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(httpFactory));
    restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
    return restTemplate;
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:13,代碼來源:TemplateUtil.java

示例3: TracingRestTemplateTest

import org.springframework.web.client.RestTemplate; //導入方法依賴的package包/類
public TracingRestTemplateTest() {
    final RestTemplate restTemplate = new RestTemplate();
    restTemplate.setInterceptors(Collections.<ClientHttpRequestInterceptor>singletonList(
            new TracingRestTemplateInterceptor(mockTracer)));

    client = new Client<RestTemplate>() {
        @Override
        public <T> ResponseEntity<T> getForEntity(String url, Class<T> clazz) {
            return restTemplate.getForEntity(url, clazz);
        }

        @Override
        public RestTemplate template() {
            return restTemplate;
        }
    };

    mockServer = MockRestServiceServer.bindTo(client.template()).build();
}
 
開發者ID:opentracing-contrib,項目名稱:java-spring-web,代碼行數:20,代碼來源:TracingRestTemplateTest.java

示例4: run

import org.springframework.web.client.RestTemplate; //導入方法依賴的package包/類
@Override
@SuppressWarnings("checkstyle:emptyblock")
public void run() {
    LOG.warn("****** SelfRevokingProvider Thread going to sleep for 15 secs");
    try {
        Thread.sleep(THREAD_SLEEP);
    } catch (InterruptedException ie) {
    }
    LOG.warn("****** SelfRevokingProvider finished sleeping, revoking all tokens");
    try {
        RestTemplate rt = restManager.getRestTemplate("keystone-revoke");
        rt.setInterceptors(Collections.singletonList(this));
        LOG.warn("****** deleting " + keystoneTokenURI.toString());
        for (TokenHolder tokenHolder : TokenManager.getInstance().getAllTokenHolders()) {
            currentToken = tokenHolder.getUnscoped();
            LOG.warn("****** deleting token " + currentToken + "[" + keystoneTokenURI.toString() + "]");
            rt.delete(keystoneTokenURI);
        }
    } catch (HttpClientErrorException ex) {
        LOG.error("****** token revocation refused for token " + currentToken);
    }
    LOG.warn("****** all tokens have been revoked - SelfRevokingProvider Thread is exiting...");
}
 
開發者ID:HewlettPackard,項目名稱:loom,代碼行數:24,代碼來源:SelfRevokingKeystoneV3Provider.java

示例5: restTemplate

import org.springframework.web.client.RestTemplate; //導入方法依賴的package包/類
@Bean
public RestTemplate restTemplate(OmegaContext context) {
  RestTemplate template = new RestTemplate();
  List<ClientHttpRequestInterceptor> interceptors = template.getInterceptors();
  interceptors.add(new TransactionClientHttpRequestInterceptor(context));
  template.setInterceptors(interceptors);
  return template;
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-saga,代碼行數:9,代碼來源:RestTemplateConfig.java

示例6: testErrorUnknownHostException

import org.springframework.web.client.RestTemplate; //導入方法依賴的package包/類
@Test
public void testErrorUnknownHostException() {
    String url = "http://nonexisting.example.com";
    try {
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setInterceptors(Collections.<ClientHttpRequestInterceptor>singletonList(
                new TracingRestTemplateInterceptor(mockTracer)));
        restTemplate.getForEntity(url, String.class);
    } catch (ResourceAccessException ex) {
        //ok UnknownHostException
    }

    List<MockSpan> mockSpans = mockTracer.finishedSpans();
    Assert.assertEquals(1, mockSpans.size());

    MockSpan mockSpan = mockSpans.get(0);
    Assert.assertEquals("GET", mockSpan.operationName());
    Assert.assertEquals(5, mockSpan.tags().size());
    Assert.assertEquals(RestTemplateSpanDecorator.StandardTags.COMPONENT_NAME,
            mockSpan.tags().get(Tags.COMPONENT.getKey()));
    Assert.assertEquals(Tags.SPAN_KIND_CLIENT, mockSpan.tags().get(Tags.SPAN_KIND.getKey()));
    Assert.assertEquals("GET", mockSpan.tags().get(Tags.HTTP_METHOD.getKey()));
    Assert.assertEquals(url, mockSpan.tags().get(Tags.HTTP_URL.getKey()));
    Assert.assertEquals(Boolean.TRUE, mockSpan.tags().get(Tags.ERROR.getKey()));

    Assert.assertEquals(1, mockSpan.logEntries().size());
    Assert.assertEquals(2, mockSpan.logEntries().get(0).fields().size());
    Assert.assertEquals(Tags.ERROR.getKey(), mockSpan.logEntries().get(0).fields().get("event"));
    Assert.assertNotNull(mockSpan.logEntries().get(0).fields().get("error.object"));
}
 
開發者ID:opentracing-contrib,項目名稱:java-spring-web,代碼行數:31,代碼來源:AbstractTracingClientTest.java

示例7: registerTracingInterceptor

import org.springframework.web.client.RestTemplate; //導入方法依賴的package包/類
private void registerTracingInterceptor(RestTemplate restTemplate) {
    List<ClientHttpRequestInterceptor> interceptors = restTemplate.getInterceptors();

    for (ClientHttpRequestInterceptor interceptor: interceptors) {
        if (interceptor instanceof TracingRestTemplateInterceptor) {
            return;
        }
    }

    log.info("Adding " + TracingRestTemplateInterceptor.class.getSimpleName() + " to rest template");
    interceptors = new ArrayList<>(interceptors);
    interceptors.add(new TracingRestTemplateInterceptor(tracer));
    restTemplate.setInterceptors(interceptors);
}
 
開發者ID:opentracing-contrib,項目名稱:java-spring-web,代碼行數:15,代碼來源:RestTemplateAutoConfiguration.java

示例8: customize

import org.springframework.web.client.RestTemplate; //導入方法依賴的package包/類
@Override
public void customize(RestTemplate restTemplate) {
    UriTemplateHandler templateHandler = restTemplate.getUriTemplateHandler();
    templateHandler = this.interceptor.createUriTemplateHandler(templateHandler);
    restTemplate.setUriTemplateHandler(templateHandler);
    List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
    interceptors.add(this.interceptor);
    interceptors.addAll(restTemplate.getInterceptors());
    restTemplate.setInterceptors(interceptors);
}
 
開發者ID:micrometer-metrics,項目名稱:micrometer,代碼行數:11,代碼來源:MetricsRestTemplateCustomizer.java

示例9: getRestTemplate

import org.springframework.web.client.RestTemplate; //導入方法依賴的package包/類
/**
 * Gets a Rest Template.
 *
 * @return A RestTemplate for rest requests.
 */
public RestTemplate getRestTemplate() {
	RestTemplate restTemplate = new RestTemplate();

	// Request Interceptors
	restTemplate.setInterceptors(new ArrayList<ClientHttpRequestInterceptor>());
	restTemplate.getInterceptors().addAll(getRestInterceptors());

	// Default Error Handler
	restTemplate.setErrorHandler(new RestErrorHandler());

	return restTemplate;
}
 
開發者ID:twitch4j,項目名稱:twitch4j,代碼行數:18,代碼來源:RestClient.java

示例10: setRestTemplateInterceptor

import org.springframework.web.client.RestTemplate; //導入方法依賴的package包/類
private void setRestTemplateInterceptor(final RestTemplate restTemplate) {
    restTemplate.setInterceptors(Collections.singletonList(
            new TraceRestTemplateInterceptor(this.tracer, new ZipkinHttpSpanInjector(),
                    new HttpTraceKeysInjector(this.tracer, new TraceKeys()))));
}
 
開發者ID:eclipse,項目名稱:keti,代碼行數:6,代碼來源:PolicyEvaluationWithAttributeConnectorIT.java

示例11: configureRestTemplate

import org.springframework.web.client.RestTemplate; //導入方法依賴的package包/類
/**
 * Configure a {@link RestTemplate} for communication with a CredHub server.
 * @param restTemplate an existing {@link RestTemplate} to configure
 * @param baseUri the base URI for the CredHub server
 * @param clientHttpRequestFactory the {@link ClientHttpRequestFactory} to use when
 * creating new connections
 */
public static void configureRestTemplate(RestTemplate restTemplate, String baseUri,
		ClientHttpRequestFactory clientHttpRequestFactory) {
	restTemplate.setRequestFactory(clientHttpRequestFactory);
	restTemplate.setUriTemplateHandler(createUriTemplateHandler(baseUri));
	restTemplate.setMessageConverters(createMessageConverters());
	restTemplate.setInterceptors(createInterceptors());
}
 
開發者ID:spring-projects,項目名稱:spring-credhub,代碼行數:15,代碼來源:CredHubClient.java

示例12: getRestTemplateWithToken

import org.springframework.web.client.RestTemplate; //導入方法依賴的package包/類
public RestTemplate getRestTemplateWithToken() {
    RestTemplate rt = restManager.getRestTemplate("keystone-data");
    rt.setInterceptors(Collections.singletonList(this));
    return rt;
}
 
開發者ID:HewlettPackard,項目名稱:loom,代碼行數:6,代碼來源:KeystoneCollector.java

示例13: getRestTemplateWithUnscopedToken

import org.springframework.web.client.RestTemplate; //導入方法依賴的package包/類
/**
 * Get a RestTemplate with an unscoped token (via the interceptor).
 *
 * @return the rest template
 */
public RestTemplate getRestTemplateWithUnscopedToken() {
    RestTemplate rt = restManager.getRestTemplate("keystone-data");
    rt.setInterceptors(Collections.singletonList(new UnscopedClientHttpRequestInterceptor(tokenManager)));
    return rt;
}
 
開發者ID:HewlettPackard,項目名稱:loom,代碼行數:11,代碼來源:OpenstackApi.java

示例14: getRestTemplateWithUnscopedAndSubjectToken

import org.springframework.web.client.RestTemplate; //導入方法依賴的package包/類
/**
 * Get a RestTemplate with an UnscopedAndSubjectToken token (via the interceptor).
 *
 * @return the rest template
 */
public RestTemplate getRestTemplateWithUnscopedAndSubjectToken() {
    RestTemplate rt = restManager.getRestTemplate("keystone-data");
    rt.setInterceptors(Collections.singletonList(new UnscopedAndSubjectClientHttpRequestInterceptor(tokenManager)));
    return rt;
}
 
開發者ID:HewlettPackard,項目名稱:loom,代碼行數:11,代碼來源:OpenstackApi.java

示例15: getRestTemplateWithScopedToken

import org.springframework.web.client.RestTemplate; //導入方法依賴的package包/類
/**
 * Get a RestTemplate with an scoped token (via the interceptor).
 *
 * @param projectId the project id
 * @return the rest template
 */
public RestTemplate getRestTemplateWithScopedToken(final String projectId) {
    RestTemplate rt = restManager.getRestTemplate("scoped");
    rt.setInterceptors(Collections.singletonList(new ScopedClientHttpRequestInterceptor(projectId, tokenManager)));
    return rt;
}
 
開發者ID:HewlettPackard,項目名稱:loom,代碼行數:12,代碼來源:OpenstackApi.java


注:本文中的org.springframework.web.client.RestTemplate.setInterceptors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。