org.springframework.http.client.InterceptingClientHttpRequestFactory Java Examples
The following examples show how to use
org.springframework.http.client.InterceptingClientHttpRequestFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FormLoginAuthenticationCsrfTokenInterceptor.java From mojito with Apache License 2.0 | 6 votes |
/** * Init */ @PostConstruct protected void init() { restTemplateForAuthenticationFlow = new CookieStoreRestTemplate(); cookieStore = restTemplateForAuthenticationFlow.getCookieStore(); logger.debug("Inject cookie store used in the rest template for authentication flow into the authRestTemplate so that they will match"); authRestTemplate.restTemplate.setCookieStoreAndUpdateRequestFactory(cookieStore); List<ClientHttpRequestInterceptor> interceptors = Collections .<ClientHttpRequestInterceptor>singletonList(new ClientHttpRequestInterceptor() { @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { if (latestCsrfToken != null) { // At the beginning of auth flow, there's no token yet injectCsrfTokenIntoHeader(request, latestCsrfToken); } return execution.execute(request, body); } }); restTemplateForAuthenticationFlow.setRequestFactory(new InterceptingClientHttpRequestFactory(restTemplateForAuthenticationFlow.getRequestFactory(), interceptors)); }
Example #2
Source File: InterceptingHttpAccessor.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public ClientHttpRequestFactory getRequestFactory() { ClientHttpRequestFactory delegate = super.getRequestFactory(); if (!CollectionUtils.isEmpty(getInterceptors())) { return new InterceptingClientHttpRequestFactory(delegate, getInterceptors()); } else { return delegate; } }
Example #3
Source File: InterceptingHttpAccessor.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public ClientHttpRequestFactory getRequestFactory() { ClientHttpRequestFactory delegate = super.getRequestFactory(); if (!CollectionUtils.isEmpty(getInterceptors())) { return new InterceptingClientHttpRequestFactory(delegate, getInterceptors()); } else { return delegate; } }
Example #4
Source File: AuthenticatedRestTemplate.java From mojito with Apache License 2.0 | 5 votes |
/** * Initialize the internal restTemplate instance */ @PostConstruct protected void init() { logger.debug("Create the RestTemplate instance that will be wrapped"); makeRestTemplateWithCustomObjectMapper(restTemplate); setErrorHandlerWithLogging(restTemplate); logger.debug("Set interceptor for authentication"); List<ClientHttpRequestInterceptor> interceptors = Collections .<ClientHttpRequestInterceptor>singletonList(formLoginAuthenticationCsrfTokenInterceptor); restTemplate.setRequestFactory(new InterceptingClientHttpRequestFactory(restTemplate.getRequestFactory(), interceptors)); }