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:xj.property.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 ww w .ja  va 2  s . c o m
        StringEntity se = new StringEntity(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;
}

From source file:Main.java

public static void applyProperties(Object o, Element root) {
    Map<String, Object> map = getProperties(root);
    Iterator<String> it = map.keySet().iterator();
    Field[] fields = o.getClass().getFields();
    Method[] methods = o.getClass().getMethods();
    while (it.hasNext()) {
        String name = (String) it.next();
        Object value = map.get(name);
        try {/*  w  w  w .  jav a2s. co m*/
            for (int i = 0; i < fields.length; i++) {
                if (fields[i].getName().equalsIgnoreCase(name)
                        && isTypeMatch(fields[i].getType(), value.getClass())) {
                    fields[i].set(o, value);
                    System.err.println("Set field " + fields

                    [i].getName() + "=" + value);
                    break;
                }
            }
            for (int i = 0; i < methods.length; i++) {
                if (methods[i].getName().equalsIgnoreCase("set" + name) && methods[i].getParameterTypes

                ().length == 1 && isTypeMatch(methods

                [i].getParameterTypes()[0], value.getClass())) {
                    methods[i].invoke(o, new Object[] { value

                    });
                    System.err.println("Set method " + methods

                    [i].getName() + "=" + value);
                    break;
                }
            }
        } catch (Exception e) {
            System.err.println("Unable to apply property '" + name + "': " + e.toString());
        }
    }
}

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

public static Promise<Result> countDatasets(@Nullable String platform, @Nonnull String prefix) {
    try {/*from ww w . jav  a 2s  . com*/
        return Promise.promise(() -> ok(
                String.valueOf(DATASET_VIEW_DAO.listDatasets(platform, "PROD", prefix, 0, 1).getTotal())));
    } catch (Exception e) {
        Logger.error("Fail to count total datasets", e);
        return Promise.promise(() -> internalServerError("Fetch data Error: " + e.toString()));
    }
}

From source file:edu.usc.polar.CoreNLP.java

public static void dir(String path, String[] args) {
    try {/*  w  w w.j  a v a  2s. c  o  m*/

        File root = new File(path);
        if (root.isFile()) {

            if (counter >= 1000 || file == null) {
                counter = 0;
                jsonCount++;
                file = new File("C:\\Users\\Snehal\\Documents\\tikaSimilarityTestSet\\CoreNLP\\NER_" + jsonCount
                        + ".json");
                if (jsonFile != null) {
                    jsonFile.write("{\"NER_CoreNLP\":");
                    jsonFile.write(jsonArray.toJSONString());
                    jsonFile.write("}");
                    //System.out.println(jsonArray.toJSONString());
                    jsonFile.close();
                }
                jsonFile = new FileWriter(file);
                jsonArray = new JSONArray();
            }

            if (!root.getName().equals((".DS_Store"))) {
                StanfordCoreNLP(root.getAbsolutePath(), args);
                counter++;
            }
        } else {
            File[] list = root.listFiles();
            if (list == null) {
                return;
            }
            for (File f : list) {
                if (f.isDirectory()) {
                    dir(f.getAbsolutePath(), args);
                    // System.out.println( "Dir:" + f.getAbsoluteFile() );
                } else {
                    if (counter >= 1000 || file == null) {
                        counter = 0;
                        jsonCount++;
                        file = new File("C:\\Users\\Snehal\\Documents\\tikaSimilarityTestSet\\CoreNLP\\NER_"
                                + jsonCount + ".json");
                        // System.out.print("check"+jsonArray.toJSONString());
                        if (jsonFile != null) {
                            jsonFile.write("{\"NER_CoreNLP\":");
                            jsonFile.write(jsonArray.toJSONString());
                            jsonFile.write("}");
                            //System.out.println(jsonArray.toJSONString());
                            jsonFile.close();
                        }
                        jsonFile = new FileWriter(file);
                        jsonArray = new JSONArray();
                    }

                    if (!f.getName().equals((".DS_Store"))) {
                        StanfordCoreNLP(f.getAbsolutePath(), args);
                        counter++;
                        // add json   
                    }
                }
            }
        }
    } catch (Exception e) {
        e.toString();

    }
}

From source file:msuresh.raftdistdb.TestAtomix.java

private static void InitPortNumber() {
    try {//from   w w w. ja v  a2  s  .c om
        File f = new File(Constants.STATE_LOCATION + "global.info");
        if (!f.exists()) {
            RaftCluster.createDefaultGlobal();
        }
        JSONParser parser = new JSONParser();
        Object obj = parser.parse(new FileReader(Constants.STATE_LOCATION + "global.info"));
        JSONObject jsonObject = (JSONObject) obj;
        Long a = (Long) jsonObject.get("currentCount");
        portId = a.intValue();
    } catch (Exception e) {
        System.out.println(e.toString());
    }
}

From source file:org.artags.android.app.widget.HttpUtils.java

/**
 * Load a bitmap/*from www.  j  av  a 2 s .  com*/
 * @param url The URL
 * @return The bitmap
 */
public static Bitmap loadBitmap(String url) {
    try {
        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:com.jonbanjo.cups.operations.HttpPoster.java

static OperationResult sendRequest(URL url, ByteBuffer ippBuf, InputStream documentStream, final AuthInfo auth)
        throws IOException {

    final OperationResult opResult = new OperationResult();

    if (ippBuf == null) {
        return null;
    }//w  ww.j  av  a 2s  . c  o  m

    if (url == null) {
        return null;
    }

    DefaultHttpClient client = new DefaultHttpClient();

    // will not work with older versions of CUPS!
    client.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
    client.getParams().setParameter("http.socket.timeout", SOCKET_TIMEOUT);
    client.getParams().setParameter("http.connection.timeout", CONNECTION_TIMEOUT);
    client.getParams().setParameter("http.protocol.content-charset", "UTF-8");
    client.getParams().setParameter("http.method.response.buffer.warnlimit", new Integer(8092));
    // probabaly not working with older CUPS versions
    client.getParams().setParameter("http.protocol.expect-continue", Boolean.valueOf(true));

    HttpPost httpPost;

    try {
        httpPost = new HttpPost(url.toURI());
    } catch (Exception e) {
        System.out.println(e.toString());
        return null;
    }

    httpPost.getParams().setParameter("http.socket.timeout", SOCKET_TIMEOUT);

    byte[] bytes = new byte[ippBuf.limit()];
    ippBuf.get(bytes);

    ByteArrayInputStream headerStream = new ByteArrayInputStream(bytes);
    // If we need to send a document, concatenate InputStreams
    InputStream inputStream = headerStream;
    if (documentStream != null) {
        inputStream = new SequenceInputStream(headerStream, documentStream);
    }

    // set length to -1 to advice the entity to read until EOF
    InputStreamEntity requestEntity = new InputStreamEntity(inputStream, -1);

    requestEntity.setContentType(IPP_MIME_TYPE);
    httpPost.setEntity(requestEntity);

    if (auth.reason == AuthInfo.AUTH_REQUESTED) {
        AuthHeader.makeAuthHeader(httpPost, auth);
        if (auth.reason == AuthInfo.AUTH_OK) {
            httpPost.addHeader(auth.getAuthHeader());
            //httpPost.addHeader("Authorization", "Basic am9uOmpvbmJveQ==");
        }
    }

    ResponseHandler<byte[]> handler = new ResponseHandler<byte[]>() {
        @Override
        public byte[] handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
            if (response.getStatusLine().getStatusCode() == 401) {
                auth.setHttpHeader(response.getFirstHeader("WWW-Authenticate"));
            } else {
                auth.reason = AuthInfo.AUTH_OK;
            }
            HttpEntity entity = response.getEntity();
            opResult.setHttResult(response.getStatusLine().toString());
            if (entity != null) {
                return EntityUtils.toByteArray(entity);
            } else {
                return null;
            }
        }
    };

    if (url.getProtocol().equals("https")) {

        Scheme scheme = JfSSLScheme.getScheme();
        if (scheme == null)
            return null;
        client.getConnectionManager().getSchemeRegistry().register(scheme);
    }

    byte[] result = client.execute(httpPost, handler);
    //String test = new String(result);
    IppResponse ippResponse = new IppResponse();

    opResult.setIppResult(ippResponse.getResponse(ByteBuffer.wrap(result)));
    opResult.setAuthInfo(auth);
    client.getConnectionManager().shutdown();
    return opResult;
}

From source file:Main.StaticTools.java

/**
 * Open up a <code> JOptionPane </code> with the given parameters
 * @param source description where the Exception is coming from, used as the header of the Pane
 * @param e the Exception which was thrown, will be prompted as the text of the Pane
 *//*from  w  ww.  j  av a 2 s  .  c  o m*/
public static void errorOut(String source, Exception e) {
    JOptionPane.showMessageDialog(null, "From :" + source + "\nMessage: " + e.toString(), "Error",
            JOptionPane.ERROR_MESSAGE);
}

From source file:BeanUtility.java

/** This method takes a JavaBean and generates a standard toString() type result for it.
 * @param o JavaBean object to stringinate
 * @return STRINGIATION! Stringingating the countryside. Stringinating all the peasants.
 *//*from  ww w  . j a  va  2  s  . c om*/
public static String beanToString(Object o) {
    StringBuffer result = new StringBuffer();
    if (o == null)
        return "--- null";
    result.append("--- begin");
    result.append(o.getClass().getName());
    result.append(" hash: ");
    result.append(o.hashCode());
    result.append("\r\n");
    try {
        PropertyDescriptor[] pds = Introspector.getBeanInfo(o.getClass()).getPropertyDescriptors();
        for (int pdi = 0; pdi < pds.length; pdi++) {
            try {
                result.append(
                        "Property: " + pds[pdi].getName() + " Value: " + pds[pdi].getReadMethod().invoke(o));
            } catch (IllegalAccessException iae) {
                result.append("Property: " + pds[pdi].getName() + " (Illegal Access to Value) ");
            } catch (InvocationTargetException iae) {
                result.append(
                        "Property: " + pds[pdi].getName() + " (InvocationTargetException) " + iae.toString());
            } catch (Exception e) {
                result.append("Property: " + pds[pdi].getName() + " (Other Exception )" + e.toString());
            }
            result.append("\r\n");
        }

    } catch (IntrospectionException ie) {
        result.append("Introspection Exception: " + ie.toString());
        result.append("\r\n");
    }
    result.append("--- end ");
    result.append(o.getClass().getName());
    result.append(" hash: ");
    result.append(o.hashCode());
    result.append("\n");
    return result.toString();
}

From source file:erainformatica.utility.JSONHelper.java

private static TelegramRequestResult<JSONObject> readJsonFromInputStream(InputStream is) {
    try {/*from   w w w  .jav a  2 s.c  om*/
        BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
        TelegramRequestResult<String> jsonText = readAll(rd);
        if (jsonText.isRequestOk()) {
            JSONObject json = new JSONObject(jsonText.get());
            return new TelegramRequestResult<>(true, null, json);
        } else {
            return new TelegramRequestResult<>(false, "Error in parsing", null);
        }
    } catch (Exception e) {
        try {
            is.close();
        } catch (Exception ex) {
        }
        return new TelegramRequestResult<>(false, e.toString(), null);
    }
}