RestTemplate的一个请求过程,mark一下

Posted 沧海一滴

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RestTemplate的一个请求过程,mark一下相关的知识,希望对你有一定的参考价值。

 

17:14:36.979 [main] DEBUG org.springframework.web.client.RestTemplate - Created GET request for "http://localhost:8080/test/session/get"
17:14:36.992 [main] DEBUG org.springframework.web.client.RestTemplate - Setting request Accept header to [application/json, application/*+json]
17:14:37.007 [main] DEBUG org.apache.http.client.protocol.RequestAddCookies - CookieSpec selected: default
17:14:37.015 [main] DEBUG org.apache.http.client.protocol.RequestAuthCache - Auth cache not set in the context
17:14:37.016 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection request: [route: {}->http://localhost:8080][total kept alive: 0; route allocated: 0 of 200; total allocated: 0 of 300]
17:14:37.028 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {}->http://localhost:8080][total kept alive: 0; route allocated: 1 of 200; total allocated: 1 of 300]
17:14:37.030 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Opening connection {}->http://localhost:8080
17:14:37.037 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connecting to localhost/127.0.0.1:8080
17:14:37.038 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connection established 127.0.0.1:60552<->127.0.0.1:8080
17:14:37.038 [main] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-0: set socket timeout to 5000
17:14:37.038 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Executing request GET /test/session/get HTTP/1.1
17:14:37.038 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Target auth state: UNCHALLENGED
17:14:37.038 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED
17:14:37.040 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> GET /test/session/get HTTP/1.1
17:14:37.040 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept: application/json, application/*+json
17:14:37.040 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Type: application/json;charset=UTF-8
17:14:37.040 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: localhost:8080
17:14:37.040 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: Keep-Alive
17:14:37.040 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.6 (Java/1.8.0_144)
17:14:37.040 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate
17:14:37.040 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "GET /test/session/get HTTP/1.1[\r][\n]"
17:14:37.040 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept: application/json, application/*+json[\r][\n]"
17:14:37.040 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Type: application/json;charset=UTF-8[\r][\n]"
17:14:37.040 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: localhost:8080[\r][\n]"
17:14:37.040 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
17:14:37.040 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.6 (Java/1.8.0_144)[\r][\n]"
17:14:37.040 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
17:14:37.040 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]"
17:14:37.056 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 200 [\r][\n]"
17:14:37.056 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Application-Context: application:dev,redis,log,flyway[\r][\n]"
17:14:37.056 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "ETag: "099914b932bd37a50b983c5e7c90ae93b"[\r][\n]"
17:14:37.056 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Content-Type-Options: nosniff[\r][\n]"
17:14:37.056 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-XSS-Protection: 1; mode=block[\r][\n]"
17:14:37.056 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Frame-Options: DENY[\r][\n]"
17:14:37.056 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Set-Cookie: SESSION=36fed5e6-fe6d-4b9e-87a1-7f7aa5ef8bf0; Path=/; HttpOnly[\r][\n]"
17:14:37.056 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Type: application/json[\r][\n]"
17:14:37.056 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Length: 2[\r][\n]"
17:14:37.056 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Date: Thu, 13 Dec 2018 09:14:37 GMT[\r][\n]"
17:14:37.056 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]"
17:14:37.056 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "{}"
17:14:37.058 [main] DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 200 
17:14:37.058 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Application-Context: application:dev,redis,log,flyway
17:14:37.058 [main] DEBUG org.apache.http.headers - http-outgoing-0 << ETag: "099914b932bd37a50b983c5e7c90ae93b"
17:14:37.058 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Content-Type-Options: nosniff
17:14:37.058 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-XSS-Protection: 1; mode=block
17:14:37.058 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Frame-Options: DENY
17:14:37.058 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Set-Cookie: SESSION=36fed5e6-fe6d-4b9e-87a1-7f7aa5ef8bf0; Path=/; HttpOnly
17:14:37.058 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Type: application/json
17:14:37.058 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Length: 2
17:14:37.058 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Date: Thu, 13 Dec 2018 09:14:37 GMT
17:14:37.061 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Connection can be kept alive indefinitely
17:14:37.066 [main] DEBUG org.apache.http.client.protocol.ResponseProcessCookies - Cookie accepted [SESSION="36fed5e6-fe6d-4b9e-87a1-7f7aa5ef8bf0", version:0, domain:localhost, path:/, expiry:null]
17:14:37.070 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection [id: 0][route: {}->http://localhost:8080] can be kept alive indefinitely
17:14:37.070 [main] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-0: set socket timeout to 0
17:14:37.070 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {}->http://localhost:8080][total kept alive: 1; route allocated: 1 of 200; total allocated: 1 of 300]
17:14:37.070 [main] INFO com.tangcheng.app.business.config.LoggingClientHttpRequestInterceptor - cost:[74]ms,GET url:http://localhost:8080/test/session/get. request:,
response:{},
17:14:37.072 [main] DEBUG org.springframework.web.client.RestTemplate - GET request for "http://localhost:8080/test/session/get" resulted in 200 ()
17:14:37.073 [main] DEBUG org.springframework.web.client.RestTemplate - Reading [java.util.Map<java.lang.String, java.lang.Object>] as "application/json" using [org.springfr[email protected]2dca0d64]
{}
17:14:37.098 [main] DEBUG org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate - Retrieved ApplicationContext from cache with key [[[email protected] testClass = RestTemplateApiTest, locations = ‘{}‘, classes = ‘{class com.tangcheng.app.business.config.RestTemplateConfig}‘, contextInitializerClasses = ‘[]‘, activeProfiles = ‘{}‘, propertySourceLocations = ‘{}‘, propertySourceProperties = ‘{}‘, contextCustomizers = set[org.springfr[email protected]6321e813, org.springframework.boot.test.json.DuplicateJsonObje[email protected]57855c9a, org.[email protected]0, org.springframework.boot[email protected]0, org.springframework.boot.test.autocon[email protected]5f282abb], contextLoader = ‘org.springframework.test.context.support.DelegatingSmartContextLoader‘, parent = [null]]]
17:14:37.098 [main] DEBUG org.springframework.test.context.cache - Spring test ApplicationContext cache statistics: [[email protected] size = 1, maxSize = 32, parentContextCount = 0, hitCount = 2, missCount = 1]
17:14:37.098 [main] DEBUG org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate - Retrieved ApplicationContext from cache with key [[[email protected] testClass = RestTemplateApiTest, locations = ‘{}‘, classes = ‘{class com.tangcheng.app.business.config.RestTemplateConfig}‘, contextInitializerClasses = ‘[]‘, activeProfiles = ‘{}‘, propertySourceLocations = ‘{}‘, propertySourceProperties = ‘{}‘, contextCustomizers = set[org.springfr[email protected]6321e813, org.springframework.boot.test.json.DuplicateJsonObje[email protected]57855c9a, org.[email protected]0, org.springframework.boot[email protected]0, org.springframework.boot.test.autocon[email protected]5f282abb], contextLoader = ‘org.springframework.test.context.support.DelegatingSmartContextLoader‘, parent = [null]]]
17:14:37.098 [main] DEBUG org.springframework.test.context.cache - Spring test ApplicationContext cache statistics: [[email protected] size = 1, maxSize = 32, parentContextCount = 0, hitCount = 3, missCount = 1]
17:14:37.099 [main] DEBUG org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate - Retrieved ApplicationContext from cache with key [[[email protected] testClass = RestTemplateApiTest, locations = ‘{}‘, classes = ‘{class com.tangcheng.app.business.config.RestTemplateConfig}‘, contextInitializerClasses = ‘[]‘, activeProfiles = ‘{}‘, propertySourceLocations = ‘{}‘, propertySourceProperties = ‘{}‘, contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCus[email protected], org.springframework.boot.test.json.DuplicateJsonObje[email protected]57855c9a, org.[email protected]0, org.springframework.boot[email protected]0, org.springframework.boot.test.autocon[email protected]5f282abb], contextLoader = ‘org.springframework.test.context.support.DelegatingSmartContextLoader‘, parent = [null]]]
17:14:37.100 [main] DEBUG org.springframework.test.context.cache - Spring test ApplicationContext cache statistics: [[email protected] size = 1, maxSize = 32, parentContextCount = 0, hitCount = 4, missCount = 1]
17:14:37.100 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean ‘org.springframework.boot.test.mock.mockito.MockitoBeans‘
17:14:37.100 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - After test method: context [[email protected] testClass = RestTemplateApiTest, testInstance = [email protected], testMethod = [email protected]t, testException = [null], mergedContextConfiguration = [[email protected] testClass = RestTemplateApiTest, locations = ‘{}‘, classes = ‘{class com.tangcheng.app.business.config.RestTemplateConfig}‘, contextInitializerClasses = ‘[]‘, activeProfiles = ‘{}‘, propertySourceLocations = ‘{}‘, propertySourceProperties = ‘{}‘, contextCustomizers = set[org.springfr[email protected]6321e813, org.springframework.boot.test.json.DuplicateJsonObje[email protected]57855c9a, org.[email protected]0, org.springframework.boot[email protected]0, org.springframework.boot.test.autocon[email protected]5f282abb], contextLoader = ‘org.springframework.test.context.support.DelegatingSmartContextLoader‘, parent = [null]]], class annotated with @DirtiesContext [false] with mode [null], method annotated with @DirtiesContext [false] with mode [null].
17:14:37.105 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - After test class: context [[email protected] testClass = RestTemplateApiTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [[email protected] testClass = RestTemplateApiTest, locations = ‘{}‘, classes = ‘{class com.tangcheng.app.business.config.RestTemplateConfig}‘, contextInitializerClasses = ‘[]‘, activeProfiles = ‘{}‘, propertySourceLocations = ‘{}‘, propertySourceProperties = ‘{}‘, contextCustomizers = set[org.springfr[email protected]6321e813, org.springframework.boot.test.json.DuplicateJsonObje[email protected]57855c9a, org.[email protected]0, org.springframework.boot[email protected]0, org.springframework.boot.test.autocon[email protected]5f282abb], contextLoader = ‘org.springframework.test.context.support.DelegatingSmartContextLoader‘, parent = [null]]], class annotated with @DirtiesContext [false] with mode [null].
17:14:37.106 [Thread-0] INFO com.tangcheng.app.business.config.RestTemplateConfig - closing http client
17:14:37.106 [Thread-1] INFO org.springframework.context.support.GenericApplicationContext - Closing [email protected]0f8e03: startup date [Thu Dec 13 17:14:35 CST 2018]; root of context hierarchy
17:14:37.106 [Thread-0] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection manager is shutting down
17:14:37.106 [Thread-0] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-0: Close connection
17:14:37.106 [Thread-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean ‘lifecycleProcessor‘
17:14:37.106 [Thread-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.s[email protected]143640d5: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,restTemplateConfig,org.springframework.boot.test.mock.mockito.MockitoPostProcessor$SpyPostProcessor,org.springframework.boot.test.mock.mockito.MockitoPostProcessor,restTemplate]; root of factory hierarchy
17:14:37.107 [Thread-0] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection manager shut down
17:14:37.107 [Thread-0] INFO com.tangcheng.app.business.config.RestTemplateConfig - http client closed

 

感觉挺有意思的

 

以上是关于RestTemplate的一个请求过程,mark一下的主要内容,如果未能解决你的问题,请参考以下文章

SpringBoot系列之RestTemplate使用示例

Spring RestTemplate 之get请求

RestTemplate发送数据为JSON的Post请求

学习 RestTemplate 一篇文章就够了 !!!

使用RestTemplate在代码内调用POST请求的参数乱码问题

RestTemplate中几种常见的请求方式