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();
			}
		}
	}
相关推荐
一叶飘零_sweeeet1 分钟前
从 0 到 1 构建零丢失 RabbitMQ 数据同步堡垒:第三方接口数据零丢失的终极方案
java·分布式·rabbitmq
三水彡彡彡彡6 分钟前
Java中使用正则表达式的正确打开方式
java·开发语言·正则表达式
百思可瑞教育24 分钟前
Nginx代理缓存机制深度解析:从原理到最佳实践
java·nginx·缓存·北京百思可瑞教育·百思可瑞教育
@HXH1 小时前
LeetCode第二题知识点2 ---- 栈、堆、地址
java·开发语言
一 乐2 小时前
医院排班|医护人员排班系统|基于springboot医护人员排班系统设计与实现(源码+数据库+文档)
java·数据库·spring boot·后端·论文·毕设·医护人员排班系统
稚辉君.MCA_P8_Java3 小时前
HTTP的状态码有哪些,并用例子说明一下
java·服务器·jvm·http·kubernetes
the beard3 小时前
Java类加载与JVM详解:从基础到双亲委托机制
java·jvm
纪东东3 小时前
做一个实用的节假日工具
java·开发语言
毕设源码余学姐3 小时前
计算机毕设javayit商城 基于SSM框架的校园二手交易全流程管理系统设计与实现 Java+MySQL的校园二手商品交易与供需对接平台开发
java·mysql·课程设计
城管不管3 小时前
Session
java·运维·服务器·后端