All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.microsoft.bingads.internal.HttpClientWebServiceCaller Maven / Gradle / Ivy

Go to download

The Bing Ads Java SDK is a library improving developer experience when working with the Bing Ads services by providing high-level access to features such as Bulk API, OAuth Authorization and SOAP API.

There is a newer version: 13.0.23.2
Show newest version
package com.microsoft.bingads.internal;

import java.io.IOException;
import java.net.ProxySelector;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.ProxySelectorRoutePlanner;


class HttpClientWebServiceCaller implements WebServiceCaller {       
	private DefaultHttpClient client;
	
    @Override
    public HttpResponse post(URL requestUrl, List formValues) throws IOException {

        try {
            client = createHttpClientWithProxy();
            
            final HttpPost httpPost = new HttpPost(requestUrl.toURI());
            
            final UrlEncodedFormEntity requestEntity = new UrlEncodedFormEntity(formValues, "UTF-8");
            
            httpPost.setEntity(requestEntity);

            return client.execute(httpPost);
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException(e);
        }
    }
    
    private DefaultHttpClient createHttpClientWithProxy() {
    	DefaultHttpClient client = new DefaultHttpClient();
    	
    	ProxySelector proxySelector = ProxySelector.getDefault();
    	
    	client.setRoutePlanner(new ProxySelectorRoutePlanner(client.getConnectionManager().getSchemeRegistry(), proxySelector));
    	
    	return client;
    }

	@Override
	public void shutDown() {
		if (client != null) {
            client.getConnectionManager().shutdown();
        }		
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy