类org.springframework.http.client.InterceptingClientHttpRequestFactory源码实例Demo

下面列出了怎么用org.springframework.http.client.InterceptingClientHttpRequestFactory的API类实例代码及写法,或者点击链接到github查看源代码。

/**
 * 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));
}
 
源代码2 项目: lams   文件: InterceptingHttpAccessor.java
@Override
public ClientHttpRequestFactory getRequestFactory() {
	ClientHttpRequestFactory delegate = super.getRequestFactory();
	if (!CollectionUtils.isEmpty(getInterceptors())) {
		return new InterceptingClientHttpRequestFactory(delegate, getInterceptors());
	}
	else {
		return delegate;
	}
}
 
@Override
public ClientHttpRequestFactory getRequestFactory() {
	ClientHttpRequestFactory delegate = super.getRequestFactory();
	if (!CollectionUtils.isEmpty(getInterceptors())) {
		return new InterceptingClientHttpRequestFactory(delegate, getInterceptors());
	}
	else {
		return delegate;
	}
}
 
源代码4 项目: mojito   文件: AuthenticatedRestTemplate.java
/**
 * 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));
}
 
 类所在包
 类方法
 同包方法