Example usage for org.apache.http.params BasicHttpParams BasicHttpParams

List of usage examples for org.apache.http.params BasicHttpParams BasicHttpParams

Introduction

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

Prototype

public BasicHttpParams() 

Source Link

Usage

From source file:sit.web.client.HTTPTrustHelper.java

/**
 * from/*from  www  . j  a v  a2  s  . c om*/
 * http://stackoverflow.com/questions/2642777/trusting-all-certificates-using-httpclient-over-https
 *
 * @param charset
 * @param port
 * @return
 */
public static HttpClient getNewHttpClient(Charset charset, int port) {
    try {
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);

        SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, charset.name());

        SchemeRegistry registry = new SchemeRegistry();
        //registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", sf, port));

        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

        return new DefaultHttpClient(ccm, params);
    } catch (Exception e) {
        return new DefaultHttpClient();
    }
}

From source file:com.subgraph.vega.internal.http.proxy.HttpProxy.java

public HttpProxy(int listenPort, ProxyTransactionManipulator transactionManipulator,
        HttpInterceptor interceptor, IHttpRequestEngine requestEngine,
        SSLContextRepository sslContextRepository) {
    this.eventHandlers = new ArrayList<IHttpInterceptProxyEventHandler>();
    this.transactionManipulator = transactionManipulator;
    this.interceptor = interceptor;
    this.listenPort = listenPort;
    this.params = new BasicHttpParams();
    this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0)
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
            //      .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true);

    BasicHttpProcessor inProcessor = new BasicHttpProcessor();
    inProcessor.addInterceptor(new ResponseConnControl());
    inProcessor.addInterceptor(new ResponseContentCustom());

    HttpRequestHandlerRegistry registry = new HttpRequestHandlerRegistry();
    registry.register("*", new ProxyRequestHandler(this, logger, requestEngine));

    httpService = new VegaHttpService(inProcessor, new DefaultConnectionReuseStrategy(),
            new DefaultHttpResponseFactory(), registry, params, sslContextRepository);

    connectionList = new ArrayList<ConnectionTask>();
}

From source file:com.siahmsoft.soundroid.sdk7.util.HttpManager.java

public static DefaultHttpClient newInstance() {
    final HttpParams params = new BasicHttpParams();

    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setUserAgent(params, "Soundroid/1.1");
    HttpProtocolParams.setContentCharset(params, "UTF-8");

    //HttpConnectionParams.setTcpNoDelay(params, true);
    HttpConnectionParams.setStaleCheckingEnabled(params, false);
    HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
    HttpConnectionParams.setSoTimeout(params, 20 * 1000);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    HttpClientParams.setRedirecting(params, true);

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);
    DefaultHttpClient sClient = new DefaultHttpClient(manager, params);

    return sClient;
}

From source file:org.berlin.crawl.net.WebConnector.java

public synchronized String connect(final BotLink blink, final URIBuilder builder) throws Exception {
    InputStream instream = null;//from  w w w.jav  a2 s  .  c o m
    try {
        logger.info("!* Attempting download and connect request : " + builder.toString());
        final HttpParams params = new BasicHttpParams();
        final HttpProtocolParamBean paramsBean = new HttpProtocolParamBean(params);
        paramsBean.setUserAgent(USER_AGENT);
        // Set this to false, or else you'll get an
        // Expectation Failed: error
        paramsBean.setUseExpectContinue(false);

        final URI uri = builder.build();
        final HttpClient httpclient = new DefaultHttpClient();
        final HttpGet httpget = new HttpGet(uri);
        httpget.setParams(params);

        // Connect //
        final HttpResponse response = httpclient.execute(httpget);
        final HttpEntity entity = response.getEntity();

        this.response = response;
        if (response != null) {
            if (response.getStatusLine() != null) {
                if (response.getStatusLine().getStatusCode() != 200) {
                    // Log the error line
                    logger.error("Invalid status code - " + response.getStatusLine().getStatusCode());
                    throw new CrawlerError("Invalid status code - " + response.getStatusLine().getStatusCode());
                }
            }
        }

        if (entity != null) {
            blink.setStatusline(String.valueOf(response.getStatusLine()));
            blink.setCode(response.getStatusLine().getStatusCode());
            instream = entity.getContent();
            if (instream != null) {
                final StringBuffer document = new StringBuffer();
                final BufferedReader reader = new BufferedReader(new InputStreamReader(instream));
                String line = "";
                while ((line = reader.readLine()) != null) {
                    document.append(line);
                    document.append(NL);
                } // End of the while //

                db.proc(blink);
                Thread.sleep(LINK_PROCESS_DELAY);

                return document.toString();
            } // End of - instream ///
        } // End of the if /

    } catch (final Throwable e) {
        logger.error("Error at connect to LINK", e);
        throw new CrawlerError("Error at connect to LINK", e);
    } finally {
        try {
            if (instream != null) {
                instream.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    } // End of the try - catch block //
    return null;
}

From source file:com.dalaran.async.task.http.AbstractHTTPService.java

public static HttpClient getNewHttpClient() {
    try {/*from  www  .j a va 2  s  .c o  m*/
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);

        SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", getSocketFactory(), 80));
        registry.register(new Scheme("https", sf, 443));

        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

        return new DefaultHttpClient(ccm, params);
    } catch (Exception e) {
        return new DefaultHttpClient();
    }
}

From source file:com.socialize.net.DefaultHttpClientFactory.java

@Override
public void init(SocializeConfig config) throws SocializeException {

    try {/*from ww  w . ja  v a 2s  .  c om*/
        if (logger != null && logger.isDebugEnabled()) {
            logger.debug("Initializing " + getClass().getSimpleName());
        }

        params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

        HttpConnectionParams.setConnectionTimeout(params,
                config.getIntProperty(SocializeConfig.HTTP_CONNECTION_TIMEOUT, 10000));
        HttpConnectionParams.setSoTimeout(params,
                config.getIntProperty(SocializeConfig.HTTP_SOCKET_TIMEOUT, 10000));

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

        connectionManager = new ThreadSafeClientConnManager(params, registry);

        monitor = new IdleConnectionMonitorThread(connectionManager);
        monitor.setDaemon(true);
        monitor.start();

        if (logger != null && logger.isDebugEnabled()) {
            logger.debug("Initialized " + getClass().getSimpleName());
        }

        destroyed = false;
    } catch (Exception e) {
        throw new SocializeException(e);
    }
}

From source file:com.ibuildapp.romanblack.TableReservationPlugin.utils.TableReservationHTTP.java

/**
 * This method sends HTTP request to add order.
 *
 * @param user/*  w  w w .  j  a v a2  s . c om*/
 * @param handler
 * @param orderInfo
 * @return
 */
public static String sendAddOrderRequest(User user, Handler handler, TableReservationInfo orderInfo) {
    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, 15000);
    HttpConnectionParams.setSoTimeout(httpParameters, 15000);

    HttpClient httpclient = new DefaultHttpClient(httpParameters);
    HttpPost httppost = new HttpPost(ADD_ORDER_URL);
    Log.e(TAG, "ADD_ORDER_URL = " + ADD_ORDER_URL);

    MultipartEntity multipartEntity = new MultipartEntity();

    // user details
    String userType = null;
    String orderUUID = null;
    try {

        if (user.getAccountType() == User.ACCOUNT_TYPES.FACEBOOK) {
            userType = "facebook";
            multipartEntity.addPart("order_customer_name", new StringBody(
                    user.getUserFirstName() + " " + user.getUserLastName(), Charset.forName("UTF-8")));
        } else if (user.getAccountType() == User.ACCOUNT_TYPES.TWITTER) {
            userType = "twitter";
            multipartEntity.addPart("order_customer_name",
                    new StringBody(user.getUserName(), Charset.forName("UTF-8")));
        } else if (user.getAccountType() == User.ACCOUNT_TYPES.IBUILDAPP) {
            userType = "ibuildapp";
            multipartEntity.addPart("order_customer_name",
                    new StringBody(user.getUserName(), Charset.forName("UTF-8")));

        } else if (user.getAccountType() == User.ACCOUNT_TYPES.GUEST) {
            userType = "guest";
            multipartEntity.addPart("order_customer_name", new StringBody("Guest", Charset.forName("UTF-8")));
        }

        multipartEntity.addPart("user_type", new StringBody(userType, Charset.forName("UTF-8")));
        multipartEntity.addPart("user_id", new StringBody(user.getAccountId(), Charset.forName("UTF-8")));
        multipartEntity.addPart("app_id", new StringBody(orderInfo.getAppid(), Charset.forName("UTF-8")));
        multipartEntity.addPart("module_id", new StringBody(orderInfo.getModuleid(), Charset.forName("UTF-8")));

        // order UUID
        orderUUID = UUID.randomUUID().toString();
        multipartEntity.addPart("order_uid", new StringBody(orderUUID, Charset.forName("UTF-8")));

        // order details
        Date tempDate = orderInfo.getOrderDate();
        tempDate.setHours(orderInfo.getOrderTime().houres);
        tempDate.setMinutes(orderInfo.getOrderTime().minutes);
        tempDate.getTimezoneOffset();
        String timeZone = timeZoneToString();

        multipartEntity.addPart("time_zone", new StringBody(timeZone, Charset.forName("UTF-8")));
        multipartEntity.addPart("order_date_time",
                new StringBody(Long.toString(tempDate.getTime() / 1000), Charset.forName("UTF-8")));
        multipartEntity.addPart("order_persons",
                new StringBody(Integer.toString(orderInfo.getPersonsAmount()), Charset.forName("UTF-8")));
        multipartEntity.addPart("order_spec_request",
                new StringBody(orderInfo.getSpecialRequest(), Charset.forName("UTF-8")));
        multipartEntity.addPart("order_customer_phone",
                new StringBody(orderInfo.getPhoneNumber(), Charset.forName("UTF-8")));
        multipartEntity.addPart("order_customer_email",
                new StringBody(orderInfo.getCustomerEmail(), Charset.forName("UTF-8")));

        // add security part
        multipartEntity.addPart("app_id", new StringBody(Statics.appId, Charset.forName("UTF-8")));
        multipartEntity.addPart("token", new StringBody(Statics.appToken, Charset.forName("UTF-8")));

    } catch (Exception e) {
        Log.d("", "");
    }

    httppost.setEntity(multipartEntity);

    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    try {
        String strResponseSaveGoal = httpclient.execute(httppost, responseHandler);
        Log.d("sendAddOrderRequest", "");
        String res = JSONParser.parseQueryError(strResponseSaveGoal);

        if (res == null || res.length() == 0) {
            return orderUUID;
        } else {
            handler.sendEmptyMessage(ADD_REQUEST_ERROR);
            return null;
        }
    } catch (ConnectTimeoutException conEx) {
        handler.sendEmptyMessage(ADD_REQUEST_ERROR);
        return null;
    } catch (ClientProtocolException ex) {
        handler.sendEmptyMessage(ADD_REQUEST_ERROR);
        return null;
    } catch (IOException ex) {
        handler.sendEmptyMessage(ADD_REQUEST_ERROR);
        return null;
    }
}

From source file:com.autburst.picture.server.HttpRequest.java

/**
 * HttpGet request// ww w .  j a va 2  s  .  com
 * 
 * @param sUrl
 * @return
 */
public String get(String sUrl) throws Exception {

    HttpParams my_httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(my_httpParams, 15000);
    HttpClient httpclient = new DefaultHttpClient(my_httpParams);

    try {

        // Prepare a request object
        HttpGet httpget = new HttpGet(sUrl);

        // Execute the request
        HttpResponse response;

        response = httpclient.execute(httpget);
        // Examine the response status
        StatusLine statusLine = response.getStatusLine();
        Log.i(TAG, statusLine.toString());

        if (statusLine.getStatusCode() != HttpStatus.SC_OK)
            throw new Exception("could not perform get request: " + statusLine.getStatusCode());

        // Get hold of the response entity
        HttpEntity entity = response.getEntity();
        // If the response does not enclose an entity, there is no need
        // to worry about connection release

        if (entity != null) {
            InputStream instream = entity.getContent();
            String result = convertStreamToString(instream);
            Log.i(TAG, result);

            // Closing the input stream will trigger connection release
            instream.close();

            return result;
        }

        throw new Exception("Http get request did not deliver any payload!");
    } catch (Exception ex) {
        Log.e(TAG, "---------Error-----" + ex.getMessage());
        throw new Exception(ex);
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:com.clarionmedia.infinitum.web.rest.impl.CachingEnabledRestfulClient.java

/**
 * Creates a new {@code CachingEnabledRestfulClient}.
 *///  w  ww.  ja v  a2  s .c o m
public CachingEnabledRestfulClient(Context context) {
    mLogger = new SmartLogger(getClass().getSimpleName());
    mHttpParams = new BasicHttpParams();
    mResponseCache = new RestResponseCache();
    mResponseCache.enableDiskCache(context, AbstractCache.DISK_CACHE_INTERNAL);
}

From source file:com.klarna.checkout.BasicConnector.java

/**
 * Create a HTTP Client.//from www  .jav  a2 s  .c om
 *
 * @return HTTP Client to use.
 */
protected IHttpClient createHttpClient() {
    BasicHttpParams params = new BasicHttpParams();
    params.setParameter("http.protocol.allow-circular-redirects", false);
    return new HttpClientWrapper(this.manager, params);
}