org.springframework.web.client.RestTemplate

复制代码
	/**
	 * Execute the given method on the provided URI.
	 * <p>The {@link ClientHttpRequest} is processed using the {@link RequestCallback};
	 * the response with the {@link ResponseExtractor}.
	 * @param url the fully-expanded URL to connect to
	 * @param method the HTTP method to execute (GET, POST, etc.)
	 * @param requestCallback object that prepares the request (can be {@code null})
	 * @param responseExtractor object that extracts the return value from the response (can be {@code null})
	 * @return an arbitrary object, as returned by the {@link ResponseExtractor}
	 */
	protected <T> T doExecute(URI url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor) throws RestClientException
	{

		Assert.notNull(url, "'url' must not be null");
		Assert.notNull(method, "'method' must not be null");
		ClientHttpResponse response = null;
		try
		{
			ClientHttpRequest request = createRequest(url, method);
			if (requestCallback != null)
			{
				requestCallback.doWithRequest(request);
			}
			response = request.execute();
			handleResponse(url, method, response);
			if (responseExtractor != null)
			{
				return responseExtractor.extractData(response);
			}
			else
			{
				return null;
			}
		}
		catch (IOException ex)
		{
			String resource = url.toString();
			String query = url.getRawQuery();
			resource = (query != null ? resource.substring(0, resource.indexOf(query) - 1) : resource);
			throw new ResourceAccessException("I/O error on " + method.name() + " request for \"" + resource + "\": " + ex.getMessage(), ex);
		}
		finally
		{
			if (response != null)
			{
				response.close();
			}
		}
	}
相关推荐
while(1){yan}4 分钟前
JAVA单例模式
java·单例模式
没有bug.的程序员12 分钟前
Async Profiler:最精准的火焰图工具
java·jvm·spring·对象分配·async profiler
金士顿19 分钟前
Ethercat耦合器添加的IO导出xml 初始化IO参数
android·xml·java
7哥♡ۣۖᝰꫛꫀꪝۣℋ25 分钟前
Spring WebMVC及常用注释
java·数据库·spring
曹牧26 分钟前
C#:Dictionary类型数组
java·开发语言·c#
躺着听Jay27 分钟前
【1267 - Illegal mix of collations 】mysql报错解决记录
java·linux·前端
bbq粉刷匠30 分钟前
力扣-电话号码组合
java·算法
xunyan623431 分钟前
面向对象(下)-模版方法的设计模式其应用场景
java·学习·设计模式
Yweir34 分钟前
Linux性能监控的工具集和分析命令工具
java·linux·jvm
Dxxyyyy39 分钟前
零基础学JAVA--Day41(IO文件流+IO流原理+InputStream+OutputStream)
java·开发语言·python