Search in sources :

Example 1 with DefaultHttpClient

use of org.apache.http.impl.client.DefaultHttpClient in project Trello-Android by chrisHoekstra.

the class TrelloService method getHttpClient.

public HttpClient getHttpClient() {
    DefaultHttpClient client = null;
    try {
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);
        SSLSocketFactory sf = new CustomSSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        // Setting up parameters
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, "utf-8");
        params.setBooleanParameter("http.protocol.expect-continue", true);
        // Setting timeout
        HttpConnectionParams.setConnectionTimeout(params, 100000);
        HttpConnectionParams.setSoTimeout(params, 100000);
        // Registering schemes for both HTTP and HTTPS
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", sf, 443));
        // Creating thread safe client connection manager
        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
        // Creating HTTP client
        client = new DefaultHttpClient(ccm, params);
    } catch (Exception e) {
        client = new DefaultHttpClient();
    }
    return client;
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) Scheme(org.apache.http.conn.scheme.Scheme) ThreadSafeClientConnManager(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) BasicHttpParams(org.apache.http.params.BasicHttpParams) KeyStore(java.security.KeyStore) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) KeyStoreException(java.security.KeyStoreException) JSONException(org.json.JSONException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ClientProtocolException(org.apache.http.client.ClientProtocolException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) UnknownHostException(java.net.UnknownHostException)

Example 2 with DefaultHttpClient

use of org.apache.http.impl.client.DefaultHttpClient in project hbase by apache.

the class Client method initialize.

private void initialize(Cluster cluster, boolean sslEnabled) {
    this.cluster = cluster;
    this.sslEnabled = sslEnabled;
    extraHeaders = new ConcurrentHashMap<>();
    String clspath = System.getProperty("java.class.path");
    LOG.debug("classpath " + clspath);
    this.httpClient = new DefaultHttpClient();
    this.httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 2000);
}
Also used : DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 3 with DefaultHttpClient

use of org.apache.http.impl.client.DefaultHttpClient in project cw-omnibus by commonsguy.

the class Downloader method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    client = new DefaultHttpClient();
}
Also used : DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 4 with DefaultHttpClient

use of org.apache.http.impl.client.DefaultHttpClient in project hive by apache.

the class JIRAService method publishComments.

void publishComments(String comments) {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    try {
        String url = String.format("%s/rest/api/2/issue/%s/comment", mUrl, mName);
        URL apiURL = new URL(mUrl);
        httpClient.getCredentialsProvider().setCredentials(new AuthScope(apiURL.getHost(), apiURL.getPort(), AuthScope.ANY_REALM), new UsernamePasswordCredentials(mUser, mPassword));
        BasicHttpContext localcontext = new BasicHttpContext();
        localcontext.setAttribute("preemptive-auth", new BasicScheme());
        httpClient.addRequestInterceptor(new PreemptiveAuth(), 0);
        HttpPost request = new HttpPost(url);
        ObjectMapper mapper = new ObjectMapper();
        StringEntity params = new StringEntity(mapper.writeValueAsString(new Body(comments)));
        request.addHeader("Content-Type", "application/json");
        request.setEntity(params);
        HttpResponse httpResponse = httpClient.execute(request, localcontext);
        StatusLine statusLine = httpResponse.getStatusLine();
        if (statusLine.getStatusCode() != 201) {
            throw new RuntimeException(statusLine.getStatusCode() + " " + statusLine.getReasonPhrase());
        }
        mLogger.info("JIRA Response Metadata: " + httpResponse);
    } catch (Exception e) {
        mLogger.error("Encountered error attempting to post comment to " + mName, e);
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
}
Also used : BasicScheme(org.apache.http.impl.auth.BasicScheme) HttpPost(org.apache.http.client.methods.HttpPost) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) URL(java.net.URL) IOException(java.io.IOException) HttpException(org.apache.http.HttpException) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) StatusLine(org.apache.http.StatusLine) StringEntity(org.apache.http.entity.StringEntity) AuthScope(org.apache.http.auth.AuthScope) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 5 with DefaultHttpClient

use of org.apache.http.impl.client.DefaultHttpClient in project PlayerHater by chrisrhoden.

the class PlaylistParser method parsePls.

private static Uri[] parsePls(Uri uri) {
    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = httpclient.execute(new HttpGet(uri.toString()));
        HttpEntity entity = response.getEntity();
        InputStream inputStream = entity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        String header = reader.readLine();
        if (header.trim().equalsIgnoreCase("[playlist]")) {
            String line;
            ArrayList<Uri> uriList = new ArrayList<Uri>();
            do {
                line = reader.readLine();
                if (line != null) {
                    if (line.startsWith("File")) {
                        String fileName = line.substring(line.indexOf("=") + 1).trim();
                        uriList.add(Uri.parse(fileName));
                    }
                }
            } while (line != null);
            if (uriList.size() > 0) {
                Uri[] res = new Uri[uriList.size()];
                return uriList.toArray(res);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return new Uri[] { uri };
}
Also used : HttpEntity(org.apache.http.HttpEntity) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) Uri(android.net.Uri) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) BufferedReader(java.io.BufferedReader)

Aggregations

DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)481 HttpResponse (org.apache.http.HttpResponse)293 HttpGet (org.apache.http.client.methods.HttpGet)227 HttpClient (org.apache.http.client.HttpClient)203 IOException (java.io.IOException)158 HttpPost (org.apache.http.client.methods.HttpPost)107 Test (org.junit.Test)86 HttpEntity (org.apache.http.HttpEntity)84 ClientProtocolException (org.apache.http.client.ClientProtocolException)64 InputStream (java.io.InputStream)60 Scheme (org.apache.http.conn.scheme.Scheme)53 BasicHttpParams (org.apache.http.params.BasicHttpParams)51 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)49 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)48 HttpParams (org.apache.http.params.HttpParams)47 ArrayList (java.util.ArrayList)45 URI (java.net.URI)43 ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)38 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)38 InputStreamReader (java.io.InputStreamReader)37