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();
			}
		}
	}
相关推荐
zfj3219 分钟前
H2数据库源码学习+debug, 数据库 sql、数据库引擎、数据库存储从此不再神秘
java·数据库·sql·学习·数据库底层原理
编程、小哥哥1 小时前
Java面试实战:从Spring Boot到分布式缓存的深度探索
java·spring boot·redis·微服务·grpc·缓存技术·面试技巧
在未来等你1 小时前
互联网大厂Java求职面试:Spring AI与大模型交互的高级模式与自定义开发
java·微服务·云原生·大模型·spring ai
androidwork2 小时前
Android Kotlin权限管理最佳实践
android·java·kotlin
sakoba2 小时前
Tomcat简述介绍
java·tomcat
键盘客3 小时前
Spring Boot 配置明文密码加密,防泄漏
java·spring boot·后端·spring
二进制小甜豆3 小时前
SpringBoot快速上手
java·spring boot·maven
苹果酱05674 小时前
Golang中的runtime.LockOSThread 和 runtime.UnlockOSThread
java·vue.js·spring boot·mysql·课程设计
我命由我123454 小时前
Android 动态申请 REQUEST_INSTALL_PACKAGES 权限问题:申请权限失败
android·java·开发语言·java-ee·android studio·android jetpack·android-studio
令狐少侠20115 小时前
idea2024 不知道安装了什么插件,界面都是中文的了,不习惯,怎么修改各个选项改回英文
java·idea