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();
			}
		}
	}
相关推荐
whn197725 分钟前
达梦连接串JDBC测试程序
java·数据库
还是鼠鼠28 分钟前
Spring AI ChatClient详解:创建第一个AI客户端
java·springboot·spring ai·chatclient
vHelios1 小时前
【电商项目】测试 授权功能 遇到的问题与解决方案
java·spring boot·sql
2401_894915531 小时前
GEO 定位优化源码搭建常见报错排查:数据库、伪静态、接口调试
java·数据库·网络协议·tcp/ip·spring·unity
bbq粉刷匠1 小时前
ArrayList 整体认识
java·jvm·数据结构
水无痕simon1 小时前
15 转账对接文档
java·区块链
西凉的悲伤1 小时前
Java 基于 MySQL 行锁实现高并发业务序列号生成器
java·mysql·springboot·序列号生成
lv__pf1 小时前
servlet与jsp
java·开发语言·servlet
xieliyu.2 小时前
Java 文件IO :File 文件类、字节流、字符流讲解
java·ide·笔记·javaee
云烟成雨TD2 小时前
Micrometer 系列【28】Spring Boot Actuator | 其他指标速览
java·spring boot·云原生