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();
			}
		}
	}
相关推荐
稻草猫.8 分钟前
SpringBoot日志全解析:从调试到持久化
java·开发语言·spring boot·java-ee·idea
zopple8 分钟前
Knife4j文档请求异常(基于SpringBoot3,查找原因并解决)
java·服务器·数据库
清水白石00816 分钟前
Python 弱引用深度解析——让缓存不再成为内存泄漏的温床
java·python·缓存
zzb158017 分钟前
RAG from Scratch-优化-routing
java·前端·网络·人工智能·后端·python·mybatis
深蓝轨迹43 分钟前
IDEA 中 Spring Boot 配置文件的自动提示消失(无法扫描配置文件)的完整解决方案
java·spring boot·intellij-idea
杀神lwz1 小时前
Java Json压缩工具类
java·json
虾..1 小时前
Linux 基于TCP实现服务端客户端通信(线程池)
java·网络协议·tcp/ip
前端小雪的博客.1 小时前
【Java 基础】变量全解:定义、命名规范、作用域与常量(附代码示例+面试题)
java·作用域·java基础·java入门·变量·常量·java面试题
mldlds1 小时前
【异常解决】Unable to start embedded Tomcat Nacos 启动报错
java·tomcat
代码探秘者1 小时前
【Java】final、finally、finalize 区别
java·开发语言