Example usage for org.apache.http.protocol HTTP UTF_8

List of usage examples for org.apache.http.protocol HTTP UTF_8

Introduction

In this page you can find the example usage for org.apache.http.protocol HTTP UTF_8.

Prototype

String UTF_8

To view the source code for org.apache.http.protocol HTTP UTF_8.

Click Source Link

Usage

From source file:de.escidoc.core.test.sm.ReportTestBase.java

/**
 * Test retrieving an report from the mock framework.
 *
 * @param xml Treport-parameters xml./*from ww w .  j  av  a  2 s .co  m*/
 * @return The retrieved report.
 * @throws Exception If anything fails.
 */
public String retrieve(final String xml) throws Exception {

    Object result = getReportClient().retrieve(xml);
    String xmlResult = null;
    if (result instanceof HttpResponse) {
        HttpResponse httpRes = (HttpResponse) result;
        xmlResult = EntityUtils.toString(httpRes.getEntity(), HTTP.UTF_8);
        assertHttpStatusOfMethod("", httpRes);
    } else if (result instanceof String) {
        xmlResult = (String) result;
    }
    return xmlResult;
}

From source file:cn.keke.travelmix.HttpClientHelper.java

public static HttpClient getNewHttpClient() {
    try {/*w  w  w .j a va  2s.co  m*/
        SSLSocketFactory sf = new EasySSLSocketFactory();

        // TODO test, if SyncBasicHttpParams is needed
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
        HttpProtocolParams.setUseExpectContinue(params, false);
        HttpProtocolParams.setHttpElementCharset(params, HTTP.UTF_8);
        HttpConnectionParams.setConnectionTimeout(params, 10000);
        HttpConnectionParams.setSocketBufferSize(params, 8192);
        HttpConnectionParams.setLinger(params, 1);
        HttpConnectionParams.setStaleCheckingEnabled(params, false);
        HttpConnectionParams.setSoReuseaddr(params, true);
        HttpConnectionParams.setTcpNoDelay(params, true);
        HttpClientParams.setCookiePolicy(params, CookiePolicy.IGNORE_COOKIES);
        HttpClientParams.setAuthenticating(params, false);
        HttpClientParams.setRedirecting(params, false);

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

        ThreadSafeClientConnManager ccm = new ThreadSafeClientConnManager(registry, 20, TimeUnit.MINUTES);
        ccm.setMaxTotal(100);
        ccm.setDefaultMaxPerRoute(20);

        return new DefaultHttpClient(ccm, params);
    } catch (Exception e) {
        LOG.warn("Failed to create custom http client. Default http client is created", e);
        return new DefaultHttpClient();
    }
}

From source file:de.escidoc.core.test.sm.StatisticDataTestBase.java

/**
 * Test creating statistic data.//from   w  ww. j a  v a 2 s  . com
 *
 * @param dataXml The xml representation of the item.
 * @return The created item.
 * @throws Exception If anything fails.
 */
public String create(final String dataXml) throws Exception {

    Object result = getStatisticDataClient().create(dataXml);
    String xmlResult = null;
    if (result instanceof HttpResponse) {
        HttpResponse httpRes = (HttpResponse) result;
        xmlResult = EntityUtils.toString(httpRes.getEntity(), HTTP.UTF_8);
        assertHttpStatusOfMethod("", httpRes);

    } else if (result instanceof String) {
        xmlResult = (String) result;
    }
    return xmlResult;
}

From source file:com.baseproject.volley.NetworkResponse.java

public NetworkResponse(byte[] data) {
    this(HttpStatus.SC_OK, data, "", HTTP.UTF_8, false);
}

From source file:com.jzc.rfid.cl.listeners.RFIDTagGainListener.java

public void tagGained(TagGainEvent tagGainEvent) {
    System.out.println(Main.readerId + " " + tagGainEvent.getValue());
    final String tagValue = tagGainEvent.getValue();
    new Thread(new Runnable() {
        public void run() {
            try {
                List<NameValuePair> qparams = new ArrayList<NameValuePair>();
                qparams.add(new BasicNameValuePair("cardId", tagValue));
                qparams.add(new BasicNameValuePair("readerId", Integer.toString(Main.readerId)));
                String url = "http://www.electric20.com/thermaPref/cardEvent.php";
                HttpPost httpPost = new HttpPost(url);
                httpPost.setEntity(new UrlEncodedFormEntity(qparams, HTTP.UTF_8));
                HttpClient httpClient = new DefaultHttpClient();
                //HttpHost proxy = new HttpHost("mainproxy.nottingham.ac.uk",8080);
                //httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
                httpClient.execute(httpPost);
                httpClient.getConnectionManager().closeExpiredConnections();
                System.out.println(httpPost.getURI());
            } catch (Exception e) {
                e.printStackTrace();/*from   w w w . ja v  a 2s.  c  om*/
            }
        }
    }).start();
    try {
        rfid.setLEDOn(!rfid.getLEDOn());
    } catch (PhidgetException e) {
        e.printStackTrace();
    }
}

From source file:jp.mixi.android.sdk.util.UrlUtils.java

/**
 * Bundle???//from   ww w .jav a2  s  .co m
 * 
 * @param params ?Bundle
 * @return ???String
 */
public static String encodeUrlForBundle(Bundle params) {
    if (params == null) {
        return "";
    }

    StringBuilder builder = new StringBuilder();
    boolean first = true;
    for (String key : params.keySet()) {
        if (first) {
            first = false;
        } else {
            builder.append(PARAM_SEPARATOR);
        }
        try {
            builder.append(URLEncoder.encode(key, HTTP.UTF_8) + EQUAL
                    + URLEncoder.encode(params.getString(key), HTTP.UTF_8));
        } catch (UnsupportedEncodingException e) {
            Log.e(TAG, e.getLocalizedMessage(), e);
        }
    }
    return builder.toString();
}

From source file:org.deviceconnect.android.client.fragment.TextDialogFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    mLogger.entering(getClass().getName(), "onCreateView",
            new Object[] { inflater, container, savedInstanceState });

    View view = inflater.inflate(R.layout.fragment_privacypolicy, null);
    TextView text = (TextView) view.findViewById(android.R.id.text1);

    InputStream is = null;//from   w  w w  . j  a v  a2  s  .c o  m
    try {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        is = getActivity().getResources().openRawResource(getArguments().getInt(Intent.EXTRA_TEXT));
        byte[] buf = new byte[BUFFER_SIZE];
        while (true) {
            int len = is.read(buf);
            if (len < 0) {
                break;
            }
            os.write(buf, 0, len);
        }
        text.setText(new String(os.toByteArray(), HTTP.UTF_8));
    } catch (IOException e) {
        mLogger.warning(e.toString());
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                mLogger.fine(e.toString());
            }
        }
    }

    getDialog().setTitle(getArguments().getInt(Intent.EXTRA_TITLE));

    mLogger.exiting(getClass().getName(), "onCreateView", view);
    return view;
}

From source file:biz.shadowservices.DegreesToolbox.HttpPoster.java

public HttpPoster(URI uri, List<? extends NameValuePair> values) {
    httppost = new HttpPost(uri);
    try {/*from  www  . j  av a 2 s . c  o  m*/
        httppost.setEntity(new UrlEncodedFormEntity(values, HTTP.UTF_8));
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, "Error: Unsupported encoding exception on " + httppost.getURI());
    }
}

From source file:dk.i2m.drupal.DrupalHttpClient.java

DrupalHttpClient(int connectionTimeout, int socketTimeout) {
    BasicHttpParams params = new BasicHttpParams();
    params.setParameter(AllClientPNames.CONNECTION_TIMEOUT, connectionTimeout)
            .setParameter(AllClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH)
            .setParameter(AllClientPNames.HTTP_CONTENT_CHARSET, HTTP.UTF_8)
            .setParameter(AllClientPNames.SO_TIMEOUT, socketTimeout);

    this.setParams(params);
}

From source file:org.andstatus.app.net.http.MisconfiguredSslHttpClientFactory.java

private static HttpParams getHttpParams() {
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
    HttpConnectionParams.setStaleCheckingEnabled(params, true);

    HttpProtocolParams.setUseExpectContinue(params, false);
    HttpConnectionParams.setSoTimeout(params, MyPreferences.getConnectionTimeoutMs());
    HttpConnectionParams.setSocketBufferSize(params, 2 * 8192);
    return params;
}