當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。