Example usage for org.springframework.web.client RestTemplate getRequestFactory

List of usage examples for org.springframework.web.client RestTemplate getRequestFactory

Introduction

In this page you can find the example usage for org.springframework.web.client RestTemplate getRequestFactory.

Prototype

@Override
public ClientHttpRequestFactory getRequestFactory() 

Source Link

Document

Overridden to expose an InterceptingClientHttpRequestFactory if necessary.

Usage

From source file:edu.mayo.cts2.framework.core.client.Cts2RestClient.java

/**
 * Creates the rest template./*w  ww .j a  v a 2  s .  c om*/
 *
 * @param username the username
 * @param password the password
 * @return the rest template
 */
protected RestTemplate createRestTemplate(String username, String password) {
    RestTemplate restTemplate;
    if (username != null && password != null) {
        restTemplate = new FixedRestTemplate(this.createSecureTransport(username, password));
    } else {
        restTemplate = new FixedRestTemplate();
    }

    SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
    rf.setConnectTimeout(connectTimeoutMS);
    rf.setReadTimeout(readTimeoutMS);

    List<HttpMessageConverter<?>> list = new ArrayList<HttpMessageConverter<?>>();

    list.add(converter);

    restTemplate.setMessageConverters(list);

    return restTemplate;
}

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

@Override
protected Object doInBackground() throws Exception {
    try {//  w  w  w .j  a v  a  2  s. 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.cloudfoundry.client.lib.rest.CloudControllerClientImpl.java

protected void configureCloudFoundryRequestFactory(RestTemplate restTemplate) {
    ClientHttpRequestFactory requestFactory = restTemplate.getRequestFactory();
    if (!(requestFactory instanceof CloudFoundryClientHttpRequestFactory)) {
        restTemplate.setRequestFactory(new CloudFoundryClientHttpRequestFactory(requestFactory));
    }/*from  www.j a  v a 2  s . c o  m*/
}

From source file:org.openpaas.paasta.portal.api.common.CustomCloudControllerClientImpl.java

protected void configureCloudFoundryRequestFactory(RestTemplate restTemplate) {
    ClientHttpRequestFactory requestFactory = restTemplate.getRequestFactory();
    if (!(requestFactory instanceof CustomCloudControllerClientImpl.CloudFoundryClientHttpRequestFactory)) {
        restTemplate.setRequestFactory(//from  w w  w .j  a v  a2  s. com
                new CustomCloudControllerClientImpl.CloudFoundryClientHttpRequestFactory(requestFactory));
    }
}