本文整理汇总了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()));
}
示例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;
}
示例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");
}
示例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");
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例10: restTemplate
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@LoadBalanced
@Bean
RestTemplate restTemplate() {
RestTemplate template = new RestTemplate();
template.setErrorHandler(getResponseErrorHandler());
return template;
}
示例11: restTemplate
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@Primary
@Bean(name="testRestTemplate")
RestTemplate restTemplate() {
RestTemplate template = new RestTemplate();
template.setErrorHandler(getResponseErrorHandler());
return template;
}
示例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;
}
示例13: configureRestTemplate
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@Override
protected void configureRestTemplate(RestTemplate restTemplate) {
restTemplate.setErrorHandler(new TwitterErrorHandler());
}
示例14: restTemplate
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@Bean
public RestTemplate restTemplate() {
RestTemplate restClient = new RestTemplate();
restClient.setErrorHandler(new SeyrenResponseErrorHandler());
return restClient;
}