本文整理匯總了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;
}