Example usage for org.apache.http.params CoreConnectionPNames SO_TIMEOUT

List of usage examples for org.apache.http.params CoreConnectionPNames SO_TIMEOUT

Introduction

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

Prototype

String SO_TIMEOUT

To view the source code for org.apache.http.params CoreConnectionPNames SO_TIMEOUT.

Click Source Link

Usage

From source file:com.oneguy.recognize.engine.GoogleStreamingEngine.java

byte[] getHttpData(String url) {
    String TAG = "getHttpData";
    HttpGet httpGet = new HttpGet(url);
    byte[] result = null;
    try {/*from   w w  w .j av a 2  s .  co  m*/
        HttpClient client = new DefaultHttpClient();
        client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, TIMEOUT);
        client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, TIMEOUT);
        Log.d(TAG, "HTTP GET:" + httpGet.getURI() + " method:" + httpGet.getMethod());
        HttpResponse httpResponse = client.execute(httpGet);
        if (httpResponse.getStatusLine().getStatusCode() == 200) {
            result = EntityUtils.toByteArray(httpResponse.getEntity());
            Log.d(TAG, new String(result));
            StreamResponse response = new StreamResponse(null, Status.SUCCESS);
            response.setResponse(result);
            response.setResponseCode(httpResponse.getStatusLine().getStatusCode());
            Message msg = new Message();
            msg.what = EVENT_RESPONSE;
            msg.obj = response;
            mHandler.sendMessage(msg);
        }
    } catch (ClientProtocolException e) {
        onError(e);
        e.printStackTrace();
    } catch (IOException e) {
        onError(e);
        e.printStackTrace();
    }
    return result;
}

From source file:org.mulgara.scon.Connection.java

/**
 * Establish a client connection in HTTP
 * @return A new client connection with parameters set for this object
 *///ww w  .j a va  2s .  co  m
private HttpClient getHttpClient() {
    HttpParams params = new BasicHttpParams();
    params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, expectContinue);
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, soTimeout);
    return new DefaultHttpClient(conManager, params);
}

From source file:org.apache.abdera2.common.protocol.BasicClient.java

/**
 * Sets the default socket timeout (SO_TIMEOUT) in milliseconds which is the timeout for waiting for data. A timeout
 * value of zero is interpreted as an infinite timeout.
 *///w  ww .  j av  a 2  s .c om
public <T extends Client> T setSocketTimeout(int timeout) {
    client.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, Math.max(0, timeout));
    return (T) this;
}

From source file:com.poomoo.edao.activity.UploadPicsActivity.java

private void upload(File file) {
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(eDaoClientConfig.imageurl); // ?Post?,Post
    client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, eDaoClientConfig.timeout);
    client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, eDaoClientConfig.timeout);

    MultipartEntity entity = new MultipartEntity(); // ,
    // List<File> list = new ArrayList<File>();
    // // File// w ww . j a  va2  s .com
    // list.add(file1);
    // list.add(file2);
    // list.add(file3);
    // list.add(file4);
    // System.out.println("list.size():" + list.size());
    // for (int i = 0; i < list.size(); i++) {
    // ContentBody body = new FileBody(list.get(i));
    // entity.addPart("file", body); // ???
    // }
    System.out.println(
            "upload" + "uploadCount" + ":" + uploadCount + "filelist.size" + ":" + filelist.size());
    entity.addPart("file", new FileBody(file));

    post.setEntity(entity); // ?Post?
    Message message = new Message();
    try {
        entity.addPart("imageType", new StringBody(String.valueOf(uploadCount + 1), Charset.forName("utf-8")));
        entity.addPart("userId", new StringBody(userId, Charset.forName("utf-8")));
        HttpResponse response;
        response = client.execute(post);
        // Post
        if (response.getStatusLine().getStatusCode() == 200) {
            uploadCount++;
            message.what = 1;
        } else
            message.what = 2;
        // return EntityUtils.toString(response.getEntity(), "UTF-8"); //
        // ??
    } catch (Exception e) {
        // TODO ? catch ?
        e.printStackTrace();
        message.what = 2;
        System.out.println("IOException:" + e.getMessage());
    } finally {
        client.getConnectionManager().shutdown(); // ?
        myHandler.sendMessage(message);
    }
}

From source file:org.apache.abdera2.common.protocol.BasicClient.java

/**
 * Return the socket timeout for the connection in milliseconds A timeout value of zero is interpreted as an
 * infinite timeout./*w  w w . j a  va  2  s.c  o m*/
 */
public int getSocketTimeout() {
    return client.getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0);
}

From source file:org.dasein.cloud.azure.AzureMethod.java

protected @Nonnull HttpClient getClient() throws CloudException, InternalException {
    ProviderContext ctx = provider.getContext();

    if (ctx == null) {
        throw new AzureConfigException("No context was defined for this request");
    }/*  w w  w.j  a  v  a  2  s  .  co  m*/
    String endpoint = ctx.getEndpoint();

    if (endpoint == null) {
        throw new AzureConfigException("No cloud endpoint was defined");
    }
    boolean ssl = endpoint.startsWith("https");
    int targetPort;

    try {
        URI uri = new URI(endpoint);

        targetPort = uri.getPort();
        if (targetPort < 1) {
            targetPort = (ssl ? 443 : 80);
        }
    } catch (URISyntaxException e) {
        throw new AzureConfigException(e);
    }
    HttpParams params = new BasicHttpParams();
    SchemeRegistry registry = new SchemeRegistry();

    try {
        registry.register(
                new Scheme(ssl ? "https" : "http", targetPort, new AzureSSLSocketFactory(new AzureX509(ctx))));
    } catch (KeyManagementException e) {
        e.printStackTrace();
        throw new InternalException(e);
    } catch (UnrecoverableKeyException e) {
        e.printStackTrace();
        throw new InternalException(e);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        throw new InternalException(e);
    } catch (KeyStoreException e) {
        e.printStackTrace();
        throw new InternalException(e);
    }

    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
    HttpProtocolParams.setUserAgent(params, "Dasein Cloud");
    params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000);
    params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 300000);

    Properties p = ctx.getCustomProperties();

    if (p != null) {
        String proxyHost = p.getProperty("proxyHost");
        String proxyPort = p.getProperty("proxyPort");

        if (proxyHost != null) {
            int port = 0;

            if (proxyPort != null && proxyPort.length() > 0) {
                port = Integer.parseInt(proxyPort);
            }
            params.setParameter(ConnRoutePNames.DEFAULT_PROXY,
                    new HttpHost(proxyHost, port, ssl ? "https" : "http"));
        }
    }

    ClientConnectionManager ccm = new ThreadSafeClientConnManager(registry);

    return new DefaultHttpClient(ccm, params);
}

From source file:org.dasein.cloud.tier3.APIHandler.java

private @Nonnull HttpClient getClient(URI uri) throws InternalException, CloudException {
    ProviderContext ctx = provider.getContext();

    if (ctx == null) {
        throw new NoContextException();
    }//from w  ww.ja  v  a2s . co  m

    boolean ssl = uri.getScheme().startsWith("https");

    HttpParams params = new BasicHttpParams();

    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    // noinspection deprecation
    HttpProtocolParams.setContentCharset(params, Consts.UTF_8.toString());
    HttpProtocolParams.setUserAgent(params, "Dasein Cloud");
    params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000);
    params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 300000);

    Properties p = ctx.getCustomProperties();

    if (p != null) {
        String proxyHost = p.getProperty("proxyHost");
        String proxyPort = p.getProperty("proxyPort");

        if (proxyHost != null) {
            int port = 0;

            if (proxyPort != null && proxyPort.length() > 0) {
                port = Integer.parseInt(proxyPort);
            }
            params.setParameter(ConnRoutePNames.DEFAULT_PROXY,
                    new HttpHost(proxyHost, port, ssl ? "https" : "http"));
        }
    }

    return new DefaultHttpClient();
}

From source file:com.googlecode.jsonrpc4j.JsonRpcHttpAsyncClient.java

private void initialize() {
    if (initialized.getAndSet(true)) {
        return;//from   w  w w.j a  v  a2  s.  com
    }

    // HTTP parameters for the client
    final HttpParams params = new BasicHttpParams();
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT,
            Integer.getInteger("com.googlecode.jsonrpc4j.async.socket.timeout", 30000));
    params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
            Integer.getInteger("com.googlecode.jsonrpc4j.async.connect.timeout", 30000));
    params.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE,
            Integer.getInteger("com.googlecode.jsonrpc4j.async.socket.buffer", 8 * 1024));
    params.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY,
            Boolean.valueOf(System.getProperty("com.googlecode.jsonrpc4j.async.tcp.nodelay", "true")));
    params.setParameter(CoreProtocolPNames.USER_AGENT, "jsonrpc4j/1.0");

    // Create client-side I/O reactor
    final ConnectingIOReactor ioReactor;
    try {
        IOReactorConfig config = new IOReactorConfig();
        config.setIoThreadCount(Integer.getInteger("com.googlecode.jsonrpc4j.async.reactor.threads", 1));
        ioReactor = new DefaultConnectingIOReactor(config);
    } catch (IOReactorException e) {
        throw new RuntimeException("Exception initializing asynchronous Apache HTTP Client", e);
    }

    // Create a default SSLSetupHandler that accepts any certificate
    if (sslContext == null) {
        try {
            sslContext = SSLContext.getDefault();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    // Create HTTP connection pool
    BasicNIOConnFactory nioConnFactory = new BasicNIOConnFactory(sslContext, null, params);
    pool = new BasicNIOConnPool(ioReactor, nioConnFactory, params);
    // Limit total number of connections to 500 by default
    pool.setDefaultMaxPerRoute(Integer.getInteger("com.googlecode.jsonrpc4j.async.max.inflight.route", 500));
    pool.setMaxTotal(Integer.getInteger("com.googlecode.jsonrpc4j.async.max.inflight.total", 500));

    // Run the I/O reactor in a separate thread
    Thread t = new Thread(new Runnable() {
        public void run() {
            try {
                // Create client-side HTTP protocol handler
                HttpAsyncRequestExecutor protocolHandler = new HttpAsyncRequestExecutor();
                // Create client-side I/O event dispatch
                IOEventDispatch ioEventDispatch = new DefaultHttpClientIODispatch(protocolHandler, sslContext,
                        params);
                // Ready to go!
                ioReactor.execute(ioEventDispatch);
            } catch (InterruptedIOException ex) {
                System.err.println("Interrupted");
            } catch (IOException e) {
                System.err.println("I/O error: " + e.getMessage());
            }
        }

    }, "jsonrpc4j HTTP IOReactor");
    // Start the client thread
    t.setDaemon(true);
    t.start();

    // Create HTTP protocol processing chain
    HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
            // Use standard client-side protocol interceptors
            new RequestContent(), new RequestTargetHost(), new RequestConnControl(), new RequestUserAgent(),
            new RequestExpectContinue() });

    // Create HTTP requester
    requester = new HttpAsyncRequester(httpproc, new DefaultConnectionReuseStrategy(), params);
}

From source file:com.sangupta.jerry.http.WebRequest.java

/**
* Specify the socket time out to the given value.
* 
* @param timeout/*w w w .j av a 2  s  .  c  om*/
*            the timeout value
* 
* @return this very {@link WebRequest}
*/
public WebRequest socketTimeout(int timeout) {
    return config(CoreConnectionPNames.SO_TIMEOUT, timeout);
}

From source file:com.drive.student.xutils.HttpUtils.java

/**
 *
 * HttpClient??get?./*  w  ww.j a  v a2 s.  c o  m*/
 */
public HttpResponse sendHttpGet(String urlpath, boolean isGzip) {
    HttpClient httpclient = new DefaultHttpClient();
    try {
        HttpGet request = new HttpGet(urlpath);
        buildHttpHeaderForGet(request);// 
        if (isGzip) {
            request.addHeader("accept-encoding", "gzip");
        }
        httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
                HttpUtils.DEFAULT_CONN_TIMEOUT); // 
        httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, HttpUtils.DEFAULT_SO_TIMEOUT); // ?
        return httpclient.execute(request, httpContext);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}