本文整理了Java中org.springframework.web.client.RestTemplate.getErrorHandler
方法的一些代码示例,展示了RestTemplate.getErrorHandler
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RestTemplate.getErrorHandler
方法的具体详情如下:
包路径:org.springframework.web.client.RestTemplate
类名称:RestTemplate
方法名:getErrorHandler
[英]Return the error handler.
[中]返回错误处理程序。
代码示例来源:origin: spring-projects/spring-framework
/**
* Return the error handler.
*/
public ResponseErrorHandler getErrorHandler() {
return this.syncTemplate.getErrorHandler();
}
代码示例来源:origin: org.springframework/spring-web
/**
* Return the error handler.
*/
public ResponseErrorHandler getErrorHandler() {
return this.syncTemplate.getErrorHandler();
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Handle the given response, performing appropriate logging and
* invoking the {@link ResponseErrorHandler} if necessary.
* <p>Can be overridden in subclasses.
* @param url the fully-expanded URL to connect to
* @param method the HTTP method to execute (GET, POST, etc.)
* @param response the resulting {@link ClientHttpResponse}
* @throws IOException if propagated from {@link ResponseErrorHandler}
* @since 4.1.6
* @see #setErrorHandler
*/
protected void handleResponse(URI url, HttpMethod method, ClientHttpResponse response) throws IOException {
ResponseErrorHandler errorHandler = getErrorHandler();
boolean hasError = errorHandler.hasError(response);
if (logger.isDebugEnabled()) {
try {
int code = response.getRawStatusCode();
HttpStatus status = HttpStatus.resolve(code);
logger.debug("Response " + (status != null ? status : code));
}
catch (IOException ex) {
// ignore
}
}
if (hasError) {
errorHandler.handleError(url, method, response);
}
}
代码示例来源:origin: org.springframework/spring-web
/**
* Handle the given response, performing appropriate logging and
* invoking the {@link ResponseErrorHandler} if necessary.
* <p>Can be overridden in subclasses.
* @param url the fully-expanded URL to connect to
* @param method the HTTP method to execute (GET, POST, etc.)
* @param response the resulting {@link ClientHttpResponse}
* @throws IOException if propagated from {@link ResponseErrorHandler}
* @since 4.1.6
* @see #setErrorHandler
*/
protected void handleResponse(URI url, HttpMethod method, ClientHttpResponse response) throws IOException {
ResponseErrorHandler errorHandler = getErrorHandler();
boolean hasError = errorHandler.hasError(response);
if (logger.isDebugEnabled()) {
try {
int code = response.getRawStatusCode();
HttpStatus status = HttpStatus.resolve(code);
logger.debug("Response " + (status != null ? status : code));
}
catch (IOException ex) {
// ignore
}
}
if (hasError) {
errorHandler.handleError(url, method, response);
}
}
代码示例来源:origin: spring-io/initializr
@Test
void customRestTemplateBuilderIsUsed() {
this.contextRunner.withUserConfiguration(CustomRestTemplateConfiguration.class)
.run((context) -> {
assertThat(context).hasSingleBean(InitializrMetadataProvider.class);
RestTemplate restTemplate = (RestTemplate) new DirectFieldAccessor(
context.getBean(InitializrMetadataProvider.class))
.getPropertyValue("restTemplate");
assertThat(restTemplate.getErrorHandler())
.isSameAs(CustomRestTemplateConfiguration.errorHandler);
});
}
代码示例来源:origin: Nepxion/Discovery
public static String getCause(RestTemplate restTemplate) {
ResponseErrorHandler responseErrorHandler = restTemplate.getErrorHandler();
if (responseErrorHandler instanceof RestErrorHandler) {
RestErrorHandler errorHandler = (RestErrorHandler) responseErrorHandler;
return errorHandler.getCause();
}
return null;
}
}
代码示例来源:origin: briandilley/jsonrpc4j
/**
* Check RestTemplate contains required converters
*/
private void initRestTemplate() {
boolean isContainsConverter = false;
for (HttpMessageConverter<?> httpMessageConverter : this.restTemplate.getMessageConverters()) {
if (MappingJacksonRPC2HttpMessageConverter.class.isAssignableFrom(httpMessageConverter.getClass())) {
isContainsConverter = true;
break;
}
}
if (!isContainsConverter) {
final MappingJacksonRPC2HttpMessageConverter messageConverter = new MappingJacksonRPC2HttpMessageConverter();
messageConverter.setObjectMapper(this.getObjectMapper());
final List<HttpMessageConverter<?>> restMessageConverters = new ArrayList<>();
restMessageConverters.addAll(this.restTemplate.getMessageConverters());
// Place JSON-RPC converter on the first place!
restMessageConverters.add(0, messageConverter);
this.restTemplate.setMessageConverters(restMessageConverters);
}
// use specific JSON-RPC error handler if it has not been changed to custom
if (restTemplate.getErrorHandler() instanceof org.springframework.web.client.DefaultResponseErrorHandler) {
restTemplate.setErrorHandler(JsonRpcResponseErrorHandler.INSTANCE);
}
}
代码示例来源:origin: apache/servicemix-bundles
/**
* Return the error handler.
*/
public ResponseErrorHandler getErrorHandler() {
return this.syncTemplate.getErrorHandler();
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-web
/**
* Return the error handler.
*/
public ResponseErrorHandler getErrorHandler() {
return this.syncTemplate.getErrorHandler();
}
代码示例来源:origin: FastBootWeixin/FastBootWeixin
public ResponseErrorHandler getErrorHandler() {
return restTemplate.getErrorHandler();
}
代码示例来源:origin: com.nepxion/discovery-common
public static String getCause(RestTemplate restTemplate) {
ResponseErrorHandler responseErrorHandler = restTemplate.getErrorHandler();
if (responseErrorHandler instanceof RestErrorHandler) {
RestErrorHandler errorHandler = (RestErrorHandler) responseErrorHandler;
return errorHandler.getCause();
}
return null;
}
}
代码示例来源:origin: org.springframework.data/spring-data-riak
public boolean getIgnoreNotFound() {
return (getRestTemplate().getErrorHandler() instanceof Ignore404sErrorHandler);
}
代码示例来源:origin: org.springframework.android/spring-android-rest-template
private void handleResponseError(HttpMethod method, URI url, ClientHttpResponse response) throws IOException {
if (Log.isLoggable(TAG, Log.WARN)) {
try {
Log.w(TAG,
method.name() + " request for \"" + url + "\" resulted in " + response.getStatusCode() + " (" +
response.getStatusText() + "); invoking error handler");
}
catch (IOException e) {
// ignore
}
}
getErrorHandler().handleError(response);
}
代码示例来源:origin: guru.nidi.raml/raml-tester
private void init(RestTemplate restTemplate) {
setErrorHandler(restTemplate.getErrorHandler());
setMessageConverters(restTemplate.getMessageConverters());
}
代码示例来源:origin: nidi3/raml-tester
private void init(RestTemplate restTemplate) {
setErrorHandler(restTemplate.getErrorHandler());
setMessageConverters(restTemplate.getMessageConverters());
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-web
/**
* Handle the given response, performing appropriate logging and
* invoking the {@link ResponseErrorHandler} if necessary.
* <p>Can be overridden in subclasses.
* @param url the fully-expanded URL to connect to
* @param method the HTTP method to execute (GET, POST, etc.)
* @param response the resulting {@link ClientHttpResponse}
* @throws IOException if propagated from {@link ResponseErrorHandler}
* @since 4.1.6
* @see #setErrorHandler
*/
protected void handleResponse(URI url, HttpMethod method, ClientHttpResponse response) throws IOException {
ResponseErrorHandler errorHandler = getErrorHandler();
boolean hasError = errorHandler.hasError(response);
if (logger.isDebugEnabled()) {
try {
int code = response.getRawStatusCode();
HttpStatus status = HttpStatus.resolve(code);
logger.debug("Response " + (status != null ? status : code));
}
catch (IOException ex) {
// ignore
}
}
if (hasError) {
errorHandler.handleError(url, method, response);
}
}
代码示例来源:origin: apache/servicemix-bundles
/**
* Handle the given response, performing appropriate logging and
* invoking the {@link ResponseErrorHandler} if necessary.
* <p>Can be overridden in subclasses.
* @param url the fully-expanded URL to connect to
* @param method the HTTP method to execute (GET, POST, etc.)
* @param response the resulting {@link ClientHttpResponse}
* @throws IOException if propagated from {@link ResponseErrorHandler}
* @since 4.1.6
* @see #setErrorHandler
*/
protected void handleResponse(URI url, HttpMethod method, ClientHttpResponse response) throws IOException {
ResponseErrorHandler errorHandler = getErrorHandler();
boolean hasError = errorHandler.hasError(response);
if (logger.isDebugEnabled()) {
try {
logger.debug(method.name() + " request for \"" + url + "\" resulted in " +
response.getRawStatusCode() + " (" + response.getStatusText() + ")" +
(hasError ? "; invoking error handler" : ""));
}
catch (IOException ex) {
// ignore
}
}
if (hasError) {
errorHandler.handleError(url, method, response);
}
}
代码示例来源:origin: pl.edu.icm.synat/synat-platform-connector
private void initTransfer(final long firstByteInRange) throws IOException {
final ClientHttpRequest request = restTemplate.getRequestFactory().createRequest(uri, HttpMethod.GET);
if (firstByteInRange > 0) {
request.getHeaders().add("Range", "bytes:" + firstByteInRange + "-");
}
final ClientHttpResponse response = request.execute();
if (restTemplate.getErrorHandler().hasError(response)) {
state = StreamingResourceState.ERROR;
throw new IllegalStateException("Transfer initialization failed, error code " + response.getStatusCode() + ":" + response.getStatusText());
}
state = StreamingResourceState.TRANSFER_IN_PROGRESS;
inputStream = response.getBody();
contentLength = response.getHeaders().getContentLength();
}
代码示例来源:origin: org.springframework.data/spring-data-riak
public void setIgnoreNotFound(boolean b) {
if (b) {
getRestTemplate().setErrorHandler(new Ignore404sErrorHandler());
} else {
if (getRestTemplate().getErrorHandler() instanceof Ignore404sErrorHandler) {
getRestTemplate().setErrorHandler(new DefaultResponseErrorHandler());
}
}
}
代码示例来源:origin: org.springframework.boot/spring-boot-test
/**
* Creates a new {@code TestRestTemplate} with the same configuration as this one,
* except that it will send basic authorization headers using the given
* {@code username} and {@code password}.
* @param username the username
* @param password the password
* @return the new template
* @since 1.4.1
*/
public TestRestTemplate withBasicAuth(String username, String password) {
RestTemplate restTemplate = new RestTemplateBuilder()
.messageConverters(getRestTemplate().getMessageConverters())
.interceptors(getRestTemplate().getInterceptors())
.uriTemplateHandler(getRestTemplate().getUriTemplateHandler()).build();
TestRestTemplate testRestTemplate = new TestRestTemplate(restTemplate, username,
password, this.httpClientOptions);
testRestTemplate.getRestTemplate()
.setErrorHandler(getRestTemplate().getErrorHandler());
return testRestTemplate;
}
内容来源于网络,如有侵权,请联系作者删除!