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();
			}
		}
	}
相关推荐
赵杰伦cpp4 小时前
C++的继承机制精讲
java·开发语言·c++·后端
.ZGR.4 小时前
蓝桥杯高校新生编程赛第一场题解——Java
java·算法·蓝桥杯
百花~4 小时前
JVM(Java虚拟机)~
java·开发语言·jvm
范清远4 小时前
java:1基本知识
java
tant4 小时前
声明式事务@Transactional失效场景研究
java
沐苏瑶4 小时前
PHP反序列化漏洞
java·开发语言
该用户已不存在5 小时前
写了这么多年Java,这几个神仙技巧你用过吗?
java·后端
小王不爱笑1325 小时前
Java 核心知识点查漏补缺(二)
java·开发语言
Lacrimosa&L5 小时前
OS_2 进程与线程(进程管理)
java·开发语言
zl9798995 小时前
SpringBoot-Web开发之嵌入式容器
java·spring boot