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

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

Introduction

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

Prototype

public synchronized final HttpParams getParams() 

Source Link

Usage

From source file:com.nextgis.maplib.util.NetworkUtil.java

public DefaultHttpClient getHttpClient() {
    /*HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, TIMEOUT_CONNECTION);
    // Set the default socket timeout (SO_TIMEOUT)
    // in milliseconds which is the timeout for waiting for data.
    HttpConnectionParams.setSoTimeout(httpParameters, TIMEOUT_SOKET);
    *///from www  .  j  av  a  2s .  c o m
    DefaultHttpClient HTTPClient = new DefaultHttpClient();//httpParameters);
    HTTPClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, APP_USER_AGENT);
    HTTPClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, TIMEOUT_CONNECTION);
    HTTPClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, TIMEOUT_SOKET);

    return HTTPClient;
}

From source file:org.mobicents.servlet.sip.restcomm.interpreter.http.HttpRequestExecutor.java

public HttpResponseDescriptor execute(final HttpRequestDescriptor request) throws ClientProtocolException,
        IllegalArgumentException, UnsupportedEncodingException, IOException, URISyntaxException {
    int statusCode = -1;
    HttpResponse response = null;//from  ww  w  .j av  a  2 s.  c o m
    HttpRequestDescriptor descriptor = request;
    do {
        final DefaultHttpClient client = new DefaultHttpClient();
        client.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);
        response = new DefaultHttpClient().execute(descriptor.getHttpRequest());
        statusCode = response.getStatusLine().getStatusCode();
        if (isRedirect(statusCode)) {
            final Header locationHeader = response.getFirstHeader("Location");
            if (locationHeader != null) {
                final String redirectLocation = locationHeader.getValue();
                final URI uri = URI.create(redirectLocation);
                descriptor = new HttpRequestDescriptor(uri, descriptor.getMethod(), descriptor.getParameters());
                continue;
            } else {
                break;
            }
        }
    } while (isRedirect(statusCode));
    return response(descriptor, response);
}

From source file:org.gradle.internal.resource.transport.http.HttpClientConfigurer.java

public void configureUserAgent(DefaultHttpClient httpClient) {
    HttpProtocolParams.setUserAgent(httpClient.getParams(), UriResource.getUserAgentString());
}

From source file:org.apache.olingo.samples.client.core.http.SocketFactoryHttpClientFactory.java

@Override
public DefaultHttpClient create(final HttpMethod method, final URI uri) {
    final TrustStrategy acceptTrustStrategy = new TrustStrategy() {
        @Override/* ww  w  .  j a  v  a2s.co  m*/
        public boolean isTrusted(final X509Certificate[] certificate, final String authType) {
            return true;
        }
    };

    final SchemeRegistry registry = new SchemeRegistry();
    try {
        final SSLSocketFactory ssf = new SSLSocketFactory(acceptTrustStrategy,
                SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        registry.register(new Scheme(uri.getScheme(), uri.getPort(), ssf));
    } catch (Exception e) {
        throw new ODataRuntimeException(e);
    }

    final DefaultHttpClient httpClient = new DefaultHttpClient(new BasicClientConnectionManager(registry));
    httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT);

    return httpClient;
}

From source file:com.example.yudiandrean.socioblood.databases.JSONParser.java

public JSONObject getJSONFromUrl(String url, List<NameValuePair> params) {

    // Making HTTP request
    try {//w  ww.j av a 2s  .c  o  m
        // defaultHttpClient
        DefaultHttpClient httpClient = new DefaultHttpClient();
        httpClient.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
        HttpPost httpPost = new HttpPost(url);
        httpPost.setEntity(new UrlEncodedFormEntity(params));

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        json = sb.toString();
        Log.e("JSON", json);
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }

    // try parse the string to a JSON object
    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }

    // return JSON String
    return jObj;

}

From source file:org.apache.nifi.processors.gcp.ProxyAwareTransportFactory.java

@Override
public HttpTransport create() {

    if (proxyConfig == null) {
        return DEFAULT_TRANSPORT;
    }/*w  w  w.ja  v  a 2  s. co m*/

    final Proxy proxy = proxyConfig.createProxy();

    if (Proxy.Type.HTTP.equals(proxy.type()) && proxyConfig.hasCredential()) {
        // If it requires authentication via username and password, use ApacheHttpTransport
        final String host = proxyConfig.getProxyServerHost();
        final int port = proxyConfig.getProxyServerPort();
        final HttpHost proxyHost = new HttpHost(host, port);

        final DefaultHttpClient httpClient = new DefaultHttpClient();
        ConnRouteParams.setDefaultProxy(httpClient.getParams(), proxyHost);

        if (proxyConfig.hasCredential()) {
            final AuthScope proxyAuthScope = new AuthScope(host, port);
            final UsernamePasswordCredentials proxyCredential = new UsernamePasswordCredentials(
                    proxyConfig.getProxyUserName(), proxyConfig.getProxyUserPassword());
            final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(proxyAuthScope, proxyCredential);
            httpClient.setCredentialsProvider(credentialsProvider);
        }

        return new ApacheHttpTransport(httpClient);

    }

    return new NetHttpTransport.Builder().setProxy(proxy).build();
}

From source file:ru.naumen.servacc.test.HTTPProxyConnectionTest.java

private HttpResponse httpGet(String uri, HttpHost proxy) throws IOException {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    return httpClient.execute(new HttpGet(uri));
}

From source file:org.xwiki.contrib.authentication.http.XWikiHTTPAuthenticator.java

private boolean checkAuth(String username, String password, URI uri)
        throws ClientProtocolException, IOException {
    DefaultHttpClient httpClient = new DefaultHttpClient();

    httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "XWik");
    httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000);
    httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000);

    httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials(username, password));

    HttpGet httpget = new HttpGet(uri);
    HttpResponse response = httpClient.execute(httpget);

    return response.getStatusLine().getStatusCode() == HttpStatus.SC_OK;
}

From source file:org.apache.olingo.samples.client.core.http.CustomConnectionsHttpClientFactory.java

@Override
public DefaultHttpClient create(final HttpMethod method, final URI uri) {
    final DefaultHttpClient httpClient = new DefaultHttpClient(new MyClientConnManager());
    httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT);

    return httpClient;
}

From source file:com.data.CheckForDataUpdateTask.java

@Override
protected Object doInBackground(Object[] params) {

    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpParams httpParams = httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, 5000);
    HttpConnectionParams.setSoTimeout(httpParams, 5000);

    BufferedReader in = null;/*ww w.  ja  v  a 2 s  .  c  o m*/
    String line = "";
    try {
        HttpResponse response = httpClient.execute(new HttpGet(Constants.DATA_VERSION_URL));
        in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        line = in.readLine();
    } catch (IOException e) {
        return false;
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                return false;
            }
        }
    }

    int remoteVersion;
    if (line.matches("^DataVersion:\\d+$")) {
        remoteVersion = Integer.parseInt(line.split(":")[1].trim());
    } else {
        return false;
    }
    SharedPreferences spData = ((Activity) params[0]).getApplicationContext().getSharedPreferences("Data", 0);
    int localVersion = spData.getInt("DataVersion", 0);
    spData.edit().putInt("DataVersionRemote", remoteVersion).apply();

    if (remoteVersion > localVersion) {
        return true;
    }
    return false;
}