当前位置: 首页>>代码示例>>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;未经允许,请勿转载。