Example usage for org.springframework.remoting.httpinvoker HttpComponentsHttpInvokerRequestExecutor getHttpClient

List of usage examples for org.springframework.remoting.httpinvoker HttpComponentsHttpInvokerRequestExecutor getHttpClient

Introduction

In this page you can find the example usage for org.springframework.remoting.httpinvoker HttpComponentsHttpInvokerRequestExecutor getHttpClient.

Prototype

public HttpClient getHttpClient() 

Source Link

Document

Return the HttpClient instance that this request executor uses.

Usage

From source file:org.valkyriercp.security.remoting.BasicAuthCommonsHttpInvokerProxyFactoryBean.java

/**
 * Handle a change in the current authentication token.
 * This method will fail fast if the executor isn't a CommonsHttpInvokerRequestExecutor.
 * @see org.valkyriercp.security.AuthenticationAware#setAuthenticationToken(org.springframework.security.core.Authentication)
 *//*from w  ww .  j  av  a  2 s .  co  m*/
public void setAuthenticationToken(Authentication authentication) {
    if (logger.isDebugEnabled()) {
        logger.debug("New authentication token: " + authentication);
    }

    HttpComponentsHttpInvokerRequestExecutor executor = (HttpComponentsHttpInvokerRequestExecutor) getHttpInvokerRequestExecutor();
    DefaultHttpClient httpClient = (DefaultHttpClient) executor.getHttpClient();
    BasicCredentialsProvider provider = new BasicCredentialsProvider();
    httpClient.setCredentialsProvider(provider);
    httpClient.addRequestInterceptor(new PreemptiveAuthInterceptor());
    UsernamePasswordCredentials usernamePasswordCredentials;
    if (authentication != null) {
        usernamePasswordCredentials = new UsernamePasswordCredentials(authentication.getName(),
                authentication.getCredentials().toString());
    } else {
        usernamePasswordCredentials = null;
    }
    provider.setCredentials(AuthScope.ANY, usernamePasswordCredentials);
}