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();
			}
		}
	}
相关推荐
悟能不能悟12 小时前
JAVA 对象转为二级制流,再转化为base64
java·开发语言
潲爺12 小时前
Java-IO笔记
java·笔记·学习
JH307312 小时前
静态资源映射相关问题解答
java
爬山算法12 小时前
Hibernate(6) Hibernate支持哪些数据库?
java·数据库·hibernate
爱吃牛肉的大老虎12 小时前
Spring WebFlux与SpringMVC 对比讲解
java·后端·spring
QQ 313163789012 小时前
文华财经软件指标公式期货买卖信号提示软件
java·前端·javascript
老华带你飞12 小时前
房屋租赁管理系统|基于java+ vue房屋租赁管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot·后端
jqrbcts12 小时前
关于发那科机器人如何时时把角度发给PLC
java·服务器·网络·人工智能
TheITSea13 小时前
Java中的Optional:从入门到精通
java·开发语言
程序员侠客行13 小时前
Mybatis入门到精通 一
java·架构·mybatis