private RestTemplateBuilder(boolean detectRequestFactory, String rootUri, Set<HttpMessageConverter<?>> messageConverters, ClientHttpRequestFactory requestFactory, UriTemplateHandler uriTemplateHandler, ResponseErrorHandler errorHandler, BasicAuthorizationInterceptor basicAuthorization, Set<RestTemplateCustomizer> restTemplateCustomizers, Set<RequestFactoryCustomizer> requestFactoryCustomizers) { super(); this.detectRequestFactory = detectRequestFactory; this.rootUri = rootUri; this.messageConverters = messageConverters; this.requestFactory = requestFactory; this.uriTemplateHandler = uriTemplateHandler; this.errorHandler = errorHandler; this.basicAuthorization = basicAuthorization; this.restTemplateCustomizers = restTemplateCustomizers; this.requestFactoryCustomizers = requestFactoryCustomizers; }
private RestTemplateBuilder(boolean detectRequestFactory, String rootUri, Set<HttpMessageConverter<?>> messageConverters, ClientHttpRequestFactory requestFactory, UriTemplateHandler uriTemplateHandler, ResponseErrorHandler errorHandler, BasicAuthorizationInterceptor basicAuthorization, Set<RestTemplateCustomizer> customizers) { super(); this.detectRequestFactory = detectRequestFactory; this.rootUri = rootUri; this.messageConverters = messageConverters; this.requestFactory = requestFactory; this.uriTemplateHandler = uriTemplateHandler; this.errorHandler = errorHandler; this.basicAuthorization = basicAuthorization; this.customizers = customizers; }
@Test @OAuth2ContextConfiguration(resource = InvalidClientCredentials.class, initialize = false) public void testInvalidCredentials() throws Exception { context.setAccessTokenProvider(new ClientCredentialsAccessTokenProvider() { @Override protected ResponseErrorHandler getResponseErrorHandler() { return new DefaultResponseErrorHandler() { public void handleError(ClientHttpResponse response) throws IOException { responseHeaders = response.getHeaders(); responseStatus = response.getStatusCode(); } }; } }); try { context.getAccessToken(); fail("Expected ResourceAccessException"); } catch (Exception e) { // ignore } // System.err.println(responseHeaders); String header = responseHeaders.getFirst("WWW-Authenticate"); assertTrue("Wrong header: " + header, header.contains("Basic realm")); assertEquals(HttpStatus.UNAUTHORIZED, responseStatus); }
public void handleError() { // handle error2 RestTemplate client = new RestTemplate(); ResponseErrorHandler responseErrorHandler = new DefaultResponseErrorHandler() { @Override public void handleError(ClientHttpResponse response) throws IOException { LOGGER.warn("response status: '{}', headers: '{}'", response.getStatusCode(), response.getHeaders()); } }; client.setErrorHandler(responseErrorHandler); client.exchange("http://localhost:8080/person/denied", HttpMethod.GET, null, String.class); }
@Test public void setErrorHandlerWithUnderlying() { ResponseErrorHandler errorHandler = mock(ResponseErrorHandler.class); wrapper.setErrorHandler(errorHandler); assertThat(wrapper.getErrorHandler(), is(errorHandler)); assertThat(wrapper.defaultRestTemplate.getErrorHandler(), is(errorHandler)); verify(underlying).setErrorHandler(errorHandler); }
private RestOperations buildOAuth2RestTemplate(final String tokenName, final ResponseErrorHandler errorHandler) { final RestTemplate restTemplate = new StupsOAuth2RestTemplate( new StupsTokensAccessTokenProvider(tokenName, accessTokens), new HttpComponentsClientHttpRequestFactory()); if (errorHandler != null) { restTemplate.setErrorHandler(errorHandler); } return restTemplate; }
@Test @OAuth2ContextConfiguration(resource = InvalidClientCredentials.class, initialize = false) public void testInvalidCredentialsWithFormAuthentication() throws Exception { resource.setClientAuthenticationScheme(AuthenticationScheme.form); context.setAccessTokenProvider(new ClientCredentialsAccessTokenProvider() { @Override protected ResponseErrorHandler getResponseErrorHandler() { return new DefaultResponseErrorHandler() { public void handleError(ClientHttpResponse response) throws IOException { responseHeaders = response.getHeaders(); responseStatus = response.getStatusCode(); } }; } }); try { context.getAccessToken(); fail("Expected ResourceAccessException"); } catch (Exception e) { // ignore } // System.err.println(responseHeaders); String header = responseHeaders.getFirst("WWW-Authenticate"); assertTrue("Wrong header: " + header, header.contains("Form realm")); assertEquals(HttpStatus.UNAUTHORIZED, responseStatus); }
public GaeRestTemplate(Type responseType, ResponseErrorHandler errorHandler, List<ClientHttpRequestInterceptor> interceptors) { this.setErrorHandler(errorHandler); this.setInterceptors(interceptors); final GsonHttpMessageConverter converter = new GsonHttpMessageConverter(); if (responseType != null) { converter.setType(responseType); } this.setMessageConverters(Collections.<HttpMessageConverter<?>>singletonList(converter)); }
@Override public void setErrorHandler(ResponseErrorHandler errorHandler) { super.setErrorHandler(errorHandler); acceptableRestTemplates.forEach(template -> template.setErrorHandler(errorHandler)); defaultRestTemplate.setErrorHandler(errorHandler); }
@Override public void setResponseErrorHandler(ResponseErrorHandler errorHandler) { this.restTemplate.setErrorHandler(errorHandler); }
@Override public void setResponseErrorHandler(ResponseErrorHandler errorHandler) { cc.setResponseErrorHandler(errorHandler); }
@Override public void setResponseErrorHandler(ResponseErrorHandler errorHandler) { }
public DefaultRestTemplateFactoryImpl(ResponseErrorHandler errorHandler) { this.errorHandler = errorHandler; }
@Test public void errorHandlerShouldApply() throws Exception { ResponseErrorHandler errorHandler = mock(ResponseErrorHandler.class); RestTemplate template = this.builder.errorHandler(errorHandler).build(); assertThat(template.getErrorHandler()).isSameAs(errorHandler); }
protected ResponseErrorHandler errorHandler() { return new DefaultResponseErrorHandler(); }
public RestOperations getRestOperations(ResponseErrorHandler responseErrorHandler) { return restOperations; }
@Override protected ResponseErrorHandler getResponseErrorHandler() { return super.getResponseErrorHandler(); }
protected ResponseErrorHandler getResponseErrorHandler() { return responseErrorHandler; }
private ResponseErrorHandler errorHandler() { return new BitcoindJsonRpcErrorHandler(); }
MyClientHttpRequestInterceptor(Context context, ResponseErrorHandler errorHandler) { this.errorHandler = errorHandler; this.pref = context.getSharedPreferences(Utils.PREF_NAME, 0); this.cookie = this.pref.getString(Utils.PREF_COOKIE, null); }
/** * Override the default REST response error handler with a custom error handler. * * @param errorHandler */ void setResponseErrorHandler(ResponseErrorHandler errorHandler);
/** * Construct an error handler that can deal with OAuth2 concerns before delegating to acustom handler. * * @param errorHandler a delegate handler */ public OAuth2ErrorHandler(ResponseErrorHandler errorHandler, OAuth2ProtectedResourceDetails resource) { this.resource = resource; this.errorHandler = errorHandler; }
void setResponseErrorHandler(ResponseErrorHandler errorHandler);