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:at.ac.univie.isc.asio.integration.IntegrationTest.java

@BeforeClass
public static void restAssuredDefaults() {
    RestAssured.config = RestAssured.config()
            .httpClient(HttpClientConfig.httpClientConfig()
                    .setParam(CoreConnectionPNames.CONNECTION_TIMEOUT, 30_000)
                    .setParam(CoreConnectionPNames.SO_TIMEOUT, 30_000))
            .encoderConfig(EncoderConfig.encoderConfig().defaultContentCharset(Charsets.UTF_8.name()).and()
                    .defaultQueryParameterCharset(Charsets.UTF_8.name()).and()
                    .appendDefaultContentCharsetToContentTypeIfUndefined(false))
            .matcherConfig(/*from   w ww  . j  a  v  a2  s  .c o m*/
                    new MatcherConfig().errorDescriptionType(MatcherConfig.ErrorDescriptionType.HAMCREST))
            .sslConfig(SSLConfig.sslConfig().relaxedHTTPSValidation());
}

From source file:org.codegist.crest.io.http.HttpClientHttpChannelTest.java

@Test
public void setSocketTimeoutShouldSetHttpClientRequestParams() throws IOException {
    HttpParams params = mock(HttpParams.class);
    when(request.getParams()).thenReturn(params);
    toTest.setSocketTimeout(123);//from   w  ww . j a  v  a2s .  co m
    verify(params).setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 123);
}

From source file:com.tejus.shavedog.HttpServer.java

public HttpServer(LocalInetAddressResolver localInetAddressResolver, int listenPort) {
    this.localInetAddressResolver = localInetAddressResolver;

    this.listenPort = listenPort;

    this.handlerRegistry = new HttpRequestHandlerRegistry();

    this.params = new BasicHttpParams();
    this.params.setParameter(CoreProtocolPNames.ORIGIN_SERVER, "4thLineAndroidHttpServer/1.0")
            .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
            .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true);

    if (Util.ANDROID_EMULATOR) {
        // Start immediately on emulator because there will never be a "WiFi switched on" event
        startServer();/*from  w w  w .  jav a  2  s. c  om*/
    }
}

From source file:org.niceday.AsyncHttpPost.java

@Override
public void run() {
    try {/*  w w w .j av  a  2  s  .c  o m*/
        request = new HttpPost(url);
        Log.d(AsyncHttpPost.class.getName(), "AsyncHttpGet  request to url :" + url);
        request.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectTimeout);
        request.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, readTimeout);
        if (parameter != null && parameter.size() > 0) {
            List<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>();
            for (RequestParameter p : parameter) {
                list.add(new BasicNameValuePair(p.getName(), p.getValue()));
            }
            ((HttpPost) request).setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8));
        }
        HttpResponse response = httpClient.execute(request);
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == HttpStatus.SC_OK) {
            ByteArrayOutputStream content = new ByteArrayOutputStream();
            response.getEntity().writeTo(content);
            String ret = new String(content.toByteArray()).trim();
            content.close();
            Object Object = null;
            if (AsyncHttpPost.this.handler != null) {
                Object = AsyncHttpPost.this.handler.handle(ret);
                if (AsyncHttpPost.this.requestCallback != null && Object != null) {
                    AsyncHttpPost.this.requestCallback.onSuccess(Object);
                    return;
                }
                if (Object == null || "".equals(Object.toString())) {
                    RequestException exception = new RequestException(RequestException.IO_EXCEPTION,
                            "");
                    AsyncHttpPost.this.requestCallback.onFail(exception);
                }
            } else {
                AsyncHttpPost.this.requestCallback.onSuccess(ret);
            }
        } else {
            RequestException exception = new RequestException(RequestException.IO_EXCEPTION,
                    "," + statusCode);
            AsyncHttpPost.this.requestCallback.onFail(exception);
        }

        Log.d(AsyncHttpPost.class.getName(), "AsyncHttpGet  request to url :" + url + "  finished !");
    } catch (java.lang.IllegalArgumentException e) {
        RequestException exception = new RequestException(RequestException.IO_EXCEPTION, "");
        AsyncHttpPost.this.requestCallback.onFail(exception);
        Log.d(AsyncHttpGet.class.getName(),
                "AsyncHttpPost  request to url :" + url + "  onFail  " + e.getMessage());
    } catch (org.apache.http.conn.ConnectTimeoutException e) {
        RequestException exception = new RequestException(RequestException.SOCKET_TIMEOUT_EXCEPTION,
                "");
        AsyncHttpPost.this.requestCallback.onFail(exception);
        Log.d(AsyncHttpPost.class.getName(),
                "AsyncHttpGet  request to url :" + url + "  onFail  " + e.getMessage());
    } catch (java.net.SocketTimeoutException e) {
        RequestException exception = new RequestException(RequestException.SOCKET_TIMEOUT_EXCEPTION,
                "");
        AsyncHttpPost.this.requestCallback.onFail(exception);
        Log.d(AsyncHttpPost.class.getName(),
                "AsyncHttpGet  request to url :" + url + "  onFail  " + e.getMessage());
    } catch (UnsupportedEncodingException e) {
        RequestException exception = new RequestException(RequestException.UNSUPPORTED_ENCODEING_EXCEPTION,
                "");
        AsyncHttpPost.this.requestCallback.onFail(exception);
        Log.d(AsyncHttpPost.class.getName(),
                "AsyncHttpGet  request to url :" + url + "  UnsupportedEncodingException  " + e.getMessage());
    } catch (org.apache.http.conn.HttpHostConnectException e) {
        RequestException exception = new RequestException(RequestException.CONNECT_EXCEPTION, "");
        AsyncHttpPost.this.requestCallback.onFail(exception);
        Log.d(AsyncHttpPost.class.getName(),
                "AsyncHttpGet  request to url :" + url + "  HttpHostConnectException  " + e.getMessage());
    } catch (ClientProtocolException e) {
        RequestException exception = new RequestException(RequestException.CLIENT_PROTOL_EXCEPTION,
                "");
        AsyncHttpPost.this.requestCallback.onFail(exception);
        e.printStackTrace();
        Log.d(AsyncHttpPost.class.getName(),
                "AsyncHttpGet  request to url :" + url + "  ClientProtocolException " + e.getMessage());
    } catch (IOException e) {
        RequestException exception = new RequestException(RequestException.IO_EXCEPTION, "");
        AsyncHttpPost.this.requestCallback.onFail(exception);
        e.printStackTrace();
        Log.d(AsyncHttpPost.class.getName(),
                "AsyncHttpGet  request to url :" + url + "  IOException  " + e.getMessage());
    } finally {
        //request.
    }
    super.run();
}

From source file:fr.cph.stock.android.web.Connect.java

protected String connectUrl(String adress) throws IOException {
    String toreturn = null;/*  w w w. j av a2 s  .co m*/
    client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30000);
    client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 60000);
    Log.d(TAG, "adress: " + adress);
    HttpGet get = new HttpGet(adress);
    HttpResponse getResponse = client.execute(get);
    HttpEntity responseEntity = getResponse.getEntity();

    Charset charset = Charset.forName("UTF8");
    InputStreamReader in = new InputStreamReader(responseEntity.getContent(), charset);
    int c = in.read();
    StringBuilder build = new StringBuilder();
    while (c != -1) {
        build.append((char) c);
        c = in.read();
    }
    toreturn = build.toString();
    return toreturn;
}

From source file:uk.ac.ox.oucs.vle.XcriPopulatorInput.java

public void init() {
    // We will have multiple threads using the same httpClient.
    httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager());
    httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "SES Import")
            .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout)
            .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, socketTimeout);
}

From source file:com.aspire.mandou.framework.http.BetterHttpRequestBase.java

@Override
public BetterHttpRequest withTimeout(int timeout) {
    oldTimeout = httpClient.getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT,
            BetterHttp.DEFAULT_SOCKET_TIMEOUT);
    BetterHttp.setSocketTimeout(timeout);
    return this;
}

From source file:org.wso2.carbon.automation.extensions.servers.httpserver.SimpleHttpServer.java

public void start() throws IOException {
    serverSocket = new ServerSocket(port);
    params = new BasicHttpParams();
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT,
            getParameter(CoreConnectionPNames.SO_TIMEOUT, 60000))
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE,
                    getParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024))
            .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK,
                    getParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, 0) == 1)
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY,
                    getParameter(CoreConnectionPNames.TCP_NODELAY, 1) == 1)
            .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "WSO2ESB-Test-Server");
    // Configure HTTP protocol processor
    BasicHttpProcessor httpProcessor = new BasicHttpProcessor();
    httpProcessor.addInterceptor(new ResponseDate());
    httpProcessor.addInterceptor(new ResponseServer());
    httpProcessor.addInterceptor(new ResponseContent());
    httpProcessor.addInterceptor(new ResponseConnControl());
    HttpRequestHandlerRegistry registry = new HttpRequestHandlerRegistry();
    registry.register("*", requestHandler);
    // Set up the HTTP service
    httpService = new HttpService(httpProcessor, new DefaultConnectionReuseStrategy(),
            new DefaultHttpResponseFactory(), registry, params);
    listener = Executors.newSingleThreadExecutor();
    workerPool = Executors.newFixedThreadPool(getParameter("ThreadCount", 2));
    shutdown = false;// w  w w . ja  va 2s .co  m
    listener.submit(new HttpListener());
}

From source file:com.DGSD.DGUtils.Http.BetterHttpRequestBase.java

public BetterHttpRequest withTimeout(int timeout) {
    oldTimeout = httpClient.getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT,
            BetterHttp.DEFAULT_SOCKET_TIMEOUT);
    BetterHttp.setSocketTimeout(timeout);
    return this;
}

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);//from w ww .j  av a  2s.c  om

    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);
}