Example usage for java.lang Throwable toString

List of usage examples for java.lang Throwable toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.lucidtechnics.blackboard.util.Jsr223ScriptingUtil.java

public Object execute(String _script) {
    Object result = null;/*from  ww w  .j a va 2 s .com*/

    if (_script == null) {
        throw new RuntimeException("Unable to execute null script");
    }

    ScriptContext scriptContext = getScriptEngine().getContext();

    try {
        result = getScriptEngine().eval(_script, scriptContext);
    } catch (Throwable t) {
        throw new RuntimeException("Unable to execute script: " + _script + " for this reason: " + t.toString(),
                t);
    }

    return result;
}

From source file:com.streamsets.pipeline.maven.rbgen.RBGenMojo.java

@Override
@SuppressWarnings("unchecked")
public void execute() throws MojoExecutionException {
    try {/*from   w  w  w.j av a  2s .c o  m*/
        ClassLoader projectCL = getProjectClassLoader();
        if (usesDataCollectorAPI(projectCL)) {
            File file = new File(project.getBuild().getOutputDirectory(), BUNDLES_TO_GEN_FILE);
            if (file.exists() && file.isFile()) {
                Map<String, File> bundles = new HashMap<>();
                List<String> classNames = new ObjectMapper().readValue(file, List.class);
                if (!classNames.isEmpty()) {
                    for (String e : classNames) {
                        Class klass = projectCL.loadClass(e);
                        String bundleName = klass.getName().replace(".", "/") + "-bundle.properties";
                        File bundleFile = generateDefaultBundleForClass(klass, bundleName);
                        bundles.put(bundleName, bundleFile);
                    }
                    File jarFile = new File(project.getBuild().getDirectory(),
                            project.getArtifactId() + "-" + project.getVersion() + "-bundles.jar");
                    getLog().info("Building bundles jar: " + jarFile.getAbsolutePath());
                    createBundlesJar(jarFile, bundles);
                } else {
                    getLog().debug(BUNDLES_TO_GEN_FILE
                            + "' file does not have any class, no bundles jar will be generated");
                }
            } else {
                getLog().debug("Project does not have '" + BUNDLES_TO_GEN_FILE
                        + "' file, no bundles jar will be generated");
            }
        } else {
            getLog().debug("Project does not use DataCollector API, no bundles jar will be generated");
        }
    } catch (Throwable ex) {
        throw new MojoExecutionException(ex.toString(), ex);
    }
}

From source file:eu.faircode.netguard.ServiceJob.java

@Override
public boolean onStartJob(JobParameters params) {
    Log.i(TAG, "Start job=" + params.getJobId());

    new AsyncTask<JobParameters, Object, Object>() {

        @Override//from ww  w .j av a2s.  c  o m
        protected JobParameters doInBackground(JobParameters... params) {
            Log.i(TAG, "Executing job=" + params[0].getJobId());

            HttpsURLConnection urlConnection = null;
            try {
                String android_id = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
                JSONObject json = new JSONObject();

                json.put("device", Util.sha256(android_id, ""));
                json.put("product", Build.DEVICE);
                json.put("sdk", Build.VERSION.SDK_INT);
                json.put("country", Locale.getDefault().getCountry());

                json.put("netguard", Util.getSelfVersionCode(ServiceJob.this));
                try {
                    json.put("store", getPackageManager().getInstallerPackageName(getPackageName()));
                } catch (Throwable ex) {
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    json.put("store", null);
                }

                for (String name : params[0].getExtras().keySet())
                    json.put(name, params[0].getExtras().get(name));

                urlConnection = (HttpsURLConnection) new URL(cUrl).openConnection();
                urlConnection.setConnectTimeout(cTimeOutMs);
                urlConnection.setReadTimeout(cTimeOutMs);
                urlConnection.setRequestProperty("Accept", "application/json");
                urlConnection.setRequestProperty("Content-type", "application/json");
                urlConnection.setRequestMethod("POST");
                urlConnection.setDoInput(true);
                urlConnection.setDoOutput(true);

                OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
                out.write(json.toString().getBytes()); // UTF-8
                out.flush();

                int code = urlConnection.getResponseCode();
                if (code != HttpsURLConnection.HTTP_OK)
                    throw new IOException("HTTP " + code);

                InputStreamReader isr = new InputStreamReader(urlConnection.getInputStream());
                Log.i(TAG, "Response=" + Util.readString(isr).toString());

                jobFinished(params[0], false);

                if ("rule".equals(params[0].getExtras().getString("type"))) {
                    SharedPreferences history = getSharedPreferences("history", Context.MODE_PRIVATE);
                    history.edit().putLong(params[0].getExtras().getString("package") + ":submitted",
                            new Date().getTime()).apply();
                }

            } catch (Throwable ex) {
                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                jobFinished(params[0], true);

            } finally {
                if (urlConnection != null)
                    urlConnection.disconnect();

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ignored) {
                }
            }

            return null;
        }
    }.execute(params);

    return true;
}

From source file:ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException.java

/**
 * Constructor/*from ww w.j av a 2 s  .c  om*/
 * 
 * @param theStatusCode
 *            The HTTP status code corresponding to this problem
 * @param theCause
 *            The underlying cause exception
 */
public BaseServerResponseException(int theStatusCode, Throwable theCause) {
    super(theCause.toString(), theCause);
    myStatusCode = theStatusCode;
    myBaseOperationOutcome = null;
}

From source file:com.lucidtechnics.blackboard.util.JavascriptingUtil.java

public Object executeScript(String _scriptResource) {
    Context context = createContext();

    Object result = null;//ww  w  . j  av  a  2s.c om

    try {
        setScope(new org.mozilla.javascript.ImporterTopLevel(context, false));

        for (String key : getBindingsMap().keySet()) {
            Object object = Context.javaToJS(getBindingsMap().get(key), getScope());
            ScriptableObject.putProperty(getScope(), key, object);
        }

        result = compileScript(_scriptResource).exec(context, scope);
    } catch (Throwable t) {
        throw new RuntimeException(
                "Unable to execute script: " + _scriptResource + " for this reason: " + t.toString(), t);
    } finally {
        context.exit();
    }

    return result;
}

From source file:com.teletalk.jserver.tcp.http.xmlrpc.XmlRpcCommunicationManager.java

/**
 * Called to handle an exception that was thrown when executing the request (in {@link #handleRequest(HttpRequest, XmlRpcEndPoint)}). 
 * This implementation will return an XmlRpcException with a code specified through the property <code>defaultErrorCode</code>. The message 
 * will be generated though a call to <code>exception.toString()</code>.<br>
 * <br>/*from  w  w  w . j  a  v a  2  s.c om*/
 * Subclasses may override this method to provide a customized exception processsing implementation. 
 * 
 * @param exception the exception that was thrown.
 */
public XmlRpcException processException(final Throwable exception) {
    return new XmlRpcException(this.defaultErrorCode.intValue(), exception.toString());
}

From source file:com.ctrip.infosec.rule.executor.PostRulesExecutorService.java

/**
 * /*from  w w w.j  a  v  a2s .co  m*/
 */
void execute(RiskFact fact, boolean isAsync) {

    // matchRules      
    List<PostRule> matchedRules = Configs.matchPostRules(fact, isAsync);
    List<String> scriptRulePackageNames = Collections3.extractToList(matchedRules, "ruleNo");
    logger.debug(
            Contexts.getLogPrefix() + "matched post rules: " + StringUtils.join(scriptRulePackageNames, ", "));
    TraceLogger.traceLog("? " + matchedRules.size() + " ??? ...");

    StatelessPostRuleEngine statelessPostRuleEngine = SpringContextHolder
            .getBean(StatelessPostRuleEngine.class);
    for (PostRule rule : matchedRules) {
        RuleMonitorHelper.newTrans(fact, RuleMonitorType.POST_RULE, rule.getRuleNo());
        TraceLogger.beginNestedTrans(fact.eventId);
        TraceLogger.setNestedLogPrefix("[" + rule.getRuleNo() + "]");
        Contexts.setPolicyOrRuleNo(rule.getRuleNo());
        try {
            long start = System.currentTimeMillis();

            // add current execute ruleNo and logPrefix before execution
            fact.ext.put(Constants.key_ruleNo, rule.getRuleNo());
            fact.ext.put(Constants.key_isAsync, isAsync);

            statelessPostRuleEngine.execute(rule.getRuleNo(), fact);

            // remove current execute ruleNo when finished execution.
            fact.ext.remove(Constants.key_ruleNo);
            fact.ext.remove(Constants.key_isAsync);

            long handlingTime = System.currentTimeMillis() - start;
            if (handlingTime > 100) {
                logger.info(Contexts.getLogPrefix() + "postRule: " + rule.getRuleNo() + ", usage: "
                        + handlingTime + "ms");
            }
            TraceLogger.traceLog("[" + rule.getRuleNo() + "] usage: " + handlingTime + "ms");

        } catch (Throwable ex) {
            logger.warn(Contexts.getLogPrefix() + "??. postRule: " + rule.getRuleNo(),
                    ex);
            TraceLogger.traceLog("[" + rule.getRuleNo() + "] EXCEPTION: " + ex.toString());
        } finally {
            TraceLogger.commitNestedTrans();
            RuleMonitorHelper.commitTrans(fact);
            Contexts.clearLogPrefix();
        }
    }

}

From source file:byps.test.TestRemoteWithAuthentication.java

/**
 * Check that clients are still supported that do not send a sessionId in the message header.
 *///from w  w  w  . j  a va 2 s . com
@Test
public void testBypsVersionWithoutSessionId() {
    log.info("testBypsVersionWithoutSessionId(");

    try {
        BMessageHeader.BYPS_VERSION_CURRENT = BMessageHeader.BYPS_VERSION_WITH_SESSIONID - 1;

        BClient_Testser client = TestUtilsHttp.createClient(TestUtils.protocol, BWire.FLAG_DEFAULT,
                BMessageHeader.BYPS_VERSION_ENCRYPTED_TARGETID, BApiDescriptor_Testser.VERSION, 1);
        client.start();

        client.getRemotePrimitiveTypes().setInt(5);
        int value = client.getRemotePrimitiveTypes().getInt();
        TestUtils.assertEquals(log, "int value", 5, value);

    } catch (Throwable e) {
        TestUtils.fail(log, e.toString());
    }

    log.info(")testBypsVersionWithoutSessionId");
}

From source file:com.lucidtechnics.blackboard.util.JavascriptingUtil.java

public Object executeScript(String[] _scriptResources) {
    Context context = createContext();

    Object result = null;/*from   w  ww  . j  a v a  2 s  .  c  o  m*/
    int i = 0;

    try {
        setScope(new org.mozilla.javascript.ImporterTopLevel(context, false));

        for (String key : getBindingsMap().keySet()) {
            Object object = Context.javaToJS(getBindingsMap().get(key), getScope());
            ScriptableObject.putProperty(getScope(), key, object);
        }

        for (i = 0; i < _scriptResources.length; i++) {
            result = compileScript(_scriptResources[i]).exec(context, getScope());
        }
    } catch (Throwable t) {
        throw new RuntimeException(
                "Unable to execute script: " + _scriptResources[i] + " for this reason: " + t.toString(), t);
    } finally {
        context.exit();
    }

    return result;
}

From source file:io.stallion.asyncTasks.AsyncTaskFilePersister.java

public boolean markFailed(AsyncTask task, Throwable e) {
    File file = new File(fullFilePathForObj(task));
    task.setTryCount(task.getTryCount() + 1);

    task.setErrorMessage(e.toString() + ExceptionUtils.getStackTrace(e));
    if (task.getTryCount() >= 5) {
        task.setFailedAt(DateUtils.mils());
    } else {// ww w. j a  va2s .  c  o m
        task.setExecuteAt(DateUtils.mils() + ((2 ^ task.getTryCount()) * 1000));
        task.setLockedAt(0);
        task.setLockUuid("");
    }
    File dest = new File(fullFilePathForObj(task));
    boolean succeeded = file.renameTo(dest);
    if (!succeeded) {
        return false;
    }
    persist(task);
    return true;
}