Example usage for org.apache.http.impl.client DefaultHttpClient DefaultHttpClient

List of usage examples for org.apache.http.impl.client DefaultHttpClient DefaultHttpClient

Introduction

In this page you can find the example usage for org.apache.http.impl.client DefaultHttpClient DefaultHttpClient.

Prototype

public DefaultHttpClient() 

Source Link

Usage

From source file:org.lilyproject.process.test.AbstractRestTest.java

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    lilyProxy = new LilyProxy();
    lilyProxy.start();/*from  www . java  2 s.  c o m*/

    httpClient = new DefaultHttpClient();

    BASE_URI = "http://localhost:12060/repository";
}

From source file:com.quietlycoding.android.reader.util.api.Tags.java

/**
 * This method pulls the tags from Google Reader, its used by the methods in
 * this class to communicate before parsing the specific results.
 * /* w  ww.  j  a  v a2s  .  c o m*/
 * @param sid
 *            the Google Reader authentication string.
 * @return arr JSONArray of the items from the server.
 */
private static JSONArray pullTags(String sid) {
    final DefaultHttpClient client = new DefaultHttpClient();
    final HttpGet get = new HttpGet(URL);
    final BasicClientCookie cookie = Authentication.buildCookie(sid);

    try {
        client.getCookieStore().addCookie(cookie);

        final HttpResponse response = client.execute(get);
        final HttpEntity respEntity = response.getEntity();

        Log.d(TAG, "Response from server: " + response.getStatusLine());

        final InputStream in = respEntity.getContent();
        final BufferedReader reader = new BufferedReader(new InputStreamReader(in));

        String line = "";
        String arr = "";
        while ((line = reader.readLine()) != null) {
            arr += line;
        }

        final JSONObject obj = new JSONObject(arr);
        final JSONArray array = obj.getJSONArray("tags");

        return array;
    } catch (final Exception e) {
        Log.d(TAG, "Exception caught:: " + e.toString());
        return null;
    }
}

From source file:com.sunhz.projectutils.httputils.HttpClientUtils.java

/**
 * get access to the network, you need to use in the sub-thread
 *
 * @param url url/*from   w w w  .  j a  v a2s .co  m*/
 * @return response inputStream
 * @throws IOException In the case of non-200 status code is returned, it would have thrown
 */
public static InputStream getInputStream(String url) throws IOException {
    org.apache.http.client.HttpClient client = new DefaultHttpClient();
    client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
            Constant.TimeInApplication.NET_TIMEOUT);
    client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, Constant.TimeInApplication.NET_TIMEOUT);
    HttpGet request = new HttpGet(url);
    HttpResponse response = client.execute(request);
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        return response.getEntity().getContent();
    } else {
        throw new IllegalArgumentException("getInputStreamInSubThread response status code is "
                + response.getStatusLine().getStatusCode());
    }
}

From source file:com.ppshein.sevendaynews.common.java

public static String getInputStreamFromUrl(String url) {
    String content = null;/*from   ww w . ja v  a  2 s  .  c  o m*/
    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = httpclient.execute(new HttpGet(url));
        HttpEntity resEntity = response.getEntity();
        content = EntityUtils.toString(resEntity);
        content = content.trim();
    } catch (Exception e) {
        Log.e("log_tag", "Error in http connection " + e.toString());
    }
    return content;
}

From source file:com.odoo.core.rpc.http.OdooSafeClient.java

private static void createThreadSafeClient(boolean forceSecure) {
    httpClient = new DefaultHttpClient();
    ClientConnectionManager mgr = httpClient.getConnectionManager();
    HttpParams params = httpClient.getParams();
    SchemeRegistry schemeRegistry = mgr.getSchemeRegistry();

    if (forceSecure) {
        schemeRegistry.register(new Scheme("https", getSecureConnectionSetting(), 443));
    } else {//www .  j  a  v a2 s. c  o m
        HostnameVerifier hostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
        SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
        socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
        schemeRegistry.register(new Scheme("https", socketFactory, 443));
    }

    httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(params, schemeRegistry), params);
}

From source file:org.kegbot.app.util.Downloader.java

/**
 * Downloads and returns a URL as a {@link Bitmap}.
 *
 * @param url the image to download//from w ww .  j  a  v a  2s  .  c  o m
 * @return a new {@link Bitmap}, or {@code null} if any error occurred
 */
public static Bitmap downloadBitmap(String url) {
    final HttpClient client = new DefaultHttpClient();
    final HttpGet getRequest = new HttpGet(url);

    try {
        HttpResponse response = client.execute(getRequest);
        final int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            Log.w(LOG_TAG, "Error " + statusCode + " while retrieving bitmap from " + url);
            return null;
        }

        final HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream inputStream = null;
            try {
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inSampleSize = 2;

                inputStream = entity.getContent();
                return BitmapFactory.decodeStream(inputStream, null, options);
            } finally {
                if (inputStream != null) {
                    inputStream.close();
                }
                entity.consumeContent();
            }
        }
    } catch (IOException e) {
        getRequest.abort();
        Log.w(LOG_TAG, "I/O error while retrieving bitmap from " + url, e);
    } catch (IllegalStateException e) {
        getRequest.abort();
        Log.w(LOG_TAG, "Incorrect URL: " + url);
    } catch (Exception e) {
        getRequest.abort();
        Log.w(LOG_TAG, "Error while retrieving bitmap from " + url, e);
    } finally {
        if ((client instanceof AndroidHttpClient)) {
            ((AndroidHttpClient) client).close();
        }
    }
    return null;
}

From source file:WSpatern.DownloadLink.java

public void getLink(String token, String id) {
    try {/*from  www.j av  a2 s. c  o  m*/
        DefaultHttpClient client = new DefaultHttpClient();
        HttpGet get = new HttpGet("http://documenta-dms.com/DMSWS/api/v1/file/" + token + "/link_by_id/" + id);
        HttpResponse response = client.execute(get);
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String line = "";
        while ((line = rd.readLine()) != null) {

            System.out.println(line);
            parseXML(line);

        }
    } catch (IOException ex) {
        Logger.getLogger(ValidTokenWS.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:ADP_Streamline.CURL2.java

public String uploadFiles(File file, String siteId, String containerId, String uploadDirectory) {

    String json = null;//from w w w .j a v a  2 s .co m
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpHost targetHost = new HttpHost("localhost", 8080, "http");

    try {

        HttpPost httppost = new HttpPost("/alfresco/service/api/upload?alf_ticket=" + this.ticket);

        FileBody bin = new FileBody(file);
        StringBody siteid = new StringBody(siteId);
        StringBody containerid = new StringBody(containerId);
        StringBody uploaddirectory = new StringBody(uploadDirectory);

        MultipartEntity reqEntity = new MultipartEntity();
        reqEntity.addPart("filedata", bin);
        reqEntity.addPart("siteid", siteid);
        reqEntity.addPart("containerid", containerid);
        reqEntity.addPart("uploaddirectory", uploaddirectory);

        httppost.setEntity(reqEntity);

        //log.debug("executing request:" + httppost.getRequestLine());

        HttpResponse response = httpclient.execute(targetHost, httppost);

        HttpEntity resEntity = response.getEntity();

        //log.debug("response status:" + response.getStatusLine());

        if (resEntity != null) {
            //log.debug("response content length:" + resEntity.getContentLength());

            json = EntityUtils.toString(resEntity);
            //log.debug("response content:" + json);
        }

        EntityUtils.consume(resEntity);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        httpclient.getConnectionManager().shutdown();
    }

    return json;
}

From source file:popo.defcon.Client.java

public Client() {

    String accountSid = "xxx";
    String authToken = "xxx";
    this.client = new TwilioRestClient(accountSid, authToken);
    HttpClient http = new DefaultHttpClient();
    HttpHost proxy = new HttpHost("10.3.100.207", 8080);
    http.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    this.client.setHttpClient(http);
}

From source file:com.fdesousa.android.WheresMyTrain.Library.json.TflJsonFetcher.java

/**
 * Utility method for fetching an InputStream from a designated URI
 * and returning it for processing.<br/>
 * Static method to aide in easy, wide-spread use
 * @param uri - the URI of the data to fetch
 * @return InputStream containing the response of the request
 * @throws IllegalStateException - in case of a problem, or if connection was aborted
 * @throws IOException - if the stream could not be created
 *///from w  ww  .  j a v a 2  s  . c om
public static InputStream fetchNewJson(URI uri) throws IllegalStateException, IOException {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(uri);
    HttpResponse httpresponse = httpclient.execute(httppost);
    HttpEntity entity = httpresponse.getEntity();

    return entity.getContent();
}