Example usage for java.io UnsupportedEncodingException toString

List of usage examples for java.io UnsupportedEncodingException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:eionet.webq.converter.CdrRequestConverter.java

@Override
public CdrRequest convert(HttpServletRequest httpRequest) {
    QueriedParametersTracker parametersTracker = new QueriedParametersTracker(httpRequest);

    CdrRequest parameters = new CdrRequest();
    parameters.setContextPath(httpRequest.getContextPath());
    parameters.setEnvelopeUrl(parametersTracker.getParameter("envelope"));
    parameters.setSchema(parametersTracker.getParameter("schema"));
    parameters.setNewFormCreationAllowed(Boolean.valueOf(parametersTracker.getParameter("add")));
    parameters.setNewFileName(parametersTracker.getParameter("file_id"));
    String instanceUrl = parametersTracker.getParameter("instance");
    parameters.setInstanceUrl(instanceUrl);
    if (isNotEmpty(instanceUrl)) {
        int fileNameSeparatorIndex = instanceUrl.lastIndexOf("/");
        parameters.setInstanceName(instanceUrl.substring(fileNameSeparatorIndex + 1));
        if (isEmpty(parameters.getEnvelopeUrl())) {
            parameters.setEnvelopeUrl(instanceUrl.substring(0, fileNameSeparatorIndex));
        }/*from   w  ww  .java 2  s .  c o m*/
    }
    parameters.setInstanceTitle(parametersTracker.getParameter("instance_title"));

    if (StringUtils.isEmpty(parameters.getEnvelopeUrl())
            && StringUtils.isNotEmpty(parameters.getInstanceUrl())) {
        parameters.setEnvelopeUrl(StringUtils.substringBeforeLast(parameters.getInstanceUrl(), "/"));
    }

    parameters.setSessionId(requestBasedUserIdProvider.getUserId(httpRequest));

    String authorizationHeader = httpRequest.getHeader("Authorization");
    if (authorizationAgainstCdrSucceed(httpRequest) && hasBasicAuthorization(authorizationHeader)) {
        try {
            setAuthorizationDetails(parameters, authorizationHeader);
        } catch (UnsupportedEncodingException e) {
            LOGGER.error("Unable to parse authorisation details" + e.toString());
        }
    }
    if (authorizationAgainstCdrSucceed(httpRequest) && !parameters.isAuthorizationSet()
            && httpRequest.getAttribute(CdrAuthorizationInterceptor.PARSED_COOKIES_ATTRIBUTE) != null) {
        parameters.setAuthorizationSet(true);
        parameters.setCookies(
                (String) httpRequest.getAttribute(CdrAuthorizationInterceptor.PARSED_COOKIES_ATTRIBUTE));
    }
    parameters.setAdditionalParametersAsQueryString(createQueryStringFromParametersNotRead(parametersTracker));
    return parameters;
}

From source file:apimanager.ZohoReportsAPIManager.java

public boolean delete(JSONObject urlParams, JSONObject criteria) {

    //  CloseableHttpClient httpclient = HttpClients.createDefault();
    // HttpPost post = new HttpPost("https://reportsapi.zoho.com/api/harshavardhan.r@zohocorp.com/Test/Name_password?ZOHO_ACTION=DELETE&ZOHO_OUTPUT_FORMAT=json&ZOHO_ERROR_FORMAT=json&authtoken=7ed717b94bc30455aad11ce5d31d34f9&ZOHO_API_VERSION=1.0");
    /*try {/*from   w w w.  ja va  2  s  .  c  o  m*/
    List<NameValuePair> nameValuePairs = new ArrayList<>(1);
    nameValuePairs.add(new BasicNameValuePair("ZOHO_CRITERIA",
            "(\"Name\" = 'harshaViaPostimportNet15')"));
    post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            
    HttpResponse response = httpclient.execute(post);
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String line = "";
    while ((line = rd.readLine()) != null) {
        System.out.println(line);
    }
            
    } catch (IOException e) {
    e.printStackTrace();
    }*/

    loggerObj.log(Level.INFO, "Inisde Delete method");
    JSONObject httpPostObjectParams = new JSONObject();

    String emailaddr = (String) urlParams.get("URLEmail");
    String dbName = (String) urlParams.get("DBName");
    String tableName = (String) urlParams.get("TableName");
    String authToken = (String) urlParams.get(AUTHTOKEN);
    String url = "https://reportsapi.zoho.com/api/" + emailaddr + "/" + dbName + "/" + tableName
            + "?ZOHO_ACTION=DELETE&ZOHO_OUTPUT_FORMAT=json&ZOHO_ERROR_FORMAT=json&authtoken=" + authToken
            + "&ZOHO_API_VERSION=1.0";

    loggerObj.log(Level.INFO, "url params are:" + url);
    httpPostObjectParams.put("url", url);

    JSONObject postParams = null;
    List<NameValuePair> nameValuePairs = new ArrayList<>(criteria.size());
    //multiple criteria wont work. Need to test how how multiple criteria has to be given//
    for (Iterator iterator = criteria.keySet().iterator(); iterator.hasNext();) {
        String key = (String) iterator.next();
        nameValuePairs.add(new BasicNameValuePair("ZOHO_CRITERIA",
                "(\"" + key + "\" = '" + (String) criteria.get(key) + "')"));
    }

    UrlEncodedFormEntity formParameters = null;
    try {
        formParameters = new UrlEncodedFormEntity(nameValuePairs);
    } catch (UnsupportedEncodingException ex) {
        loggerObj.log(Level.INFO, "The delete criteria cannot be encoded properly" + ex.toString());
        return false;
    }

    loggerObj.log(Level.INFO, "httpPost form params are:" + nameValuePairs.toString());

    HttpsClient httpsClientObj = new HttpsClient();
    boolean isSuccessfulPost = httpsClientObj.httpsPost(url, null, formParameters);

    return isSuccessfulPost;

}

From source file:com.mellanox.jxio.helloworld.HelloClient.java

public void connect(URI uri) {
    LOG.info("Try to establish a new session to '" + uri + "'");
    this.client = new ClientSession(eqh, uri, new MyClientCallbacks(this));

    Msg msg = this.mp.getMsg();
    try {/* w w w .j  a v  a2  s  . c  o m*/
        msg.getOut().put("Hello Server".getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        // Just suppress the exception handling in this demo code
    }
    try {
        client.sendRequest(msg);
    } catch (IOException e) {
        //all exceptions thrown extend IOException
        LOG.error(e.toString());
    }
}

From source file:com.savvywits.wethepeople.RESTService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();//w ww.j  a va2s.c  o  m
    ResultReceiver receiver = extras.getParcelable("receiver");
    String data = extras.getString("zipcode");
    String url = ZIP_CODE_BASE + data;

    Bundle bundle = new Bundle();
    receiver.send(STATUS_RUNNING, Bundle.EMPTY);
    try {
        String json = EntityUtils.toString(new DefaultHttpClient().execute(new HttpGet(url)).getEntity());

        if (!validateJSON(json)) {
            receiver.send(STATUS_ERROR, Bundle.EMPTY);
        } else {
            bundle.putString("rest_result", json);
            receiver.send(STATUS_FINISHED, bundle);
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        bundle.putString(Intent.EXTRA_TEXT, e.toString());
        receiver.send(STATUS_ERROR, bundle);
    }
}

From source file:com.swdouglass.joid.server.OpenIdServlet.java

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    StringBuilder sb = new StringBuilder();
    Enumeration e = request.getParameterNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        String[] values = request.getParameterValues(name);
        if (values.length == 0) {
            throw new IOException("Empty value not allowed: " + name + " has no value");
        }//from  ww  w. j a v  a  2 s  .c  o  m
        try {
            sb.append(URLEncoder.encode(name, "UTF-8") + "=" + URLEncoder.encode(values[0], "UTF-8"));
        } catch (UnsupportedEncodingException ex) {
            throw new IOException(ex.toString());
        }
        if (e.hasMoreElements()) {
            sb.append("&");
        }
    }
    doQuery(sb.toString(), request, response);
}

From source file:com.gameanalytics.android.BatchThread.java

private void sendEventSet(String json, String category, String eventGameKey, EventList<?> eventList) {
    // Extract bits from eventList
    String eventSecretKey = eventList.getSecretKey();
    ArrayList<Integer> eventsToDelete = eventList.getEventIdList();

    // Game key for these events
    if (eventGameKey == EventDatabase.DEFAULT_GAME_KEY) {
        eventGameKey = this.defaultGameKey;
        eventSecretKey = this.defaultSecretKey;
    }/* ww  w.  jav a2s .c  o m*/

    // Print response if in VERBOSE mode
    GALog.i("Raw JSON for " + category + " events, game key = " + eventGameKey
            + ", events being sent to GA server: " + json);

    // Add auth header
    Header[] headers = new Header[1];
    headers[0] = new BasicHeader(GameAnalytics.AUTHORIZATION, getAuthorizationString(json, eventSecretKey));

    // POST request to server
    StringEntity jsonEntity = null;
    try {
        jsonEntity = new StringEntity(json);
    } catch (UnsupportedEncodingException e) {
        GALog.e("Error converting json String into StringEntity: " + e.toString(), e);
    }

    // Create handler
    PostResponseHandler handler = new PostResponseHandler(eventsToDelete, eventDatabase, category);

    // Send event
    client.post(context, GameAnalytics.API_URL + eventGameKey + category, jsonEntity,
            GameAnalytics.CONTENT_TYPE_JSON, headers, handler);

    // Notify GameAnalytics that new thread should not be sent until handler
    // has finished
    GameAnalytics.sendingEvents(handler);
}

From source file:com.xorcode.andtweet.net.ConnectionOAuth.java

@Override
public JSONObject updateStatus(String message, long inReplyToId) throws ConnectionException {
    HttpPost post = new HttpPost(STATUSES_UPDATE_URL);
    LinkedList<BasicNameValuePair> out = new LinkedList<BasicNameValuePair>();
    out.add(new BasicNameValuePair("status", message));
    if (inReplyToId > 0) {
        out.add(new BasicNameValuePair("in_reply_to_status_id", String.valueOf(inReplyToId)));
    }/*ww  w  .  j  a  va 2s  .  c o m*/
    try {
        post.setEntity(new UrlEncodedFormEntity(out, HTTP.UTF_8));
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, e.toString());
    }
    return postRequest(post);
}

From source file:org.accelio.jxio.simpletest.SimpleClient.java

public void send() {
    Msg msg = this.mp.getMsg();
    try {/* w w  w  . j  ava 2  s . c  o  m*/
        msg.getOut().put("Simple request".getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        // Just suppress the exception handling in this demo code
    }
    try {
        client.sendRequest(msg);
    } catch (IOException e) {
        //all exceptions thrown extend IOException
        LOG.error(e.toString());
    }
}

From source file:com.robertszkutak.androidexamples.tumblrexample.TumblrExampleActivity.java

public void sendPost() {
    String title = posttitle.getText().toString();
    String body = poststring.getText().toString();

    HttpPost hpost = new HttpPost(
            "http://api.tumblr.com/v2/blog/" + blogname.getText().toString() + ".tumblr.com/post");

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    nameValuePairs.add(new BasicNameValuePair("type", "text"));
    nameValuePairs.add(new BasicNameValuePair("title", title));
    nameValuePairs.add(new BasicNameValuePair("body", body));

    try {/*from   w  w  w  . j a  va 2s.  c o  m*/
        hpost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    } catch (UnsupportedEncodingException e) {
        debug += e.toString();
    }

    consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
    consumer.setTokenWithSecret(token, secret);
    try {
        consumer.sign(hpost);
    } catch (OAuthMessageSignerException e) {
        debug += e.toString();
    } catch (OAuthExpectationFailedException e) {
        debug += e.toString();
    } catch (OAuthCommunicationException e) {
        debug += e.toString();
    }

    DefaultHttpClient client = new DefaultHttpClient();
    HttpResponse resp = null;
    try {
        resp = client.execute(hpost);
    } catch (ClientProtocolException e) {
        debug += e.toString();
    } catch (IOException e) {
        debug += e.toString();
    }

    String result = null;
    try {
        result = EntityUtils.toString(resp.getEntity());
    } catch (ParseException e) {
        debug += e.toString();
    } catch (IOException e) {
        debug += e.toString();
    }

    debug += result;
    debugStatus.setText(debug);
}

From source file:me.kaidul.uhunt.JSONDownloader.java

public InputStreamReader getJSONStringFromUrl(String url) {

    try {/*from   ww  w. j  av  a 2 s.co m*/
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();
    } catch (UnsupportedEncodingException e) {

    } catch (ClientProtocolException e) {

    } catch (IOException e) {
    }

    try {
        return new InputStreamReader(is, "UTF-8");
    } catch (Exception e) {
        if (CommonUtils.isDebuggable) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }
        return null;
    }
}