Example usage for org.apache.http.params HttpParams setParameter

List of usage examples for org.apache.http.params HttpParams setParameter

Introduction

In this page you can find the example usage for org.apache.http.params HttpParams setParameter.

Prototype

HttpParams setParameter(String str, Object obj);

Source Link

Usage

From source file:org.eclipse.lyo.oslc4j.bugzilla.utils.BugzillaHttpClient.java

private static HttpClient getHttpClient() {
    SSLContext sc = getTrustingSSLContext();
    SchemeSocketFactory sf = new SSLSocketFactory(sc);

    Scheme scheme = new Scheme("https", 443, sf);
    SchemeRegistry schemeRegistry = new SchemeRegistry();

    schemeRegistry.register(scheme);//w  w w .  ja  va2 s . co  m

    sf = PlainSocketFactory.getSocketFactory();
    scheme = new Scheme("http", 80, sf);

    schemeRegistry.register(scheme);

    ClientConnectionManager clientConnectionManager = new PoolingClientConnectionManager(schemeRegistry);
    HttpParams clientParams = new BasicHttpParams();

    clientParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, TIMEOUT);
    clientParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, TIMEOUT);
    clientParams.setParameter(ClientPNames.HANDLE_REDIRECTS, true);

    return new DefaultHttpClient(clientConnectionManager, clientParams);
}

From source file:org.pluroid.pluroium.HttpClientFactory.java

public static ClientConnectionManager createConnectionManager() {
    HttpParams params = new BasicHttpParams();
    params.setParameter("http.socket.timeout", new Integer(READ_TIMEOUT));
    params.setParameter("http.connection.timeout", new Integer(CONNECT_TIMEOUT));
    return new ThreadSafeClientConnManager(params, supportedSchemes);
}

From source file:org.pluroid.pluroium.HttpClientFactory.java

public static DefaultHttpClient createHttpClient(ClientConnectionManager connMgr) {
    DefaultHttpClient httpClient;//from   w  w w.  j a v  a2s .  com
    HttpParams params = new BasicHttpParams();
    params.setParameter("http.socket.timeout", new Integer(READ_TIMEOUT));
    params.setParameter("http.connection.timeout", new Integer(CONNECT_TIMEOUT));
    connMgr = new ThreadSafeClientConnManager(params, supportedSchemes);

    httpClient = new DefaultHttpClient(connMgr, params);
    httpClient.removeRequestInterceptorByClass(RequestExpectContinue.class);
    return httpClient;
}

From source file:com.wrapp.android.webimage.ImageDownloader.java

public static Date getServerTimestamp(final URL imageUrl) {
    Date expirationDate = new Date();

    try {/* w  w  w .j a  va  2  s .  co m*/
        final String imageUrlString = imageUrl.toString();
        if (imageUrlString == null || imageUrlString.length() == 0) {
            throw new Exception("Passed empty URL");
        }
        LogWrapper.logMessage("Requesting image '" + imageUrlString + "'");
        final HttpClient httpClient = new DefaultHttpClient();
        final HttpParams httpParams = httpClient.getParams();
        httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, CONNECTION_TIMEOUT_IN_MS);
        httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT_IN_MS);
        httpParams.setParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, DEFAULT_BUFFER_SIZE);
        final HttpHead httpHead = new HttpHead(imageUrlString);
        final HttpResponse response = httpClient.execute(httpHead);

        Header[] header = response.getHeaders("Expires");
        if (header != null && header.length > 0) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.US);
            expirationDate = dateFormat.parse(header[0].getValue());
            LogWrapper
                    .logMessage("Image at " + imageUrl.toString() + " expires on " + expirationDate.toString());
        }
    } catch (Exception e) {
        LogWrapper.logException(e);
    }

    return expirationDate;
}

From source file:neembuu.uploader.external.CheckMajorUpdate.java

/**
 * @deprecated version.xml is located in update.zip which is used to get list 
 * of latest plugins//from   w  w w  . j a  v  a  2  s . c  o  m
 */
@Deprecated
private static String getVersionXmlOnline() throws IOException {
    HttpParams params = new BasicHttpParams();
    params.setParameter("http.useragent",
            "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6");
    DefaultHttpClient httpclient = new DefaultHttpClient(params);
    HttpGet httpget = new HttpGet("http://neembuuuploader.sourceforge.net/version.xml");
    NULogger.getLogger().info("Checking for new version...");
    HttpResponse response = httpclient.execute(httpget);
    return EntityUtils.toString(response.getEntity());
}

From source file:org.red5.server.util.HttpConnectionUtil.java

/**
 * Returns a client with all our selected properties / params.
 * //w w  w.j  a  v a 2 s  .  c  o  m
 * @return client
 */
public static final DefaultHttpClient getClient() {
    // create a singular HttpClient object
    DefaultHttpClient client = new DefaultHttpClient(connectionManager);
    // dont retry
    client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
    // get the params for the client
    HttpParams params = client.getParams();
    // establish a connection within x seconds
    params.setParameter(CoreConnectionPNames.SO_TIMEOUT, connectionTimeout);
    // no redirects
    params.setParameter(ClientPNames.HANDLE_REDIRECTS, false);
    // set custom ua
    params.setParameter(CoreProtocolPNames.USER_AGENT, userAgent);
    // set the proxy if the user has one set
    if ((System.getProperty("http.proxyHost") != null) && (System.getProperty("http.proxyPort") != null)) {
        HttpHost proxy = new HttpHost(System.getProperty("http.proxyHost").toString(),
                Integer.valueOf(System.getProperty("http.proxyPort")));
        client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
    return client;
}

From source file:com.blacklocus.sample.time.HttpClientFactory.java

/**
 * Construct a new HttpClient which uses the {@link #POOL_MGR default connection pool}.
 *
 * @param connectionTimeout highly sensitive to application so must be specified
 * @param socketTimeout highly sensitive to application so must be specified
 *//*from  w w  w  . j ava  2 s .  c om*/
public static HttpClient createHttpClient(final int connectionTimeout, final int socketTimeout) {
    return new DefaultHttpClient(POOL_MGR) {
        {
            HttpParams httpParams = getParams();

            // prevent seg fault JVM bug, see https://code.google.com/p/crawler4j/issues/detail?id=136
            httpParams.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);

            HttpConnectionParams.setConnectionTimeout(httpParams, connectionTimeout);
            HttpConnectionParams.setSoTimeout(httpParams, socketTimeout);
            HttpConnectionParams.setStaleCheckingEnabled(httpParams, true);

        }
    };
}

From source file:es.deustotech.piramide.utils.tts.TextToSpeechWeb.java

private static synchronized void speech(final Context context, final String text, final String language) {
    executor.submit(new Runnable() {
        @Override/*from  w w w  .  j  ava  2 s .c o m*/
        public void run() {
            try {
                final String encodedUrl = Constants.URL + language + "&q="
                        + URLEncoder.encode(text, Encoding.UTF_8.name());
                final DefaultHttpClient client = new DefaultHttpClient();
                HttpParams params = new BasicHttpParams();
                params.setParameter("http.protocol.content-charset", "UTF-8");
                client.setParams(params);
                final FileOutputStream fos = context.openFileOutput(Constants.MP3_FILE,
                        Context.MODE_WORLD_READABLE);
                try {
                    try {
                        final HttpResponse response = client.execute(new HttpGet(encodedUrl));
                        downloadFile(response, fos);
                    } finally {
                        fos.close();
                    }
                    final String filePath = context.getFilesDir().getAbsolutePath() + "/" + Constants.MP3_FILE;
                    final MediaPlayer player = MediaPlayer.create(context.getApplicationContext(),
                            Uri.fromFile(new File(filePath)));
                    player.start();
                    Thread.sleep(player.getDuration());
                    while (player.isPlaying()) {
                        Thread.sleep(100);
                    }
                    player.stop();

                } finally {
                    context.deleteFile(Constants.MP3_FILE);
                }
            } catch (InterruptedException ie) {
                // ok
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:com.wrapp.android.webimage.ImageDownloader.java

public static boolean loadImage(final String imageKey, final URL imageUrl) {
    HttpEntity responseEntity = null;/*from ww w .j  a v  a  2  s .  c o  m*/
    InputStream contentInputStream = null;

    try {
        final String imageUrlString = imageUrl.toString();
        if (imageUrlString == null || imageUrlString.length() == 0) {
            throw new Exception("Passed empty URL");
        }
        LogWrapper.logMessage("Requesting image '" + imageUrlString + "'");
        final HttpClient httpClient = new DefaultHttpClient();
        final HttpParams httpParams = httpClient.getParams();
        httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, CONNECTION_TIMEOUT_IN_MS);
        httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT_IN_MS);
        httpParams.setParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, DEFAULT_BUFFER_SIZE);
        final HttpGet httpGet = new HttpGet(imageUrlString);
        final HttpResponse response = httpClient.execute(httpGet);

        responseEntity = response.getEntity();
        if (responseEntity == null) {
            throw new Exception("No response entity for image: " + imageUrl.toString());
        }
        contentInputStream = responseEntity.getContent();
        if (contentInputStream == null) {
            throw new Exception("No content stream for image: " + imageUrl.toString());
        }

        Bitmap bitmap = BitmapFactory.decodeStream(contentInputStream);
        ImageCache.saveImageInFileCache(imageKey, bitmap);
        LogWrapper.logMessage("Downloaded image: " + imageUrl.toString());
        bitmap.recycle();
    } catch (IOException e) {
        LogWrapper.logException(e);
        return false;
    } catch (Exception e) {
        LogWrapper.logException(e);
        return false;
    } finally {
        try {
            if (contentInputStream != null) {
                contentInputStream.close();
            }
            if (responseEntity != null) {
                responseEntity.consumeContent();
            }
        } catch (IOException e) {
            LogWrapper.logException(e);
        }
    }

    return true;
}

From source file:jfabrix101.lib.helper.NetworkHelper.java

/**
 * First step for an execution of an http request.
 * Create an HttpClient using http or https.
 * @return/*from w ww  .  ja  v  a 2s. c o  m*/
 */
private static HttpClient getHttpClient() {
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", new SimpleSSLSocketFactory(), 443));

    HttpParams params = new BasicHttpParams();
    params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30);
    params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30));
    params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

    ClientConnectionManager cm = new SingleClientConnManager(params, schemeRegistry);
    HttpClient httpClient = new DefaultHttpClient(cm, params);
    return httpClient;
}