org.springframework.web.client.RestTemplate.getErrorHandler()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(198)

本文整理了Java中org.springframework.web.client.RestTemplate.getErrorHandler方法的一些代码示例,展示了RestTemplate.getErrorHandler的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RestTemplate.getErrorHandler方法的具体详情如下:
包路径:org.springframework.web.client.RestTemplate
类名称:RestTemplate
方法名:getErrorHandler

RestTemplate.getErrorHandler介绍

[英]Return the error handler.
[中]返回错误处理程序。

代码示例

代码示例来源:origin: spring-projects/spring-framework

  1. /**
  2. * Return the error handler.
  3. */
  4. public ResponseErrorHandler getErrorHandler() {
  5. return this.syncTemplate.getErrorHandler();
  6. }

代码示例来源:origin: org.springframework/spring-web

  1. /**
  2. * Return the error handler.
  3. */
  4. public ResponseErrorHandler getErrorHandler() {
  5. return this.syncTemplate.getErrorHandler();
  6. }

代码示例来源:origin: spring-projects/spring-framework

  1. /**
  2. * Handle the given response, performing appropriate logging and
  3. * invoking the {@link ResponseErrorHandler} if necessary.
  4. * <p>Can be overridden in subclasses.
  5. * @param url the fully-expanded URL to connect to
  6. * @param method the HTTP method to execute (GET, POST, etc.)
  7. * @param response the resulting {@link ClientHttpResponse}
  8. * @throws IOException if propagated from {@link ResponseErrorHandler}
  9. * @since 4.1.6
  10. * @see #setErrorHandler
  11. */
  12. protected void handleResponse(URI url, HttpMethod method, ClientHttpResponse response) throws IOException {
  13. ResponseErrorHandler errorHandler = getErrorHandler();
  14. boolean hasError = errorHandler.hasError(response);
  15. if (logger.isDebugEnabled()) {
  16. try {
  17. int code = response.getRawStatusCode();
  18. HttpStatus status = HttpStatus.resolve(code);
  19. logger.debug("Response " + (status != null ? status : code));
  20. }
  21. catch (IOException ex) {
  22. // ignore
  23. }
  24. }
  25. if (hasError) {
  26. errorHandler.handleError(url, method, response);
  27. }
  28. }

代码示例来源:origin: org.springframework/spring-web

  1. /**
  2. * Handle the given response, performing appropriate logging and
  3. * invoking the {@link ResponseErrorHandler} if necessary.
  4. * <p>Can be overridden in subclasses.
  5. * @param url the fully-expanded URL to connect to
  6. * @param method the HTTP method to execute (GET, POST, etc.)
  7. * @param response the resulting {@link ClientHttpResponse}
  8. * @throws IOException if propagated from {@link ResponseErrorHandler}
  9. * @since 4.1.6
  10. * @see #setErrorHandler
  11. */
  12. protected void handleResponse(URI url, HttpMethod method, ClientHttpResponse response) throws IOException {
  13. ResponseErrorHandler errorHandler = getErrorHandler();
  14. boolean hasError = errorHandler.hasError(response);
  15. if (logger.isDebugEnabled()) {
  16. try {
  17. int code = response.getRawStatusCode();
  18. HttpStatus status = HttpStatus.resolve(code);
  19. logger.debug("Response " + (status != null ? status : code));
  20. }
  21. catch (IOException ex) {
  22. // ignore
  23. }
  24. }
  25. if (hasError) {
  26. errorHandler.handleError(url, method, response);
  27. }
  28. }

代码示例来源:origin: spring-io/initializr

  1. @Test
  2. void customRestTemplateBuilderIsUsed() {
  3. this.contextRunner.withUserConfiguration(CustomRestTemplateConfiguration.class)
  4. .run((context) -> {
  5. assertThat(context).hasSingleBean(InitializrMetadataProvider.class);
  6. RestTemplate restTemplate = (RestTemplate) new DirectFieldAccessor(
  7. context.getBean(InitializrMetadataProvider.class))
  8. .getPropertyValue("restTemplate");
  9. assertThat(restTemplate.getErrorHandler())
  10. .isSameAs(CustomRestTemplateConfiguration.errorHandler);
  11. });
  12. }

代码示例来源:origin: Nepxion/Discovery

  1. public static String getCause(RestTemplate restTemplate) {
  2. ResponseErrorHandler responseErrorHandler = restTemplate.getErrorHandler();
  3. if (responseErrorHandler instanceof RestErrorHandler) {
  4. RestErrorHandler errorHandler = (RestErrorHandler) responseErrorHandler;
  5. return errorHandler.getCause();
  6. }
  7. return null;
  8. }
  9. }

代码示例来源:origin: briandilley/jsonrpc4j

  1. /**
  2. * Check RestTemplate contains required converters
  3. */
  4. private void initRestTemplate() {
  5. boolean isContainsConverter = false;
  6. for (HttpMessageConverter<?> httpMessageConverter : this.restTemplate.getMessageConverters()) {
  7. if (MappingJacksonRPC2HttpMessageConverter.class.isAssignableFrom(httpMessageConverter.getClass())) {
  8. isContainsConverter = true;
  9. break;
  10. }
  11. }
  12. if (!isContainsConverter) {
  13. final MappingJacksonRPC2HttpMessageConverter messageConverter = new MappingJacksonRPC2HttpMessageConverter();
  14. messageConverter.setObjectMapper(this.getObjectMapper());
  15. final List<HttpMessageConverter<?>> restMessageConverters = new ArrayList<>();
  16. restMessageConverters.addAll(this.restTemplate.getMessageConverters());
  17. // Place JSON-RPC converter on the first place!
  18. restMessageConverters.add(0, messageConverter);
  19. this.restTemplate.setMessageConverters(restMessageConverters);
  20. }
  21. // use specific JSON-RPC error handler if it has not been changed to custom
  22. if (restTemplate.getErrorHandler() instanceof org.springframework.web.client.DefaultResponseErrorHandler) {
  23. restTemplate.setErrorHandler(JsonRpcResponseErrorHandler.INSTANCE);
  24. }
  25. }

代码示例来源:origin: apache/servicemix-bundles

  1. /**
  2. * Return the error handler.
  3. */
  4. public ResponseErrorHandler getErrorHandler() {
  5. return this.syncTemplate.getErrorHandler();
  6. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-web

  1. /**
  2. * Return the error handler.
  3. */
  4. public ResponseErrorHandler getErrorHandler() {
  5. return this.syncTemplate.getErrorHandler();
  6. }

代码示例来源:origin: FastBootWeixin/FastBootWeixin

  1. public ResponseErrorHandler getErrorHandler() {
  2. return restTemplate.getErrorHandler();
  3. }

代码示例来源:origin: com.nepxion/discovery-common

  1. public static String getCause(RestTemplate restTemplate) {
  2. ResponseErrorHandler responseErrorHandler = restTemplate.getErrorHandler();
  3. if (responseErrorHandler instanceof RestErrorHandler) {
  4. RestErrorHandler errorHandler = (RestErrorHandler) responseErrorHandler;
  5. return errorHandler.getCause();
  6. }
  7. return null;
  8. }
  9. }

代码示例来源:origin: org.springframework.data/spring-data-riak

  1. public boolean getIgnoreNotFound() {
  2. return (getRestTemplate().getErrorHandler() instanceof Ignore404sErrorHandler);
  3. }

代码示例来源:origin: org.springframework.android/spring-android-rest-template

  1. private void handleResponseError(HttpMethod method, URI url, ClientHttpResponse response) throws IOException {
  2. if (Log.isLoggable(TAG, Log.WARN)) {
  3. try {
  4. Log.w(TAG,
  5. method.name() + " request for \"" + url + "\" resulted in " + response.getStatusCode() + " (" +
  6. response.getStatusText() + "); invoking error handler");
  7. }
  8. catch (IOException e) {
  9. // ignore
  10. }
  11. }
  12. getErrorHandler().handleError(response);
  13. }

代码示例来源:origin: guru.nidi.raml/raml-tester

  1. private void init(RestTemplate restTemplate) {
  2. setErrorHandler(restTemplate.getErrorHandler());
  3. setMessageConverters(restTemplate.getMessageConverters());
  4. }

代码示例来源:origin: nidi3/raml-tester

  1. private void init(RestTemplate restTemplate) {
  2. setErrorHandler(restTemplate.getErrorHandler());
  3. setMessageConverters(restTemplate.getMessageConverters());
  4. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-web

  1. /**
  2. * Handle the given response, performing appropriate logging and
  3. * invoking the {@link ResponseErrorHandler} if necessary.
  4. * <p>Can be overridden in subclasses.
  5. * @param url the fully-expanded URL to connect to
  6. * @param method the HTTP method to execute (GET, POST, etc.)
  7. * @param response the resulting {@link ClientHttpResponse}
  8. * @throws IOException if propagated from {@link ResponseErrorHandler}
  9. * @since 4.1.6
  10. * @see #setErrorHandler
  11. */
  12. protected void handleResponse(URI url, HttpMethod method, ClientHttpResponse response) throws IOException {
  13. ResponseErrorHandler errorHandler = getErrorHandler();
  14. boolean hasError = errorHandler.hasError(response);
  15. if (logger.isDebugEnabled()) {
  16. try {
  17. int code = response.getRawStatusCode();
  18. HttpStatus status = HttpStatus.resolve(code);
  19. logger.debug("Response " + (status != null ? status : code));
  20. }
  21. catch (IOException ex) {
  22. // ignore
  23. }
  24. }
  25. if (hasError) {
  26. errorHandler.handleError(url, method, response);
  27. }
  28. }

代码示例来源:origin: apache/servicemix-bundles

  1. /**
  2. * Handle the given response, performing appropriate logging and
  3. * invoking the {@link ResponseErrorHandler} if necessary.
  4. * <p>Can be overridden in subclasses.
  5. * @param url the fully-expanded URL to connect to
  6. * @param method the HTTP method to execute (GET, POST, etc.)
  7. * @param response the resulting {@link ClientHttpResponse}
  8. * @throws IOException if propagated from {@link ResponseErrorHandler}
  9. * @since 4.1.6
  10. * @see #setErrorHandler
  11. */
  12. protected void handleResponse(URI url, HttpMethod method, ClientHttpResponse response) throws IOException {
  13. ResponseErrorHandler errorHandler = getErrorHandler();
  14. boolean hasError = errorHandler.hasError(response);
  15. if (logger.isDebugEnabled()) {
  16. try {
  17. logger.debug(method.name() + " request for \"" + url + "\" resulted in " +
  18. response.getRawStatusCode() + " (" + response.getStatusText() + ")" +
  19. (hasError ? "; invoking error handler" : ""));
  20. }
  21. catch (IOException ex) {
  22. // ignore
  23. }
  24. }
  25. if (hasError) {
  26. errorHandler.handleError(url, method, response);
  27. }
  28. }

代码示例来源:origin: pl.edu.icm.synat/synat-platform-connector

  1. private void initTransfer(final long firstByteInRange) throws IOException {
  2. final ClientHttpRequest request = restTemplate.getRequestFactory().createRequest(uri, HttpMethod.GET);
  3. if (firstByteInRange > 0) {
  4. request.getHeaders().add("Range", "bytes:" + firstByteInRange + "-");
  5. }
  6. final ClientHttpResponse response = request.execute();
  7. if (restTemplate.getErrorHandler().hasError(response)) {
  8. state = StreamingResourceState.ERROR;
  9. throw new IllegalStateException("Transfer initialization failed, error code " + response.getStatusCode() + ":" + response.getStatusText());
  10. }
  11. state = StreamingResourceState.TRANSFER_IN_PROGRESS;
  12. inputStream = response.getBody();
  13. contentLength = response.getHeaders().getContentLength();
  14. }

代码示例来源:origin: org.springframework.data/spring-data-riak

  1. public void setIgnoreNotFound(boolean b) {
  2. if (b) {
  3. getRestTemplate().setErrorHandler(new Ignore404sErrorHandler());
  4. } else {
  5. if (getRestTemplate().getErrorHandler() instanceof Ignore404sErrorHandler) {
  6. getRestTemplate().setErrorHandler(new DefaultResponseErrorHandler());
  7. }
  8. }
  9. }

代码示例来源:origin: org.springframework.boot/spring-boot-test

  1. /**
  2. * Creates a new {@code TestRestTemplate} with the same configuration as this one,
  3. * except that it will send basic authorization headers using the given
  4. * {@code username} and {@code password}.
  5. * @param username the username
  6. * @param password the password
  7. * @return the new template
  8. * @since 1.4.1
  9. */
  10. public TestRestTemplate withBasicAuth(String username, String password) {
  11. RestTemplate restTemplate = new RestTemplateBuilder()
  12. .messageConverters(getRestTemplate().getMessageConverters())
  13. .interceptors(getRestTemplate().getInterceptors())
  14. .uriTemplateHandler(getRestTemplate().getUriTemplateHandler()).build();
  15. TestRestTemplate testRestTemplate = new TestRestTemplate(restTemplate, username,
  16. password, this.httpClientOptions);
  17. testRestTemplate.getRestTemplate()
  18. .setErrorHandler(getRestTemplate().getErrorHandler());
  19. return testRestTemplate;
  20. }

相关文章