Example usage for java.lang Exception toString

List of usage examples for java.lang Exception toString

Introduction

In this page you can find the example usage for java.lang Exception toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.mymed.android.myjam.controller.CallManager.java

public static CallManager getInstance(Context context) {
    if (instance == null)
        try {//w ww.ja  v a2  s  .  c  om
            instance = new CallManager(context);
        } catch (Exception e) {
            Log.d(TAG, e.toString());
        }
    return instance;
}

From source file:azureml_besapp.AzureML_BESApp.java

/**
 * Call REST API to submit job to Azure ML for batch predictions
 * @return response from the REST API// w w  w.  ja v a  2 s  . co  m
 */
public static String besHttpPost() {

    HttpPost post;
    HttpClient client;
    StringEntity entity;

    try {
        // create HttpPost and HttpClient object
        post = new HttpPost(apiurl);
        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 " + apikey));
        post.setEntity(entity);

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

        jobId = EntityUtils.toString(authResponse.getEntity()).replaceAll("\"", "");

        return jobId;

    } catch (Exception e) {

        return e.toString();
    }

}

From source file:com.quietlycoding.android.reader.util.api.Authentication.java

/**
 * This method returns back to the caller a proper authentication token to
 * use with the other API calls to Google Reader.
 * /* w  w w.  j  a v  a2  s.  c  o m*/
 * @param user
 *            - the Google username
 * @param pass
 *            - the Google password
 * @return sid - the returned authentication token for use with the API.
 * 
 */
public static String getAuthToken(String user, String pass) {
    final NameValuePair username = new BasicNameValuePair("Email", user);
    final NameValuePair password = new BasicNameValuePair("Passwd", pass);
    final NameValuePair service = new BasicNameValuePair("service", "reader");
    final List<NameValuePair> pairs = new ArrayList<NameValuePair>();
    pairs.add(username);
    pairs.add(password);
    pairs.add(service);

    try {
        final DefaultHttpClient client = new DefaultHttpClient();
        final HttpPost post = new HttpPost(AUTH_URL);
        final UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs);

        post.setEntity(entity);

        final HttpResponse response = client.execute(post);
        final HttpEntity respEntity = response.getEntity();

        Log.d(TAG, "Server Response: " + response.getStatusLine());

        final InputStream in = respEntity.getContent();
        final BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;
        String result = null;

        while ((line = reader.readLine()) != null) {
            if (line.startsWith("SID")) {
                result = line.substring(line.indexOf("=") + 1);
            }
        }

        reader.close();
        client.getConnectionManager().shutdown();

        return result;
    } catch (final Exception e) {
        Log.d(TAG, "Exception caught:: " + e.toString());
        return null;
    }
}

From source file:org.artags.android.app.stackwidget.util.HttpUtils.java

public static Bitmap loadBitmap(String url) {
    try {//from   ww w.ja v a 2  s.c  om
        final HttpClient httpClient = getHttpClient();
        final HttpResponse resp = httpClient.execute(new HttpGet(url));
        final HttpEntity entity = resp.getEntity();

        final int statusCode = resp.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK || entity == null) {
            return null;
        }

        final byte[] respBytes = EntityUtils.toByteArray(entity);
        // Decode the bytes and return the bitmap.
        BitmapFactory.Options decodeOptions = new BitmapFactory.Options();
        decodeOptions.inSampleSize = 1;
        return BitmapFactory.decodeByteArray(respBytes, 0, respBytes.length, decodeOptions);
    } catch (Exception e) {
        Log.w(TAG, "Problem while loading image: " + e.toString(), e);
    }
    return null;

}

From source file:alfio.model.modification.AdminReservationModification.java

public static String summary(AdminReservationModification src) {
    try {/*from   ww w  .jav  a 2 s .co  m*/
        List<TicketsInfo> ticketsInfo = src.ticketsInfo.stream().map(ti -> {
            List<Attendee> attendees = ti.getAttendees().stream()
                    .map(a -> new Attendee(a.ticketId, placeholderIfNotEmpty(a.firstName),
                            placeholderIfNotEmpty(a.lastName), placeholderIfNotEmpty(a.emailAddress),
                            a.language, a.reassignmentForbidden, a.reference,
                            singletonMap("hasAdditionalInfo",
                                    singletonList(String.valueOf(a.additionalInfo.isEmpty())))))
                    .collect(toList());
            return new TicketsInfo(ti.getCategory(), attendees, ti.isAddSeatsIfNotAvailable(),
                    ti.isUpdateAttendees());
        }).collect(toList());
        return Json.toJson(
                new AdminReservationModification(src.expiration, summaryForCustomerData(src.customerData),
                        ticketsInfo, src.getLanguage(), src.updateContactData, src.notification));
    } catch (Exception e) {
        return e.toString();
    }
}

From source file:controllers.api.v2.Dataset.java

public static Promise<Result> getComplianceDataTypes() {
    try {/*from ww  w.  j a va 2  s  .  co  m*/
        return Promise.promise(() -> ok(Json.newObject().set("complianceDataTypes",
                Json.toJson(DATA_TYPES_DAO.getAllComplianceDataTypes()))));
    } catch (Exception e) {
        Logger.error("Fail to get compliance data types", e);
        return Promise.promise(() -> notFound("Fetch data Error: " + e.toString()));
    }
}

From source file:com.googlecode.spektom.gcsearch.utils.EasySSLProtocolSocketFactory.java

private static SSLContext createEasySSLContext() {
    try {// w w w.j  a  v  a2s  .  com
        SSLContext context = SSLContext.getInstance("SSL");
        context.init(null, new TrustManager[] { new EasyX509TrustManager(null) }, null);
        return context;
    } catch (Exception e) {
        throw new HttpClientError(e.toString());
    }
}

From source file:com.symbian.driver.core.cmdline.CleanCmdLine.java

/**
 * @throws ParseException//from ww w .j  a  va 2  s .c  o m
 */
private static void cleanJobsRepository() throws ParseException {
    Utils.recusiveDelete(TDConfig.getInstance().getPreferenceFile(TDConfig.JOBS_FOLDER));
    //clear job counter.
    try {
        JobCounter jobCounter = new JobCounter();
        if (jobCounter.needRestore()) {
            LOGGER.info("Reset Job counter to 0.");
            jobCounter.reset();
            jobCounter.takeSnapshot();
        }
    } catch (Exception e) {
        LOGGER.warning("error to reset job count." + e.toString());
    }
}

From source file:controllers.api.v2.Dataset.java

public static Promise<Result> listDatasets(@Nullable String platform, @Nonnull String prefix) {
    try {/*from   www  .  j  av  a2 s .  c  o m*/
        int page = NumberUtils.toInt(request().getQueryString("page"), 0);
        int start = page * _dataset_search_page_size;

        return Promise.promise(() -> ok(Json.toJson(
                DATASET_VIEW_DAO.listDatasets(platform, "PROD", prefix, start, _dataset_search_page_size))));
    } catch (Exception e) {
        Logger.error("Fail to list datasets", e);
        return Promise.promise(() -> internalServerError("Fetch data Error: " + e.toString()));
    }
}

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

public static MyMessage post(String url, String data) {
    // TODO Auto-generated method stub
    CommonUtil.printLog("ums", url);
    String returnContent = "";
    MyMessage message = new MyMessage();
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url);
    try {/*from  w  w w.  j  a v  a  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());
        returnContent = URLDecoder.decode(returnXML);
        switch (status) {
        case 200:
            message.setFlag(true);
            message.setMsg(returnContent);
            break;

        default:
            Log.e("error", status + returnContent);
            message.setFlag(false);
            message.setMsg(returnContent);
            break;
        }
    } catch (Exception e) {
        JSONObject jsonObject = new JSONObject();

        try {
            jsonObject.put("err", e.toString());
            returnContent = jsonObject.toString();
            message.setFlag(false);
            message.setMsg(returnContent);
        } catch (JSONException e1) {
            e1.printStackTrace();
        }

    }
    CommonUtil.printLog("UMSAGENT", message.getMsg());
    return message;
}