Example usage for java.io UnsupportedEncodingException getLocalizedMessage

List of usage examples for java.io UnsupportedEncodingException getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:org.kuali.mobility.academics.dao.AcademicsDaoJSONImpl.java

public List<Career> getCareers(final Map<String, String> query) {
    List<Career> lCareers = new ArrayList<Career>();

    try {/*w  w w.  jav a2  s . c o m*/
        URLConnection connection = new URL(getCareerUrl()).openConnection();
        InputStream response = connection.getInputStream();

        String jsonData = IOUtils.toString(response, DEFAULT_CHARACTER_SET);

        LOG.debug("JSON Data is: [" + jsonData + "]");

        JSONParser parser = new JSONParser();

        Object rootObj = parser.parse(jsonData);

        JSONObject jsonObject = (JSONObject) rootObj;
        JSONArray jsonTerms = (JSONArray) jsonObject.get("academicCareer");

        for (Object o : jsonTerms) {
            Career career = (Career) getApplicationContext().getBean("careerBean");

            JSONObject jsonTerm = (JSONObject) o;

            if (jsonTerm.get("id") instanceof Long) {
                career.setId(((Long) (jsonTerm.get("id"))).toString());
            } else {
                career.setId((String) jsonTerm.get("id"));
            }
            career.setDescription((String) jsonTerm.get("description"));
            career.setShortDescription((String) jsonTerm.get("shortDescription"));
            lCareers.add(career);
        }
    } catch (UnsupportedEncodingException uee) {
        LOG.error(uee.getLocalizedMessage());
    } catch (IOException ioe) {
        LOG.error(ioe.getLocalizedMessage());
    } catch (ParseException pe) {
        LOG.error(pe.getLocalizedMessage(), pe);
    }

    return lCareers;
}

From source file:edu.cmu.cylab.starslinger.exchange.WebEngine.java

private byte[] doPost(String uri, byte[] requestBody) throws ExchangeException {
    mCancelable = false;/*from w ww.  j  a  v  a 2s  .  co m*/

    // sets up parameters
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "utf-8");
    params.setBooleanParameter("http.protocol.expect-continue", false);

    if (mHttpClient == null) {
        mHttpClient = new CheckedHttpClient(params, mCtx);
    }
    HttpPost httppost = new HttpPost(uri);
    BasicResponseHandler responseHandler = new BasicResponseHandler();
    byte[] reqData = null;
    HttpResponse response = null;
    long startTime = SystemClock.elapsedRealtime();
    int statCode = 0;
    String statMsg = "";
    String error = "";

    try {
        // Execute HTTP Post Request
        httppost.addHeader("Content-Type", "application/octet-stream");
        httppost.setEntity(new ByteArrayEntity(requestBody));
        response = mHttpClient.execute(httppost);
        reqData = responseHandler.handleResponse(response).getBytes("8859_1");

    } catch (UnsupportedEncodingException e) {
        error = e.getLocalizedMessage() + " (" + e.getClass().getSimpleName() + ")";
    } catch (HttpResponseException e) {
        // this subclass of java.io.IOException contains useful data for
        // users, do not swallow, handle properly
        e.printStackTrace();
        statCode = e.getStatusCode();
        statMsg = e.getLocalizedMessage();
        error = (String.format(mCtx.getString(R.string.error_HttpCode), statCode) + ", \'" + statMsg + "\'");
    } catch (java.io.IOException e) {
        // just show a simple Internet connection error, so as not to
        // confuse users
        e.printStackTrace();
        error = mCtx.getString(R.string.error_CorrectYourInternetConnection);
    } catch (RuntimeException e) {
        error = e.getLocalizedMessage() + " (" + e.getClass().getSimpleName() + ")";
    } catch (OutOfMemoryError e) {
        error = mCtx.getString(R.string.error_OutOfMemoryError);
    } finally {
        long msDelta = SystemClock.elapsedRealtime() - startTime;
        if (response != null) {
            StatusLine status = response.getStatusLine();
            if (status != null) {
                statCode = status.getStatusCode();
                statMsg = status.getReasonPhrase();
            }
        }
        Log.d(TAG, uri + ", " + requestBody.length + "b sent, " + (reqData != null ? reqData.length : 0)
                + "b recv, " + statCode + " code, " + msDelta + "ms");
    }

    if (!TextUtils.isEmpty(error) || reqData == null) {
        throw new ExchangeException(error);
    }
    return reqData;
}

From source file:org.kuali.mobility.academics.dao.AcademicsDaoJSONImpl.java

public List<Term> getTerms(final Map<String, String> query) {
    List<Term> lTerms = new ArrayList<Term>();

    try {// w  ww.j a  v  a  2 s.  c om
        URLConnection connection = new URL(getTermUrl()).openConnection();
        InputStream response = connection.getInputStream();

        String jsonData = IOUtils.toString(response, DEFAULT_CHARACTER_SET);

        LOG.debug("JSON Data is: [" + jsonData + "]");

        JSONParser parser = new JSONParser();

        Object rootObj = parser.parse(jsonData);

        JSONObject jsonObject = (JSONObject) rootObj;
        JSONArray jsonTerms = (JSONArray) jsonObject.get("term");

        for (Object o : jsonTerms) {
            Term term = (Term) getApplicationContext().getBean("termBean");

            JSONObject jsonTerm = (JSONObject) o;

            if (jsonTerm.get("id") instanceof Long) {
                term.setId(((Long) (jsonTerm.get("id"))).toString());
            } else {
                term.setId((String) jsonTerm.get("id"));
            }
            term.setDescription((String) jsonTerm.get("description"));
            term.setShortDescription((String) jsonTerm.get("shortDescription"));
            if (jsonTerm.get("active") instanceof Boolean) {
                term.setActive(((Boolean) jsonTerm.get("active")).booleanValue());
            } else {
                term.setActive(Boolean.parseBoolean((String) jsonTerm.get("active")));
            }
            lTerms.add(term);
        }
    } catch (UnsupportedEncodingException uee) {
        LOG.error(uee.getLocalizedMessage());
    } catch (IOException ioe) {
        LOG.error(ioe.getLocalizedMessage());
    } catch (ParseException pe) {
        LOG.error(pe.getLocalizedMessage(), pe);
    }

    return lTerms;
}

From source file:com.sastix.cms.server.services.content.impl.ZipFileHandlerServiceImpl.java

@Override
public String findParentResource(Map<String, byte[]> bytesMap) {
    byte[] dataXml = bytesMap.get(METADATA_XML_FILE);
    if (dataXml == null) {
        return null;
    }// ww  w .  ja v a2  s.com
    String xml = "";
    String ret = "";
    try {
        xml = new String(dataXml, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        LOG.error("Error in finding parent resource name: {}", e.getLocalizedMessage());
    }
    Document doc = Jsoup.parse(xml, "", Parser.xmlParser());
    for (Element e : doc.select("resources")) {
        ret = e.select("resource").get(0).attr("href");
    }
    return ret;
}

From source file:com.sastix.cms.server.services.content.impl.ZipFileHandlerServiceImpl.java

@Override
public boolean isScormType(Map<String, byte[]> bytesMap) {
    byte[] dataXml = bytesMap.get(METADATA_XML_FILE);
    if (dataXml == null) {
        return false;
    } else {//from w  w w .j av  a 2  s  . com
        String xml = "";
        String ret = "";
        try {
            xml = new String(dataXml, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            LOG.error("Error in determining if it is a scorm type: {}", e.getLocalizedMessage());
        }
        Document doc = Jsoup.parse(xml, "", Parser.xmlParser());
        for (Element e : doc.select("resources")) {
            ret = e.select("resource").get(0).attr("adlcp:scormType");
        }
        return ret.equals("sco");
    }
}

From source file:com.sastix.cms.server.services.content.impl.ZipFileHandlerServiceImpl.java

@Override
public String getResourceStartPage(Map<String, byte[]> bytesMap) {
    byte[] dataJson = bytesMap.get(METADATA_JSON_FILE);
    String json = "";
    if (dataJson == null) {
        return null;
    }//w  w w  . j a  v  a2 s  .c o m
    try {
        json = new String(dataJson, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        LOG.error("Error in determining if it is a cms zip resource: {}", e.getLocalizedMessage());
        return null;
    }

    Map<String, Object> map = gsonJsonParser.parseMap(json);

    String ret = null;
    if (map.get(METADATA_STARTPAGE) != null) {
        ret = (String) map.get(METADATA_STARTPAGE);
    } else if (map.get(METADATA_STARTPAGE_CAMEL) != null) {
        ret = (String) map.get(METADATA_STARTPAGE_CAMEL);
    }

    return ret;
}

From source file:org.kuali.mobility.news.service.NewsServiceImpl.java

@Override
@GET//from  w  w  w.  java 2s  . c om
@Path("/source/{sourceId}/article/{articleId}")
public NewsArticleImpl getNewsArticle(@PathParam("articleId") final String articleId,
        @PathParam("sourceId") final long sourceId) {
    NewsArticleImpl foundArticle = null;
    LOG.debug("Looking for article id " + articleId);
    NewsSource source = getNewsSourceById(sourceId);
    NewsArticleTransform transform = new NewsArticleTransform();
    for (NewsArticle article : source.getArticles()) {
        LOG.debug("Comparing with: " + article.getArticleId());
        String id;
        try {
            id = URLDecoder.decode(article.getArticleId(), "UTF-8");
            //            if (articleId.equals(id)) {
            //               return article.copy();
            //            }
            if (articleId.equalsIgnoreCase(id) || articleId.equalsIgnoreCase(article.getArticleId())) {
                foundArticle = transform.transform(article);
                break;
            }
        } catch (UnsupportedEncodingException e) {
            LOG.error(e.getLocalizedMessage());
        }
    }
    return foundArticle;
}

From source file:com.fourspaces.couchdb.test.ViewTest.java

private void assertEncodedEquals(final String key, final String expected, final String actual) {
    try {/*from w w  w . j  a va2s. c o m*/
        assertEquals(key + "=" + URLEncoder.encode(expected, "UTF-8"), actual);
    } catch (final UnsupportedEncodingException e) {
        fail(e.getLocalizedMessage());
    }
}

From source file:eu.codeplumbers.cosi.api.tasks.CheckDesignDocumentsTask.java

private String createDesignDocument(String docType) {
    String returnResult = "";
    JSONObject docTypeMap = new JSONObject();
    try {/*from  www .  j  a  v  a  2 s  .c o m*/
        docTypeMap.put("map", "function (doc) { if (doc.docType.toLowerCase() === '" + docType
                + "') { filter = function (doc) { return emit(doc._id, doc); }; filter(doc); }}");

        URL urlO = getCosiUrl(docType);

        String requestMethod = "PUT";

        HttpURLConnection conn = (HttpURLConnection) urlO.openConnection();
        conn.setConnectTimeout(5000);
        conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
        conn.setRequestProperty("Authorization", authHeader);
        conn.setDoOutput(true);
        conn.setDoInput(true);

        conn.setRequestMethod(requestMethod);

        // set request body
        OutputStream os = conn.getOutputStream();
        os.write(docTypeMap.toString().getBytes("UTF-8"));
        os.flush();

        // read the response
        InputStream in = new BufferedInputStream(conn.getInputStream());

        StringWriter writer = new StringWriter();
        IOUtils.copy(in, writer, "UTF-8");
        String result = writer.toString();

        if (result.contains("success")) {
            returnResult = "";
        } else {
            returnResult = result;
        }

        in.close();
        conn.disconnect();

    } catch (UnsupportedEncodingException e) {
        returnResult = e.getLocalizedMessage();
        e.printStackTrace();
    } catch (ProtocolException e) {
        returnResult = e.getLocalizedMessage();
        e.printStackTrace();
    } catch (IOException e) {
        returnResult = e.getLocalizedMessage();
        e.printStackTrace();
    } catch (JSONException e) {
        returnResult = e.getLocalizedMessage();
        e.printStackTrace();
    }

    return returnResult;
}

From source file:org.kuali.mobility.news.service.NewsServiceImpl.java

@Override
@GET//www  . jav  a 2 s  .  c o m
@Path("/articles")
public NewsArticleImpl getNewsArticle(@QueryParam("articleId") final String articleId) {
    NewsArticleImpl foundArticle = null;
    LOG.debug("Looking for article id " + articleId);
    NewsArticleTransform transform = new NewsArticleTransform();
    for (NewsSource source : getDao().findAllActiveNewsSources()) {
        if (source.getArticles() != null && source.getArticles().size() > 0) {
            for (NewsArticle article : source.getArticles()) {
                LOG.debug("Comparing with: " + article.getArticleId());
                String id;
                try {
                    id = URLDecoder.decode(article.getArticleId(), "UTF-8");
                    if (articleId.equalsIgnoreCase(id) || articleId.equalsIgnoreCase(article.getArticleId())) {
                        foundArticle = transform.transform(article);
                        break;
                    }
                } catch (UnsupportedEncodingException e) {
                    LOG.error(e.getLocalizedMessage());
                }
            }
        }
    }
    return foundArticle;
}