Example usage for org.springframework.http.client HttpComponentsClientHttpRequestFactory getHttpClient

List of usage examples for org.springframework.http.client HttpComponentsClientHttpRequestFactory getHttpClient

Introduction

In this page you can find the example usage for org.springframework.http.client HttpComponentsClientHttpRequestFactory getHttpClient.

Prototype

public HttpClient getHttpClient() 

Source Link

Document

Return the HttpClient used for #createRequest(URI,HttpMethod) synchronous execution .

Usage

From source file:com.jskj.asset.client.login.LoginTask.java

@Override
protected Object doInBackground() throws Exception {
    try {//from   w w  w . j  a  va 2s . c  om
        RestTemplate restTemplate = (RestTemplate) BeanFactory.instance().createBean(RestTemplate.class);

        if (logined) {
            ComResponse<String> com = restTemplate.getForObject(
                    java.net.URI.create(Constants.HTTP + Constants.APPID + "logout"), ComResponse.class);
            if (com.getResponseStatus() != ComResponse.STATUS_OK) {
                return new Exception("logout failed. ");
            } else {
                BaseTreePane.disTabCount.clear();
            }
        }

        Object userNameObj = map.get("userName");
        ;
        Object passwdObj = map.get("userPassword");

        HttpComponentsClientHttpRequestFactory httpRequestFactory = (HttpComponentsClientHttpRequestFactory) restTemplate
                .getRequestFactory();
        DefaultHttpClient httpClient = (DefaultHttpClient) httpRequestFactory.getHttpClient();
        String unicodeStr = UnicodeConverter.toEncodedUnicode(userNameObj.toString(), false);
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(unicodeStr,
                passwdObj.toString());
        httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);

        UserSessionEntity session = restTemplate.getForObject(java.net.URI.create(URI),
                UserSessionEntity.class);

        return session;
    } catch (Exception e) {
        e.printStackTrace();
        return e;
    }
}

From source file:org.openflamingo.web.util.RestTemplateFactoryBean.java

@Override
public void afterPropertiesSet() throws Exception {
    HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
    factory.setReadTimeout(readTimeout);
    factory.setConnectTimeout(connectTimeout);

    if (!StringUtils.isEmpty(proxyHost) && !StringUtils.isEmpty(proxyPort)) {
        HttpHost proxy = new HttpHost(proxyHost, Integer.parseInt(proxyPort), "http");
        factory.getHttpClient().getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }/*from   www  .  j  av  a 2s  .  c om*/

    this.restTemplate = new RestTemplate(factory);
    this.restTemplate.setMessageConverters(messageConverters);
}