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();
			}
		}
	}
相关推荐
汝生淮南吾在北3 小时前
SpringBoot+Vue饭店点餐管理系统
java·vue.js·spring boot·毕业设计·毕设
冬夜戏雪6 小时前
【java学习日记】【2025.12.7】【7/60】
java·开发语言·学习
CC.GG6 小时前
【C++】二叉搜索树
java·c++·redis
JIngJaneIL8 小时前
基于Java非遗传承文化管理系统(源码+数据库+文档)
java·开发语言·数据库·vue.js·spring boot
南部余额8 小时前
踩坑与解惑:深入理解 SpringBoot 自动配置原理与配置排除机制
java·spring boot·自动配置原理·import
木鹅.9 小时前
LangChain4j
java
永远都不秃头的程序员(互关)9 小时前
Java核心技术精要:高效实践指南
java·开发语言·性能优化
CoderYanger10 小时前
动态规划算法-子序列问题(数组中不连续的一段):28.摆动序列
java·算法·leetcode·动态规划·1024程序员节
代码栈上的思考10 小时前
深入解析Spring IoC核心与关键注解
java·后端·spring
Mai Dang10 小时前
SpringBoot4用Swagger
java