/** * Set the error handler. * <p>By default, AsyncRestTemplate uses a * {@link org.springframework.web.client.DefaultResponseErrorHandler}. */ public void setErrorHandler(ResponseErrorHandler errorHandler) { this.syncTemplate.setErrorHandler(errorHandler); }
/** * Set the error handler. * <p>By default, AsyncRestTemplate uses a * {@link org.springframework.web.client.DefaultResponseErrorHandler}. */ public void setErrorHandler(ResponseErrorHandler errorHandler) { this.syncTemplate.setErrorHandler(errorHandler); }
public RemoteTokenServices() { restTemplate = new RestTemplate(); ((RestTemplate) restTemplate).setErrorHandler(new DefaultResponseErrorHandler() { @Override // Ignore 400 public void handleError(ClientHttpResponse response) throws IOException { if (response.getRawStatusCode() != 400) { super.handleError(response); } } }); }
public RemoteTokenServices() { restTemplate = new RestTemplate(); ((RestTemplate) restTemplate).setErrorHandler(new DefaultResponseErrorHandler() { @Override // Ignore 400 public void handleError(ClientHttpResponse response) throws IOException { if (response.getRawStatusCode() != 400) { super.handleError(response); } } }); }
public DefaultOAuth2UserService() { RestTemplate restTemplate = new RestTemplate(); restTemplate.setErrorHandler(new OAuth2ErrorResponseErrorHandler()); this.restOperations = restTemplate; }
@Override public void setErrorHandler(ResponseErrorHandler errorHandler) { if (!(errorHandler instanceof OAuth2ErrorHandler)) { errorHandler = new OAuth2ErrorHandler(errorHandler, resource); } super.setErrorHandler(errorHandler); }
/** * Constructs a {@code CustomUserTypesOAuth2UserService} using the provided parameters. * * @param customUserTypes a {@code Map} of {@link OAuth2User} type(s) keyed by {@link ClientRegistration#getRegistrationId() Registration Id} */ public CustomUserTypesOAuth2UserService(Map<String, Class<? extends OAuth2User>> customUserTypes) { Assert.notEmpty(customUserTypes, "customUserTypes cannot be empty"); this.customUserTypes = Collections.unmodifiableMap(new LinkedHashMap<>(customUserTypes)); RestTemplate restTemplate = new RestTemplate(); restTemplate.setErrorHandler(new OAuth2ErrorResponseErrorHandler()); this.restOperations = restTemplate; }
@LoadBalanced @Bean public RestTemplate restTemplate() { final RestTemplate template = new RestTemplate(); template.setErrorHandler(new TccResponseErrorHandler()); return template; }
public RestAuthenticationManager() { RestTemplate restTemplate = new RestTemplate(); // The default java.net client doesn't allow you to handle 4xx responses restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory()); restTemplate.setErrorHandler(new DefaultResponseErrorHandler() { @Override protected boolean hasError(HttpStatus statusCode) { return statusCode.series() == HttpStatus.Series.SERVER_ERROR; } }); this.restTemplate = restTemplate; }
@Bean public RestTemplateCustomizer testRestTemplateCustomizer() { return (b) -> b.setErrorHandler(errorHandler); }
@Test public void handlingError() throws Exception { RestTemplate restTemplate = new RestTemplate(); restTemplate.setErrorHandler(NO_OP_ERROR_HANDLER); URI url = new URI("http://localhost:" + port + "/handling-error"); ResponseEntity<String> response = restTemplate.getForEntity(url, String.class); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); }
@Test public void responseBodyError() throws Exception { RestTemplate restTemplate = new RestTemplate(); restTemplate.setErrorHandler(NO_OP_ERROR_HANDLER); URI url = new URI("http://localhost:" + port + "/response-body-error"); ResponseEntity<String> response = restTemplate.getForEntity(url, String.class); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); }
@Test // SPR-15560 public void emptyPathSegments() throws Exception { RestTemplate restTemplate = new RestTemplate(); restTemplate.setErrorHandler(NO_OP_ERROR_HANDLER); URI url = new URI("http://localhost:" + port + "//"); ResponseEntity<String> response = restTemplate.getForEntity(url, String.class); assertEquals(HttpStatus.OK, response.getStatusCode()); }
public DefaultAuthorizationCodeTokenResponseClient() { RestTemplate restTemplate = new RestTemplate(Arrays.asList( new FormHttpMessageConverter(), new OAuth2AccessTokenResponseHttpMessageConverter())); restTemplate.setErrorHandler(new OAuth2ErrorResponseErrorHandler()); this.restOperations = restTemplate; }
public DefaultClientCredentialsTokenResponseClient() { RestTemplate restTemplate = new RestTemplate(Arrays.asList( new FormHttpMessageConverter(), new OAuth2AccessTokenResponseHttpMessageConverter())); restTemplate.setErrorHandler(new OAuth2ErrorResponseErrorHandler()); this.restOperations = restTemplate; }
protected RestOperations getRestTemplate() { if (restTemplate == null) { synchronized (this) { if (restTemplate == null) { RestTemplate restTemplate = new RestTemplate(); restTemplate.setErrorHandler(getResponseErrorHandler()); restTemplate.setRequestFactory(requestFactory); restTemplate.setInterceptors(interceptors); this.restTemplate = restTemplate; } } } if (messageConverters == null) { setMessageConverters(new RestTemplate().getMessageConverters()); } return restTemplate; }
@Before public void setup() { requestFactory = mock(ClientHttpRequestFactory.class); request = mock(ClientHttpRequest.class); response = mock(ClientHttpResponse.class); errorHandler = mock(ResponseErrorHandler.class); converter = mock(HttpMessageConverter.class); template = new RestTemplate(Collections.singletonList(converter)); template.setRequestFactory(requestFactory); template.setErrorHandler(errorHandler); }
@Before public void setErrorHandlerOnRestTemplate() { ((RestTemplate)serverRunning.getRestTemplate()).setErrorHandler(new OAuth2ErrorHandler(context.getResource()) { // Pass errors through in response entity for status code analysis @Override public boolean hasError(ClientHttpResponse response) throws IOException { return false; } @Override public void handleError(ClientHttpResponse response) throws IOException { } }); }
@Before public void setUp() throws Exception { ((RestTemplate)serverRunning.getRestTemplate()).setErrorHandler( new UaaOauth2ErrorHandler(context.getResource(), HttpStatus.Series.SERVER_ERROR) ); }
@Before public void createRestTemplate() throws Exception { client = serverRunning.getRestTemplate(); ((RestTemplate)serverRunning.getRestTemplate()).setErrorHandler(new OAuth2ErrorHandler(context.getResource()) { // Pass errors through in response entity for status code analysis @Override public boolean hasError(ClientHttpResponse response) throws IOException { return false; } @Override public void handleError(ClientHttpResponse response) throws IOException { } }); }