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.PreprocessingTestBase.java

/**
 * Test preprocessing raw statistic data.
 *
 * @param dataXml                 The preprocessing-information xml.
 * @param aggregationDefinitionId The id of the aggregationDefinition to preprocess.
 * @return The created item.//from   w ww .j  a  v a  2 s.co m
 * @throws Exception If anything fails.
 */
public String preprocess(final String aggregationDefinitionId, final String dataXml) throws Exception {

    Object result = getPreprocessingClient().preprocess(aggregationDefinitionId, 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:Main.java

public static void PostRequest(String url, Map<String, String> params, String userName, String password,
        Handler messageHandler) {
    HttpPost postMethod = new HttpPost(url);
    List<NameValuePair> nvps = null;
    DefaultHttpClient client = new DefaultHttpClient();

    if ((userName != null) && (userName.length() > 0) && (password != null) && (password.length() > 0)) {
        client.getCredentialsProvider().setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials(userName, password));
    }/*from   w w  w  .  j  a v  a  2  s.c o  m*/

    final Map<String, String> sendHeaders = new HashMap<String, String>();
    sendHeaders.put(CONTENT_TYPE, MIME_FORM_ENCODED);

    client.addRequestInterceptor(new HttpRequestInterceptor() {
        @Override
        public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
            for (String key : sendHeaders.keySet()) {
                if (!request.containsHeader(key)) {
                    request.addHeader(key, sendHeaders.get(key));
                }
            }
        }
    });

    if ((params != null) && (params.size() > 0)) {
        nvps = new ArrayList<NameValuePair>();
        for (String key : params.keySet()) {
            nvps.add(new BasicNameValuePair(key, params.get(key)));
        }
    }
    if (nvps != null) {
        try {
            postMethod.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    ExecutePostRequest(client, postMethod, GetResponseHandlerInstance(messageHandler));
}

From source file:com.oplay.nohelper.volley.toolbox.JsonRequest.java

public static String getParamsString(Map<String, String> params) {
    try {/* w  ww  .  jav  a  2s .  c  o  m*/
        if (params == null || params.size() == 0) {
            return "";
        }
        final Iterator<String> keySet = params.keySet().iterator();
        final StringBuilder sb = new StringBuilder();
        while (keySet.hasNext()) {
            final String key = keySet.next();
            final String val = params.get(key);
            if (val != null) {
                sb.append(key).append("=").append(URLEncoder.encode(val, HTTP.UTF_8));
                if (keySet.hasNext()) {
                    sb.append("&");
                }
            }
        }
        return sb.toString();
    } catch (Throwable e) {
    }
    return "";
}

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

/**
 * Test creating aggregationDefinition./*w  w  w .ja  v  a2 s  . c  om*/
 *
 * @param dataXml The xml representation of the aggregationDefinition.
 * @return The created aggregationDefinition.
 * @throws Exception If anything fails.
 */
@Override
public String create(final String dataXml) throws Exception {

    Object result = getAggregationDefinitionClient().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:org.bishoph.oxdemo.util.GetTaskList.java

@Override
protected JSONObject doInBackground(Object... params) {
    try {//from  www. j a v a 2s.  c om
        String uri = (String) params[0];
        Log.v("OXDemo", "Attempting to get task list " + uri);
        HttpGet httpget = new HttpGet(uri);
        httpget.setHeader("Accept", "application/json, text/javascript");
        HttpResponse response = httpclient.execute(httpget, localcontext);
        HttpEntity entity = response.getEntity();
        String result = EntityUtils.toString(entity, HTTP.UTF_8);
        Log.d("OXDemo", "<<<<<<<\n" + result + "\n\n");
        JSONObject jsonObj = new JSONObject(result);
        return jsonObj;
    } catch (JSONException e) {
        Log.e("OXDemo", e.getMessage());
    } catch (ClientProtocolException e) {
        Log.e("OXDemo", e.getMessage());
    } catch (IOException e) {
        Log.e("OXDemo", e.getMessage());
    }
    return null;
}

From source file:org.peterbaldwin.vlcremote.net.ServerConnectionTest.java

@Override
protected Integer doInBackground(Server... servers) {
    if (servers == null || servers.length != 1) {
        return -1;
    }/*from w w w . ja v  a2  s . c o m*/
    URL url;
    try {
        url = new URL("http://" + servers[0].getUri().getAuthority() + TEST_PATH);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setConnectTimeout(1000);
        try {
            Header auth = BasicScheme.authenticate(
                    new UsernamePasswordCredentials(servers[0].getUser(), servers[0].getPassword()), HTTP.UTF_8,
                    false);
            connection.setRequestProperty(auth.getName(), auth.getValue());
            return connection.getResponseCode();
        } finally {
            connection.disconnect();
        }
    } catch (IOException ex) {

    }
    return -1;
}

From source file:com.wbtech.ums.common.NetworkUitlity.java

public static String Post(String url, String data) {

    CommonUtil.printLog("ums", url);

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url);
    try {//from  w ww.j  a  va 2s  .  c  o m
        StringEntity se = new StringEntity("content=" + data, HTTP.UTF_8);
        CommonUtil.printLog("postdata", "content=" + data);
        se.setContentType("application/x-www-form-urlencoded");
        httppost.setEntity(se);
        HttpResponse response = httpclient.execute(httppost);
        int status = response.getStatusLine().getStatusCode();
        CommonUtil.printLog("ums", status + "");
        String returnXML = EntityUtils.toString(response.getEntity());
        Log.d("returnString", URLDecoder.decode(returnXML));
        return URLDecoder.decode(returnXML);

    } catch (Exception e) {
        CommonUtil.printLog("ums", e.toString());
    }
    return null;
}

From source file:com.neu.bigdata.service.PredictionService.java

private String rrsHttpPost() {

    HttpPost post;/*w  w w  . j a  v  a2 s.co  m*/
    HttpClient client;
    StringEntity entity;
    String response = "";

    try {
        // create HttpPost and HttpClient object
        post = new HttpPost(API_URL);
        client = HttpClientBuilder.create().build();

        // setup output message by copying JSON body into 
        // apache StringEntity object along with content type
        entity = new StringEntity(jsonBody, HTTP.UTF_8);
        entity.setContentEncoding(HTTP.UTF_8);
        entity.setContentType("text/json");

        // add HTTP headers
        post.setHeader("Accept", "text/json");
        post.setHeader("Accept-Charset", "UTF-8");

        // set Authorization header based on the API key
        post.setHeader("Authorization", ("Bearer " + API_KEY));
        post.setEntity(entity);

        // Call REST API and retrieve response content
        HttpResponse authResponse = client.execute(post);
        response = EntityUtils.toString(authResponse.getEntity());

        return response;

    } catch (Exception e) {

        return e.toString();
    }

}

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/*from  www  .  j a v  a  2s.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:no.norrs.projects.andronary.service.utils.HttpUtil.java

public static HttpResponse POST(String uri, List<NameValuePair> data) throws IOException {
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(uri);
    //httpPost.addHeader("Accept", "application/json");
    httpPost.addHeader("Content-Type", "application/json; charset=utf-8");
    httpPost.addHeader("User-Agent", "Andronary/0.1");
    httpPost.addHeader("Connection", "close");
    StringEntity e = new StringEntity(data.get(0).getValue(), HTTP.UTF_8);
    //httpPost.setEntity(new UrlEncodedFormEntity(data));
    httpPost.setEntity(e);//from   w w w  .  j a v  a2  s  . c o  m
    HttpResponse response;

    return httpClient.execute(httpPost);

    //return response.getStatusLine().getStatusCode();

    /*HttpEntity entity = response.getEntity();
    return entity.getContent();*/

}