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


Java RestTemplate.setErrorHandler方法代码示例

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


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

示例1: WinDriverService

import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
public WinDriverService() {
    urlBuilder = new URLBuilder();
    objMapper = new ObjectMapper();
    winDriverElementType = WinDriverElement.class;
    restTemplate = new RestTemplate(ConfiguredRequestFactory.defaultFactory());
    restTemplate.setErrorHandler(new ErrorHandler());
    setLogLevel(Level.toLevel(EnvironmentProperties.CLIENT_LOG_LEVEL.readString()));
}
 
开发者ID:WinDriverTeam,项目名称:windriver-java,代码行数:9,代码来源:WinDriverService.java

示例2: restTemplate

import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
public RestTemplate restTemplate(ClientHttpRequestFactory requestFactory, List<MediaType> types) {
	RestTemplate rt = new RestTemplate(requestFactory);

	// Override default error handler to consider HTTP 3xx 4xx and 5xx as errors
	rt.setErrorHandler(restErrorHandler);

	// Default HTTP 'Accept' header value will be application/json
	rt.getInterceptors().add(new AcceptRequestInterceptor(types));

	return rt;
}
 
开发者ID:vianneyfaivre,项目名称:Persephone,代码行数:12,代码来源:DefaultRestTemplateConfig.java

示例3: testStatusReleaseNameNotFound

import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@Test(expected = ReleaseNotFoundException.class)
public void testStatusReleaseNameNotFound() {
	RestTemplate restTemplate = new RestTemplate();
	restTemplate.setErrorHandler(new SkipperClientResponseErrorHandler(new ObjectMapper()));
	SkipperClient skipperClient = new DefaultSkipperClient("", restTemplate);

	MockRestServiceServer mockServer = MockRestServiceServer.bindTo(restTemplate).build();
	mockServer.expect(requestTo("/release/status/mylog"))
			.andRespond(withStatus(HttpStatus.NOT_FOUND).body(ERROR1).contentType(MediaType.APPLICATION_JSON));

	skipperClient.status("mylog");
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:13,代码来源:DefaultSkipperClientTests.java

示例4: testSkipperException

import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@Test(expected = SkipperException.class)
public void testSkipperException() {
	RestTemplate restTemplate = new RestTemplate();
	restTemplate.setErrorHandler(new SkipperClientResponseErrorHandler(new ObjectMapper()));
	SkipperClient skipperClient = new DefaultSkipperClient("", restTemplate);

	MockRestServiceServer mockServer = MockRestServiceServer.bindTo(restTemplate).build();
	mockServer.expect(requestTo("/release/status/mylog"))
			.andRespond(withStatus(HttpStatus.NOT_FOUND).body(ERROR2).contentType(MediaType.APPLICATION_JSON));

	skipperClient.status("mylog");
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:13,代码来源:DefaultSkipperClientTests.java

示例5: testDeleteRelease

import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
private void testDeleteRelease(boolean deletePackage) {
	RestTemplate restTemplate = new RestTemplate();
	restTemplate.setErrorHandler(new SkipperClientResponseErrorHandler(new ObjectMapper()));
	SkipperClient skipperClient = new DefaultSkipperClient("", restTemplate);

	final MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(),
			MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));

	MockRestServiceServer mockServer = MockRestServiceServer.bindTo(restTemplate).build();
	mockServer.expect(requestTo("/release/release1/" + deletePackage))
			.andRespond(withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON));

	skipperClient.delete("release1", deletePackage);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:15,代码来源:DefaultSkipperClientTests.java

示例6: testDeletePackageHasDeployedRelease

import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@Test(expected = PackageDeleteException.class)
public void testDeletePackageHasDeployedRelease() {
	RestTemplate restTemplate = new RestTemplate();
	restTemplate.setErrorHandler(new SkipperClientResponseErrorHandler(new ObjectMapper()));
	SkipperClient skipperClient = new DefaultSkipperClient("", restTemplate);

	MockRestServiceServer mockServer = MockRestServiceServer.bindTo(restTemplate).build();
	mockServer.expect(requestTo("/release/release1/" + true))
			.andRespond(withStatus(HttpStatus.CONFLICT).body(ERROR3).contentType(MediaType.APPLICATION_JSON));
	skipperClient.delete("release1", true);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:12,代码来源:DefaultSkipperClientTests.java

示例7: createRestTemplate

import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
public RestTemplate createRestTemplate(HttpProxyConfiguration httpProxyConfiguration, boolean
        trustSelfSignedCerts) {
    RestTemplate restTemplate = new LoggingRestTemplate();
    restTemplate.setRequestFactory(createRequestFactory(httpProxyConfiguration, trustSelfSignedCerts));
    restTemplate.setErrorHandler(new CloudControllerResponseErrorHandler());
    restTemplate.setMessageConverters(getHttpMessageConverters());

    return restTemplate;
}
 
开发者ID:SAP,项目名称:cf-java-client-sap,代码行数:10,代码来源:RestUtil.java

示例8: 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

示例9: getPlainRestTemplate

import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
/**
 * Gets a Rest Template without any interceptors.
 *
 * @return A RestTemplate for rest requests.
 */
public RestTemplate getPlainRestTemplate() {
	RestTemplate restTemplate = new RestTemplate();
	restTemplate.setErrorHandler(new RestErrorHandler());

	return restTemplate;
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:12,代码来源:RestClient.java

示例10: restTemplate

import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@LoadBalanced
@Bean
RestTemplate restTemplate() {
	RestTemplate template = new RestTemplate();
	template.setErrorHandler(getResponseErrorHandler());

	return template;
}
 
开发者ID:daflockinger,项目名称:poppynotes,代码行数:9,代码来源:CloudConfig.java

示例11: restTemplate

import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@Primary
@Bean(name="testRestTemplate")
RestTemplate restTemplate() {
	RestTemplate template = new RestTemplate();
	template.setErrorHandler(getResponseErrorHandler());

	return template;
}
 
开发者ID:daflockinger,项目名称:poppynotes,代码行数:9,代码来源:TestConfig.java

示例12: initRestTemplate

import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
/**
 * springboot初始化restTemplate
 */
@Bean
public RestTemplate initRestTemplate() {
    // 长连接保持30秒
    PoolingHttpClientConnectionManager pollingConnectionManager = new PoolingHttpClientConnectionManager(30, TimeUnit.SECONDS);
    // 总连接数
    pollingConnectionManager.setMaxTotal(1000);
    // 同路由的并发数
    pollingConnectionManager.setDefaultMaxPerRoute(1000);

    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    httpClientBuilder.setConnectionManager(pollingConnectionManager);
    // 重试次数,默认是3次,没有开启
    httpClientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(2, true));
    // 保持长连接配置,需要在头添加Keep-Alive
    httpClientBuilder.setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy());

    RequestConfig.Builder builder = RequestConfig.custom();
    builder.setConnectionRequestTimeout(200);
    builder.setConnectTimeout(5000);
    builder.setSocketTimeout(5000);

    RequestConfig requestConfig = builder.build();
    httpClientBuilder.setDefaultRequestConfig(requestConfig);

    List<Header> headers = new ArrayList<>();
    headers.add(new BasicHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.16 Safari/537.36"));
    headers.add(new BasicHeader("Accept-Encoding", "gzip,deflate"));
    headers.add(new BasicHeader("Accept-Language", "zh-CN"));
    headers.add(new BasicHeader("Connection", "Keep-Alive"));

    httpClientBuilder.setDefaultHeaders(headers);

    HttpClient httpClient = httpClientBuilder.build();

    // httpClient连接配置,底层是配置RequestConfig
    HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
    // 连接超时
    clientHttpRequestFactory.setConnectTimeout(5000);
    // 数据读取超时时间,即SocketTimeout
    clientHttpRequestFactory.setReadTimeout(5000);
    // 连接不够用的等待时间,不宜过长,必须设置,比如连接不够用时,时间过长将是灾难性的
    clientHttpRequestFactory.setConnectionRequestTimeout(200);
    // 缓冲请求数据,默认值是true。通过POST或者PUT大量发送数据时,建议将此属性更改为false,以免耗尽内存。
    clientHttpRequestFactory.setBufferRequestBody(false);

    // 添加内容转换器
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
    messageConverters.add(initStringHttpMessageConverter());
    messageConverters.add(new FormHttpMessageConverter());
    messageConverters.add(new MappingJackson2XmlHttpMessageConverter());
    messageConverters.add(new MappingJackson2HttpMessageConverter());

    RestTemplate restTemplate = new RestTemplate(messageConverters);
    restTemplate.setRequestFactory(clientHttpRequestFactory);
    restTemplate.setErrorHandler(new DefaultResponseErrorHandler());
    return restTemplate;

}
 
开发者ID:wu05281,项目名称:admin-shiro,代码行数:62,代码来源:RestTemplateConfig.java

示例13: configureRestTemplate

import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@Override
protected void configureRestTemplate(RestTemplate restTemplate) {
    restTemplate.setErrorHandler(new TwitterErrorHandler());
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:5,代码来源:TwitterTemplate.java

示例14: restTemplate

import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@Bean
public RestTemplate restTemplate() {
    RestTemplate restClient = new RestTemplate();
    restClient.setErrorHandler(new SeyrenResponseErrorHandler());
    return restClient;
}
 
开发者ID:voyages-sncf-technologies,项目名称:cerebro,代码行数:7,代码来源:App.java


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