Search in sources :

Example 1 with TransportClientProperties

use of org.apache.axis.components.net.TransportClientProperties in project tdi-studio-se by Talend.

the class ExchangeUtils method sendGetRequest.

public static String sendGetRequest(String urlAddress) throws Exception {
    HttpClient httpclient = new HttpClient();
    GetMethod getMethod = new GetMethod(urlAddress);
    TransportClientProperties tcp = TransportClientPropertiesFactory.create("http");
    if (tcp.getProxyHost().length() != 0) {
        UsernamePasswordCredentials creds = new UsernamePasswordCredentials(tcp.getProxyUser() != null ? tcp.getProxyUser() : "", tcp.getProxyPassword() != null ? tcp.getProxyUser() : "");
        httpclient.getState().setProxyCredentials(AuthScope.ANY, creds);
        HostConfiguration hcf = new HostConfiguration();
        hcf.setProxy(tcp.getProxyHost(), Integer.parseInt(tcp.getProxyPort()));
        httpclient.executeMethod(hcf, getMethod);
    } else {
        httpclient.executeMethod(getMethod);
    }
    String response = getMethod.getResponseBodyAsString();
    getMethod.releaseConnection();
    return response;
}
Also used : HostConfiguration(org.apache.commons.httpclient.HostConfiguration) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) TransportClientProperties(org.apache.axis.components.net.TransportClientProperties) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Aggregations

TransportClientProperties (org.apache.axis.components.net.TransportClientProperties)1 HostConfiguration (org.apache.commons.httpclient.HostConfiguration)1 HttpClient (org.apache.commons.httpclient.HttpClient)1 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)1 GetMethod (org.apache.commons.httpclient.methods.GetMethod)1