Example usage for org.apache.http.params HttpProtocolParams setContentCharset

List of usage examples for org.apache.http.params HttpProtocolParams setContentCharset

Introduction

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

Prototype

public static void setContentCharset(HttpParams httpParams, String str) 

Source Link

Usage

From source file:org.bfr.querytools.spectrumbridge.SpectrumBridgeQuery.java

private static HttpClient createClient() {
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
    HttpProtocolParams.setUseExpectContinue(params, true);

    HttpClient client = new DefaultHttpClient(params);

    HttpConnectionParams.setConnectionTimeout(client.getParams(), 10 * 1000);
    HttpConnectionParams.setSoTimeout(client.getParams(), 10 * 1000);

    return client;
}

From source file:playn.android.AndroidNet.java

private void doHttp(final boolean isPost, final String url, final String data,
        final Callback<String> callback) {
    platform.invokeAsync(new Runnable() {
        @Override// w w w  .  jav  a 2 s .c  o m
        public void run() {
            HttpParams params = new BasicHttpParams();
            HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
            HttpProtocolParams.setHttpElementCharset(params, HTTP.UTF_8);
            HttpClient httpclient = new DefaultHttpClient(params);
            HttpRequestBase req = null;
            if (isPost) {
                HttpPost httppost = new HttpPost(url);
                if (data != null) {
                    try {
                        httppost.setEntity(new StringEntity(data, HTTP.UTF_8));
                    } catch (UnsupportedEncodingException e) {
                        platform.notifyFailure(callback, e);
                    }
                }
                req = httppost;
            } else {
                req = new HttpGet(url);
            }
            try {
                HttpResponse response = httpclient.execute(req);
                StatusLine status = response.getStatusLine();
                int code = status.getStatusCode();
                String body = EntityUtils.toString(response.getEntity());
                if (code == HttpStatus.SC_OK) {
                    platform.notifySuccess(callback, body);
                } else {
                    platform.notifyFailure(callback, new HttpException(code, body));
                }
            } catch (Exception e) {
                platform.notifyFailure(callback, e);
            }
        }

        @Override
        public String toString() {
            return "AndroidNet.doHttp(" + isPost + ", " + url + ")";
        }
    });
}

From source file:com.entertailion.android.launcher.utils.HttpRequestHelper.java

public static DefaultHttpClient createHttpClient() {
    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, 60000);
    HttpConnectionParams.setSoTimeout(params, 60000);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
    HttpProtocolParams.setUserAgent(params,
            "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.5 Safari/537.22");

    SchemeRegistry schReg = new SchemeRegistry();
    schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);

    return new DefaultHttpClient(conMgr, params);
}

From source file:org.dasein.security.joyent.DefaultClientFactory.java

@Override
public @Nonnull HttpClient getClient(String endpoint) throws CloudException, InternalException {
    if (providerContext == null) {
        throw new CloudException("No context was defined for this request");
    }//from www.  j a va2s . c o  m

    final HttpParams params = new BasicHttpParams();

    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, Consts.UTF_8.toString());
    HttpProtocolParams.setUserAgent(params, "Dasein Cloud");

    Properties p = providerContext.getCustomProperties();
    if (p != null) {
        String proxyHost = p.getProperty("proxyHost");
        String proxyPortStr = p.getProperty("proxyPort");
        int proxyPort = 0;
        if (proxyPortStr != null) {
            proxyPort = Integer.parseInt(proxyPortStr);
        }
        if (proxyHost != null && proxyHost.length() > 0 && proxyPort > 0) {
            params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(proxyHost, proxyPort));
        }
    }
    DefaultHttpClient client = new DefaultHttpClient(params);
    // Joyent does not support gzip at the moment (7.2), but in case it will
    // in the future we might just leave these here
    client.addRequestInterceptor(new HttpRequestInterceptor() {
        public void process(final HttpRequest request, final HttpContext context)
                throws HttpException, IOException {
            if (!request.containsHeader("Accept-Encoding")) {
                request.addHeader("Accept-Encoding", "gzip");
            }
            request.setParams(params);
        }
    });
    client.addResponseInterceptor(new HttpResponseInterceptor() {
        public void process(final HttpResponse response, final HttpContext context)
                throws HttpException, IOException {
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                Header header = entity.getContentEncoding();
                if (header != null) {
                    for (HeaderElement codec : header.getElements()) {
                        if (codec.getName().equalsIgnoreCase("gzip")) {
                            response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                            break;
                        }
                    }
                }
            }
        }
    });
    return client;
}

From source file:net.oneandone.sushi.fs.webdav.WebdavRoot.java

public WebdavRoot(WebdavFilesystem filesystem, String protocol, String host, int port) {
    this.filesystem = filesystem;
    this.host = new HttpHost(host, port, protocol);
    this.authorization = null;
    this.params = new BasicHttpParams();

    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, WebdavFilesystem.ENCODING);
}

From source file:eu.trentorise.smartcampus.portfolio.utils.HttpClientFactory.java

private final HttpClient createHttpClient() {
    HttpParams httpParams = new BasicHttpParams();
    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(httpParams, HTTP.DEFAULT_CONTENT_CHARSET);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    Scheme httpScheme = new Scheme(HTTP_SCHEMA, PlainSocketFactory.getSocketFactory(), 80);
    schemeRegistry.register(httpScheme);
    Scheme httpsScheme = new Scheme(HTTPS_SCHEMA, SSLSocketFactory.getSocketFactory(), 443);
    schemeRegistry.register(httpsScheme);
    ClientConnectionManager tsConnManager = new ThreadSafeClientConnManager(httpParams, schemeRegistry);
    HttpClient client = new DefaultHttpClient(tsConnManager, httpParams);
    HttpConnectionParams.setSoTimeout(client.getParams(), TIMEOUT);
    HttpConnectionParams.setConnectionTimeout(client.getParams(), TIMEOUT);
    return client;
}

From source file:org.bishoph.oxdemo.util.OXLoginAction.java

public OXLoginAction(OXDemo oxdemo) {
    this.oxdemo = oxdemo;
    if (httpclient == null) {
        CookieStore cookieStore = new BasicCookieStore();
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setContentCharset(params, "UTF-8");
        httpclient = new DefaultHttpClient(params);
        localcontext = new BasicHttpContext();
        localcontext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
    }/*from  w  w w .j a v a2 s  . com*/
}

From source file:eu.mobileguild.HttpClientDelegate.java

public void createHttpClient() {
    Log.d(TAG, "createHttpClient()...");
    HttpParams params = new BasicHttpParams();

    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
    HttpProtocolParams.setUseExpectContinue(params, true);

    SchemeRegistry schReg = new SchemeRegistry();
    schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));

    ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);

    httpClient = new DefaultHttpClient(conMgr, params);
}

From source file:com.entertailion.android.dial.HttpRequestHelper.java

public static DefaultHttpClient createHttpClient() {
    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, 20000);
    HttpConnectionParams.setSoTimeout(params, 20000);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);

    SchemeRegistry schReg = new SchemeRegistry();
    schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);

    return new DefaultHttpClient(conMgr, params);
}

From source file:com.navnorth.learningregistry.LRClient.java

public static HttpClient getHttpClient(String scheme) {

    // TODO: this allows for self-signed certificates, which should just be an option, not used by default.
    if (scheme.equals("https")) {
        try {/*from w w  w.ja  va  2 s . c o m*/
            KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
            trustStore.load(null, null);
            SSLSocketFactory sf = new SelfSignSSLSocketFactory(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", PlainSocketFactory.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();
        }
    } else {
        return new DefaultHttpClient();
    }
}