沉稳的打火机 · YOLO内卷时期该如何选模型?· 5 月前 · |
安静的匕首 · Docker RabbitMQ安装 ...· 11 月前 · |
打酱油的帽子 · anaconda安装perl-火山引擎· 1 年前 · |
傻傻的瀑布 · MATLAB-循环类型相关(for ...· 1 年前 · |
苦闷的手术刀 · 并列不等高块状元素保持高度一致 - 掘金· 1 年前 · |
string uri |
https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/web/client/TestRestTemplate.html |
失望的作业本
1 月前 |
RestTemplate
that is suitable for integration tests.
TestRestTemplate
is fault-tolerant. This means that 4xx and 5xx do not result
in an exception being thrown and can instead be detected through the
response entity
and its
status code
.
A
TestRestTemplate
can optionally carry Basic authentication headers. If Apache
Http Client 4.3.2 or better is available (recommended) it will be used as the client,
and by default configured to ignore cookies and redirects.
Note: To prevent injection problems this class intentionally does not extend
RestTemplate
. If you need access to the underlying
RestTemplate
use
getRestTemplate()
.
If you are using the
@SpringBootTest
annotation
with an embedded server, a
TestRestTemplate
is automatically available and can
be
@Autowired
into your test. If you need customizations (for example to adding
additional message converters) use a
RestTemplateBuilder
@Bean
.
protected static class
HttpComponentsClientHttpRequestFactory
to apply customizations.
static enum
TestRestTemplate
(
String
username,
String
password,
TestRestTemplate.HttpClientOption
... httpClientOptions)
TestRestTemplate
instance with the specified credentials.
TestRestTemplate
(
TestRestTemplate.HttpClientOption
... httpClientOptions)
TestRestTemplate
instance.
TestRestTemplate
(
RestTemplateBuilder
restTemplateBuilder)
TestRestTemplate
instance.
TestRestTemplate
(
RestTemplateBuilder
builder,
String
username,
String
password,
TestRestTemplate.HttpClientOption
... httpClientOptions)
TestRestTemplate
instance with the specified credentials.
ResponseEntity
.
<T>
ResponseEntity
<T>
exchange
(
String
url,
HttpMethod
method,
HttpEntity
<?> requestEntity,
Class
<T> responseType,
Map
<
String
,
?> urlVariables)
ResponseEntity
.
<T>
ResponseEntity
<T>
exchange
(
String
url,
HttpMethod
method,
HttpEntity
<?> requestEntity,
ParameterizedTypeReference
<T> responseType,
Object
... urlVariables)
ResponseEntity
.
<T>
ResponseEntity
<T>
exchange
(
String
url,
HttpMethod
method,
HttpEntity
<?> requestEntity,
ParameterizedTypeReference
<T> responseType,
Map
<
String
,
?> urlVariables)
ResponseEntity
.
<T>
ResponseEntity
<T>
exchange
(
URI
url,
HttpMethod
method,
HttpEntity
<?> requestEntity,
Class
<T> responseType)
ResponseEntity
.
<T>
ResponseEntity
<T>
exchange
(
URI
url,
HttpMethod
method,
HttpEntity
<?> requestEntity,
ParameterizedTypeReference
<T> responseType)
ResponseEntity
.
<T>
ResponseEntity
<T>
exchange
(
RequestEntity
<?> requestEntity,
Class
<T> responseType)
RequestEntity
and return the
response as
ResponseEntity
.
<T>
ResponseEntity
<T>
exchange
(
RequestEntity
<?> requestEntity,
ParameterizedTypeReference
<T> responseType)
RequestEntity
and return the
response as
ResponseEntity
.
execute
(
String
url,
HttpMethod
method,
RequestCallback
requestCallback,
ResponseExtractor
<T> responseExtractor,
Object
... urlVariables)
RequestCallback
, and reading the response with a
ResponseExtractor
.
execute
(
String
url,
HttpMethod
method,
RequestCallback
requestCallback,
ResponseExtractor
<T> responseExtractor,
Map
<
String
,
?> urlVariables)
RequestCallback
, and reading the response with a
ResponseExtractor
.
execute
(
URI
url,
HttpMethod
method,
RequestCallback
requestCallback,
ResponseExtractor
<T> responseExtractor)
RequestCallback
, and reading the response with a
ResponseExtractor
.
<T>
ResponseEntity
<T>
getForEntity
(
String
url,
Class
<T> responseType,
Object
... urlVariables)
<T>
ResponseEntity
<T>
getForEntity
(
String
url,
Class
<T> responseType,
Map
<
String
,
?> urlVariables)
<T>
ResponseEntity
<T>
getForEntity
(
URI
url,
Class
<T> responseType)
getForObject
(
String
url,
Class
<T> responseType,
Object
... urlVariables)
getForObject
(
String
url,
Class
<T> responseType,
Map
<
String
,
?> urlVariables)
getForObject
(
URI
url,
Class
<T> responseType)
RestTemplate
that is actually used to perform the
REST operations.
getRootUri
()
RestTemplateBuilder.rootUri(String)
or
""
if the root URI has not been applied.
headForHeaders
(
String
url,
Object
... urlVariables)
headForHeaders
(
String
url,
Map
<
String
,
?> urlVariables)
headForHeaders
(
URI
url)
Set
<
HttpMethod
>
optionsForAllow
(
String
url,
Object
... urlVariables)
Allow
header for the given URI.
Set
<
HttpMethod
>
optionsForAllow
(
String
url,
Map
<
String
,
?> urlVariables)
Allow
header for the given URI.
Set
<
HttpMethod
>
optionsForAllow
(
URI
url)
Allow
header for the given URL.
patchForObject
(
String
url,
Object
request,
Class
<T> responseType,
Object
... uriVariables)
patchForObject
(
String
url,
Object
request,
Class
<T> responseType,
Map
<
String
,
?> uriVariables)
patchForObject
(
URI
url,
Object
request,
Class
<T> responseType)
<T>
ResponseEntity
<T>
postForEntity
(
String
url,
Object
request,
Class
<T> responseType,
Object
... urlVariables)
ResponseEntity
.
<T>
ResponseEntity
<T>
HttpEntity
.
<T>
ResponseEntity
<T>
postForEntity
(
URI
url,
Object
request,
Class
<T> responseType)
ResponseEntity
.
postForLocation
(
String
url,
Object
request,
Object
... urlVariables)
Location
header.
postForLocation
(
String
url,
Object
request,
Map
<
String
,
?> urlVariables)
Location
header.
postForLocation
(
URI
url,
Object
request)
Location
header.
postForObject
(
String
url,
Object
request,
Class
<T> responseType,
Object
... urlVariables)
postForObject
(
URI
url,
Object
request,
Class
<T> responseType)
setUriTemplateHandler
(
UriTemplateHandler
handler)
UriTemplateHandler
to use to expand URI templates.
withBasicAuth
(
String
username,
String
password)
TestRestTemplate
with the same configuration as this one,
except that it will send basic authorization headers using the given
username
and
password
.
TestRestTemplate
instance.
restTemplateBuilder
- builder used to configure underlying
RestTemplate
TestRestTemplate
instance.
httpClientOptions
- client options to use if the Apache HTTP Client is used
TestRestTemplate
instance with the specified credentials.
username
- the username to use (or
null
)
password
- the password (or
null
)
httpClientOptions
- client options to use if the Apache HTTP Client is used
TestRestTemplate
instance with the specified credentials.
builder
- builder used to configure underlying
RestTemplate
username
- the username to use (or
null
)
password
- the password (or
null
)
httpClientOptions
- client options to use if the Apache HTTP Client is used
UriTemplateHandler
to use to expand URI templates. By default
the
DefaultUriBuilderFactory
is used which relies on Spring's URI template
support and exposes several useful properties that customize its behavior for
encoding and for prepending a common base URL. An alternative implementation may be
used to plug an external URI template library.
handler
- the URI template handler to use
RestTemplateBuilder.rootUri(String)
or
""
if the root URI has not been applied.
T
- the type of the return value
url
- the URL
responseType
- the type of the return value
urlVariables
- the variables to expand the template
RestTemplate.getForObject(String, Class, Object...)
T
- the type of the return value
url
- the URL
responseType
- the type of the return value
urlVariables
- the map containing variables for the URI template
RestTemplate.getForObject(String, Class, Object...)
T
- the type of the return value
url
- the URL
responseType
- the type of the return value
RestTemplate.getForObject(java.net.URI, java.lang.Class)
ResponseEntity
.
URI Template variables are expanded using the given URI variables, if any.
T
- the type of the return value
url
- the URL
responseType
- the type of the return value
urlVariables
- the variables to expand the template
RestTemplate.getForEntity(java.lang.String, java.lang.Class, java.lang.Object[])
ResponseEntity
.
URI Template variables are expanded using the given map.
T
- the type of the return value
url
- the URL
responseType
- the type of the return value
urlVariables
- the map containing variables for the URI template
RestTemplate.getForEntity(java.lang.String, java.lang.Class, java.util.Map)
ResponseEntity
.
T
- the type of the return value
url
- the URL
responseType
- the type of the return value
RestTemplate.getForEntity(java.net.URI, java.lang.Class)
url
- the URL
urlVariables
- the variables to expand the template
RestTemplate.headForHeaders(java.lang.String, java.lang.Object[])
url
- the URL
urlVariables
- the map containing variables for the URI template
RestTemplate.headForHeaders(java.lang.String, java.util.Map)
url
- the URL
RestTemplate.headForHeaders(java.net.URI)
Location
header. This header typically indicates where the
new resource is stored.
URI Template variables are expanded using the given URI variables, if any.
The
request
parameter can be a
HttpEntity
in order to add
additional HTTP headers to the request.
url
- the URL
request
- the Object to be POSTed, may be
null
urlVariables
- the variables to expand the template
Location
header
HttpEntity
RestTemplate.postForLocation(java.lang.String, java.lang.Object, java.lang.Object[])
Location
header. This header typically indicates where the
new resource is stored.
URI Template variables are expanded using the given map.
The
request
parameter can be a
HttpEntity
in order to add
additional HTTP headers to the request.
url
- the URL
request
- the Object to be POSTed, may be
null
urlVariables
- the variables to expand the template
Location
header
HttpEntity
RestTemplate.postForLocation(java.lang.String, java.lang.Object, java.util.Map)
Location
header. This header typically indicates where the new
resource is stored.
The
request
parameter can be a
HttpEntity
in order to add
additional HTTP headers to the request.
url
- the URL
request
- the Object to be POSTed, may be
null
Location
header
HttpEntity
RestTemplate.postForLocation(java.net.URI, java.lang.Object)
request
parameter can be a
HttpEntity
in order to add
additional HTTP headers to the request.
T
- the type of the return value
url
- the URL
request
- the Object to be POSTed, may be
null
responseType
- the type of the return value
urlVariables
- the variables to expand the template
HttpEntity
RestTemplate.postForObject(java.lang.String, java.lang.Object, java.lang.Class, java.lang.Object[])
request
parameter can be a
HttpEntity
in order to add
additional HTTP headers to the request.
T
- the type of the return value
url
- the URL
request
- the Object to be POSTed, may be
null
responseType
- the type of the return value
urlVariables
- the variables to expand the template
HttpEntity
RestTemplate.postForObject(java.lang.String, java.lang.Object, java.lang.Class, java.util.Map)
request
parameter can be a
HttpEntity
in order to add
additional HTTP headers to the request.
T
- the type of the return value
url
- the URL
request
- the Object to be POSTed, may be
null
responseType
- the type of the return value
HttpEntity
RestTemplate.postForObject(java.net.URI, java.lang.Object, java.lang.Class)
ResponseEntity
.
URI Template variables are expanded using the given URI variables, if any.
The
request
parameter can be a
HttpEntity
in order to add
additional HTTP headers to the request.
T
- the type of the return value
url
- the URL
request
- the Object to be POSTed, may be
null
responseType
- the response type to return
urlVariables
- the variables to expand the template
HttpEntity
RestTemplate.postForEntity(java.lang.String, java.lang.Object, java.lang.Class, java.lang.Object[])
HttpEntity
.
URI Template variables are expanded using the given map.
The
request
parameter can be a
HttpEntity
in order to add
additional HTTP headers to the request.
T
- the type of the return value
url
- the URL
request
- the Object to be POSTed, may be
null
responseType
- the response type to return
urlVariables
- the variables to expand the template
HttpEntity
RestTemplate.postForEntity(java.lang.String, java.lang.Object, java.lang.Class, java.util.Map)
ResponseEntity
.
The
request
parameter can be a
HttpEntity
in order to add
additional HTTP headers to the request.
T
- the type of the return value
url
- the URL
request
- the Object to be POSTed, may be
null
responseType
- the response type to return
HttpEntity
RestTemplate.postForEntity(java.net.URI, java.lang.Object, java.lang.Class)
request
parameter can be a
HttpEntity
in order to add
additional HTTP headers to the request.
If you need to assert the request result consider using the
exchange
method.
url
- the URL
request
- the Object to be PUT, may be
null
urlVariables
- the variables to expand the template
HttpEntity
RestTemplate.put(java.lang.String, java.lang.Object, java.lang.Object[])
request
parameter can be a
HttpEntity
in order to add
additional HTTP headers to the request.
If you need to assert the request result consider using the
exchange
method.
url
- the URL
request
- the Object to be PUT, may be
null
urlVariables
- the variables to expand the template
HttpEntity
RestTemplate.put(java.lang.String, java.lang.Object, java.util.Map)
request
parameter can be a
HttpEntity
in order to add
additional HTTP headers to the request.
If you need to assert the request result consider using the
exchange
method.
url
- the URL
request
- the Object to be PUT, may be
null
HttpEntity
RestTemplate.put(java.net.URI, java.lang.Object)
request
parameter can be a
HttpEntity
in order to add
additional HTTP headers to the request.
T
- the type of the return value
url
- the URL
request
- the Object to be PATCHed, may be
null
responseType
- the type of the return value
uriVariables
- the variables to expand the template
HttpEntity
request
parameter can be a
HttpEntity
in order to add
additional HTTP headers to the request.
T
- the type of the return value
url
- the URL
request
- the Object to be PATCHed, may be
null
responseType
- the type of the return value
uriVariables
- the variables to expand the template
HttpEntity
request
parameter can be a
HttpEntity
in order to add
additional HTTP headers to the request.
T
- the type of the return value
url
- the URL
request
- the Object to be POSTed, may be
null
responseType
- the type of the return value
HttpEntity
exchange
method.
url
- the URL
urlVariables
- the variables to expand in the template
RestTemplate.delete(java.lang.String, java.lang.Object[])
exchange
method.
url
- the URL
urlVariables
- the variables to expand the template
RestTemplate.delete(java.lang.String, java.util.Map)
exchange
method.
url
- the URL
RestTemplate.delete(java.net.URI)
Allow
header for the given URI.
URI Template variables are expanded using the given URI variables, if any.
url
- the URL
urlVariables
- the variables to expand in the template
Allow
header
RestTemplate.optionsForAllow(java.lang.String, java.lang.Object[])
Allow
header for the given URI.
URI Template variables are expanded using the given map.
url
- the URL
urlVariables
- the variables to expand in the template
Allow
header
RestTemplate.optionsForAllow(java.lang.String, java.util.Map)
Allow
header for the given URL.
url
- the URL
Allow
header
RestTemplate.optionsForAllow(java.net.URI)
ResponseEntity
.
URI Template variables are expanded using the given URI variables, if any.
T
- the type of the return value
url
- the URL
method
- the HTTP method (GET, POST, etc.)
requestEntity
- the entity (headers and/or body) to write to the request, may
be
null
responseType
- the type of the return value
urlVariables
- the variables to expand in the template
RestTemplate.exchange(java.lang.String, org.springframework.http.HttpMethod, org.springframework.http.HttpEntity, java.lang.Class, java.lang.Object[])
ResponseEntity
.
URI Template variables are expanded using the given URI variables, if any.
T
- the type of the return value
url
- the URL
method
- the HTTP method (GET, POST, etc.)
requestEntity
- the entity (headers and/or body) to write to the request, may
be
null
responseType
- the type of the return value
urlVariables
- the variables to expand in the template
RestTemplate.exchange(java.lang.String, org.springframework.http.HttpMethod, org.springframework.http.HttpEntity, java.lang.Class, java.util.Map)
ResponseEntity
.
T
- the type of the return value
url
- the URL
method
- the HTTP method (GET, POST, etc.)
requestEntity
- the entity (headers and/or body) to write to the request, may
be
null
responseType
- the type of the return value
RestTemplate.exchange(java.net.URI, org.springframework.http.HttpMethod, org.springframework.http.HttpEntity, java.lang.Class)
ResponseEntity
. The given
ParameterizedTypeReference
is used to pass generic type information:
ParameterizedTypeReference<List<MyBean>> myBean = new ParameterizedTypeReference<List<MyBean>>() {};
ResponseEntity<List<MyBean>> response = template.exchange("https://example.com",HttpMethod.GET, null, myBean);
T
- the type of the return value
url
- the URL
method
- the HTTP method (GET, POST, etc.)
requestEntity
- the entity (headers and/or body) to write to the request, may
be
null
responseType
- the type of the return value
urlVariables
- the variables to expand in the template
RestTemplate.exchange(java.lang.String, org.springframework.http.HttpMethod, org.springframework.http.HttpEntity, org.springframework.core.ParameterizedTypeReference, java.lang.Object[])
ResponseEntity
. The given
ParameterizedTypeReference
is used to pass generic type information:
ParameterizedTypeReference<List<MyBean>> myBean = new ParameterizedTypeReference<List<MyBean>>() {};
ResponseEntity<List<MyBean>> response = template.exchange("https://example.com",HttpMethod.GET, null, myBean);
T
- the type of the return value
url
- the URL
method
- the HTTP method (GET, POST, etc.)
requestEntity
- the entity (headers and/or body) to write to the request, may
be
null
responseType
- the type of the return value
urlVariables
- the variables to expand in the template
RestTemplate.exchange(java.lang.String, org.springframework.http.HttpMethod, org.springframework.http.HttpEntity, org.springframework.core.ParameterizedTypeReference, java.util.Map)
ResponseEntity
. The given
ParameterizedTypeReference
is used to pass generic type information:
ParameterizedTypeReference<List<MyBean>> myBean = new ParameterizedTypeReference<List<MyBean>>() {};
ResponseEntity<List<MyBean>> response = template.exchange("https://example.com",HttpMethod.GET, null, myBean);
T
- the type of the return value
url
- the URL
method
- the HTTP method (GET, POST, etc.)
requestEntity
- the entity (headers and/or body) to write to the request, may
be
null
responseType
- the type of the return value
RestTemplate.exchange(java.net.URI, org.springframework.http.HttpMethod, org.springframework.http.HttpEntity, org.springframework.core.ParameterizedTypeReference)
RequestEntity
and return the
response as
ResponseEntity
. Typically used in combination with the static
builder methods on
RequestEntity
, for instance:
MyRequest body = ... RequestEntity request = RequestEntity.post(new URI("https://example.com/foo")).accept(MediaType.APPLICATION_JSON).body(body); ResponseEntity<MyResponse> response = template.exchange(request, MyResponse.class);
T
- the type of the return valuerequestEntity
- the entity to write to the requestresponseType
- the type of the return valueRestTemplate.exchange(org.springframework.http.RequestEntity, java.lang.Class)
RequestEntity
and return the
response as ResponseEntity
. The given ParameterizedTypeReference
is
used to pass generic type information: MyRequest body = ... RequestEntity request = RequestEntity.post(new URI("https://example.com/foo")).accept(MediaType.APPLICATION_JSON).body(body); ParameterizedTypeReference<List<MyResponse>> myBean = new ParameterizedTypeReference<List<MyResponse>>() {}; ResponseEntity<List<MyResponse>> response = template.exchange(request, myBean);
T
- the type of the return valuerequestEntity
- the entity to write to the requestresponseType
- the type of the return valueRestTemplate.exchange(org.springframework.http.RequestEntity, org.springframework.core.ParameterizedTypeReference)
RequestCallback
, and reading the response with a ResponseExtractor
.
URI Template variables are expanded using the given URI variables, if any.T
- the type of the return valueurl
- the URLmethod
- the HTTP method (GET, POST, etc.)requestCallback
- object that prepares the requestresponseExtractor
- object that extracts the return value from the responseurlVariables
- the variables to expand in the templateResponseExtractor
RestTemplate.execute(java.lang.String, org.springframework.http.HttpMethod, org.springframework.web.client.RequestCallback, org.springframework.web.client.ResponseExtractor, java.lang.Object[])
RequestCallback
, and reading the response with a ResponseExtractor
.
URI Template variables are expanded using the given URI variables map.T
- the type of the return valueurl
- the URLmethod
- the HTTP method (GET, POST, etc.)requestCallback
- object that prepares the requestresponseExtractor
- object that extracts the return value from the responseurlVariables
- the variables to expand in the templateResponseExtractor
RestTemplate.execute(java.lang.String, org.springframework.http.HttpMethod, org.springframework.web.client.RequestCallback, org.springframework.web.client.ResponseExtractor, java.util.Map)
RequestCallback
, and reading the response with a ResponseExtractor
.T
- the type of the return valueurl
- the URLmethod
- the HTTP method (GET, POST, etc.)requestCallback
- object that prepares the requestresponseExtractor
- object that extracts the return value from the responseResponseExtractor
RestTemplate.execute(java.net.URI, org.springframework.http.HttpMethod, org.springframework.web.client.RequestCallback, org.springframework.web.client.ResponseExtractor)
RestTemplate
that is actually used to perform the
REST operations.TestRestTemplate
with the same configuration as this one,
except that it will send basic authorization headers using the given
username
and password
. The request factory used is a new instance
of the underlying RestTemplate
's request factory type (when possible).username
- the usernamepassword
- the password沉稳的打火机 · YOLO内卷时期该如何选模型? 5 月前 |
打酱油的帽子 · anaconda安装perl-火山引擎 1 年前 |
苦闷的手术刀 · 并列不等高块状元素保持高度一致 - 掘金 1 年前 |