Example usage for java.io UnsupportedEncodingException printStackTrace

List of usage examples for java.io UnsupportedEncodingException printStackTrace

Introduction

In this page you can find the example usage for java.io UnsupportedEncodingException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.thed.zapi.cloud.sample.FetchExecuteUpdate.java

private static String[] getIssuesByJQL(String issueSearchURL, String userName, String password,
        JSONObject jqlJsonObj) throws JSONException {

    byte[] bytesEncoded = Base64.encodeBase64((userName + ":" + password).getBytes());
    String authorizationHeader = "Basic " + new String(bytesEncoded);
    Header header = new BasicHeader(HttpHeaders.AUTHORIZATION, authorizationHeader);

    String[] issueIds = new String[jqlJsonObj.getInt("maxResults")];

    StringEntity jqlJSON = null;/*from  w  w w  .  j  ava2  s  .  c om*/
    try {
        jqlJSON = new StringEntity(jqlJsonObj.toString());
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
    }

    HttpResponse response = null;
    HttpClient restClient = new DefaultHttpClient();
    try {
        // System.out.println(issueSearchURL);
        HttpPost createProjectReq = new HttpPost(issueSearchURL);
        createProjectReq.addHeader(header);
        createProjectReq.addHeader("Content-Type", "application/json");
        createProjectReq.setEntity(jqlJSON);

        response = restClient.execute(createProjectReq);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    int statusCode = response.getStatusLine().getStatusCode();
    // System.out.println(statusCode);

    if (statusCode >= 200 && statusCode < 300) {
        HttpEntity entity1 = response.getEntity();
        String string1 = null;
        try {
            string1 = EntityUtils.toString(entity1);
        } catch (ParseException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.println(string1);
        JSONObject allIssues = new JSONObject(string1);
        JSONArray IssuesArray = allIssues.getJSONArray("issues");
        //         System.out.println(IssuesArray.length());
        if (IssuesArray.length() == 0) {
            return issueIds;
        }

        for (int j = 0; j < IssuesArray.length(); j++) {
            JSONObject jobj = IssuesArray.getJSONObject(j);
            String issueId = jobj.getString("id");
            issueIds[j] = issueId;
        }
    }
    return issueIds;
}

From source file:com.permpings.utils.facebook.sdk.Util.java

public static String encodeUrl(Bundle parameters) {
    if (parameters == null) {
        return "";
    }/*from  w  w  w .  ja va 2 s.  co m*/

    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (String key : parameters.keySet()) {
        Object parameter = parameters.get(key);
        if (!(parameter instanceof String)) {
            continue;
        }

        if (first)
            first = false;
        else
            sb.append("&");
        try {
            sb.append(URLEncoder.encode(key, HTTP.UTF_8) + "="
                    + URLEncoder.encode(parameters.getString(key), HTTP.UTF_8));
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return sb.toString();
}

From source file:com.escabe.TraktApi.java

private static Object getDataFromJSON(String url, boolean login, String type) {
    url = baseurl + url;// www . j  av a  2s . c  om
    url = url.replaceAll("%k", apikey);
    url = url.replaceAll("%u", username);

    HttpClient httpclient = new DefaultHttpClient();
    if (login) {
        HttpPost httppost = new HttpPost(url);
        JSONObject jsonpost = new JSONObject();
        try {
            jsonpost.put("username", username);
            jsonpost.put("password", password);
            httppost.setEntity(new StringEntity(jsonpost.toString()));
            String response = httpclient.execute(httppost, new BasicResponseHandler());
            if (type == "array") {
                return new JSONArray(response);
            } else {
                return new JSONObject(response);
            }
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else { // No login
        HttpGet httpget = new HttpGet(url);
        try {
            String response = httpclient.execute(httpget, new BasicResponseHandler());
            if (type == "array") {
                return new JSONArray(response);
            } else {
                return new JSONObject(response);
            }
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return null;

}

From source file:foam.zizim.android.net.BoskoiHttpClient.java

public static HttpResponse PostURL(String URL, List<NameValuePair> data, String Referer) throws IOException {
    BoskoiService.httpRunning = true;//from   w w w.jav  a 2 s.c  o  m
    //Dipo Fix
    try {
        //wrap try around because this constructor can throw Error 
        final HttpPost httpost = new HttpPost(URL);
        //org.apache.http.client.methods.
        if (Referer.length() > 0) {
            httpost.addHeader("Referer", Referer);
        }
        if (data != null) {
            try {
                //NEED THIS NOW TO FIX ERROR 417
                httpost.getParams().setBooleanParameter("http.protocol.expect-continue", false);
                httpost.setEntity(new UrlEncodedFormEntity(data, HTTP.UTF_8));
            } catch (final UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                BoskoiService.httpRunning = false;
                return null;
            }
        }

        // Post, check and show the result (not really spectacular, but works):
        try {
            HttpResponse response = BoskoiService.httpclient.execute(httpost);
            BoskoiService.httpRunning = false;
            return response;

        } catch (final Exception e) {

        }
    } catch (final Exception e) {
        e.printStackTrace();
    }

    BoskoiService.httpRunning = false;
    return null;
}

From source file:br.com.itfox.utils.Utils.java

public static String encodeURIComponent(String url) {
    String result = "";
    try {// www. j a va 2 s. com
        result = URLEncoder.encode(url, "UTF-8").replaceAll("\\+", "%20").replaceAll("\\%21", "!")
                .replaceAll("\\%27", "'").replaceAll("\\%28", "(").replaceAll("\\%29", ")")
                .replaceAll("\\%7E", "~");
        //the slow option:
        //new ScriptEngineManager().getEngineByName("JavaScript")...etc
    } catch (UnsupportedEncodingException e) {
        //never
        e.printStackTrace();
    }
    return result;
}

From source file:io.cslinmiso.line.utils.Utility.java

/**
 * ??UTF-8/*w  w  w .  ja  v a2 s  . c  o  m*/
 * 
 * @param str
 * @return
 */
public static String unescapeString(String str) {
    String result = null;
    try {
        result = URLDecoder.decode(str, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        System.out.println("" + e.getMessage());
        result = null;
        e.printStackTrace();
    }
    return result;
}

From source file:com.jigsforjava.string.StringUtils.java

public static String urlDecode(String string) {
    try {//from ww w  . j a  va2s. com
        return URLDecoder.decode(string, URL_ENCODING);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    return string;
}

From source file:com.jigsforjava.string.StringUtils.java

public static String urlEncode(String string) {
    try {//from   w ww.  j a  va 2s.c o m
        return URLEncoder.encode(string, URL_ENCODING);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    return string;
}

From source file:org.transdroid.daemon.util.HttpHelper.java

public static String convertStreamToString(InputStream is) {
    try {/*from  www. j  av a2s . c  o  m*/
        return convertStreamToString(is, null);
    } catch (UnsupportedEncodingException e) {
        // Since this is going to use the default encoding, it is never going to crash on an
        // UnsupportedEncodingException
        e.printStackTrace();
        return null;
    }
}

From source file:ca.cmput301w14t09.elasticSearch.ElasticSearchOperations.java

/**
 * updateComment updates the text field of a comment
 * @throws InterruptedException /*from  ww  w .  j ava 2 s. c om*/
 */
public static void updateComment(final Comment comment, final String str)
        throws ClientProtocolException, IOException, InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);

    Thread thread = new Thread() {
        @SuppressWarnings("hiding")
        @Override
        public void run() {
            HttpPost updateRequest = new HttpPost(updateAddress + comment.getUuid() + "/_update/");
            String query = "{\"script\" : \"ctx._source." + str + "}";
            StringEntity stringentity;
            try {
                stringentity = new StringEntity(query);
                updateRequest.setHeader("Accept", "application/json");
                updateRequest.setEntity(stringentity);

                latch.countDown();

            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    };
    thread.start();
    latch.await();
}