Example usage for java.lang Throwable getMessage

List of usage examples for java.lang Throwable getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.vaadin.tools.ReportUsage.java

private static void doHttpGet(String userAgent, String url) {
    Throwable caught;
    InputStream is = null;/*from   w  ww.  j av a  2  s  .com*/
    try {
        URL urlToGet = new URL(url);
        URLConnection conn = urlToGet.openConnection();
        conn.setRequestProperty(USER_AGENT, userAgent);
        is = conn.getInputStream();
        // TODO use the results
        IOUtils.toByteArray(is);
        return;
    } catch (MalformedURLException e) {
        caught = e;
    } catch (IOException e) {
        caught = e;
    } finally {
        IOUtils.closeQuietly(is);
    }

    Logger.getLogger(ReportUsage.class.getName())
            .fine("Caught an exception while executing HTTP query: " + caught.getMessage());
}

From source file:org.glowroot.central.SyntheticMonitorService.java

private static String getBestMessageForSyntheticFailure(Throwable throwable) {
    String message = throwable.getMessage();
    if (throwable.getClass() == Exception.class && throwable.getCause() == null && message != null) {
        // special case so synthetic monitors can display a simple error message without the
        // exception class name clutter
        return message;
    } else {// ww w  .j  a  va 2  s .  c om
        return Throwables.getBestMessage(throwable);
    }
}

From source file:com.tomtom.speedtools.rest.GeneralExceptionMapper.java

@Nonnull
private static String createLogMessage(@Nonnull final String prefix, @Nonnull final Throwable exception,
        @Nonnull final ExceptionDTO exceptionDTO, final int statusCode) {
    assert prefix != null;
    assert exception != null;
    assert exceptionDTO != null;
    if (verboseMode) {
        return String.format(LOG_MESSAGE_TEMPLATE_VERBOSE, prefix, exceptionDTO.getReference(), "status",
                statusCode, exception.getMessage(), exceptionDTO.getTime());
    } else {/*  ww  w  .j  av a2 s  .c om*/
        return String.format(LOG_MESSAGE_TEMPLATE_COMPACT, "status", statusCode, exception.getMessage());
    }
}

From source file:org.eclipse.cft.server.core.internal.CloudErrorUtil.java

public static CoreException toCoreException(Throwable e) {
    if (e instanceof CloudFoundryException) {
        if (((CloudFoundryException) e).getDescription() != null) {
            return new CoreException(
                    new Status(IStatus.ERROR, CloudFoundryPlugin.PLUGIN_ID, NLS.bind("{0} ({1})", //$NON-NLS-1$
                            ((CloudFoundryException) e).getDescription(), e.getMessage()), e));
        }//from w  w w.j a va  2  s  .c o  m
    }
    return new CoreException(new Status(IStatus.ERROR, CloudFoundryPlugin.PLUGIN_ID,
            NLS.bind(Messages.ERROR_PERFORMING_CLOUD_FOUNDRY_OPERATION, e.getMessage()), e));
}

From source file:DDTTestRunner.java

/**
 * Invoke a Test Runner using the defaults specified by the ddt.properties file (or the hard coded defaults)
 * @return// w w  w.j av  a  2s.c o  m
 */
public static void invokeDefaults() {
    DDTSettings.reset();

    // Use the default test items provider
    try {
        // Get the initial test items specified in the properties file or the command line
        String tmp[] = DDTSettings.Settings().inputSpecsArrayWithDataFolder();
        runOn(tmp);
        generateReportIfNeeded();
        if (Driver.isInitialized()) {
            System.out.println("End of Test Session - Closing Driver");
            Driver.getDriver().close();
        }
    } catch (Throwable ex) {
        System.out.println("Exception encountered running defaults: " + ex.getMessage().toString());
    }
}

From source file:edu.osu.ling.pep.Pep.java

/**
 * Prints a throwable./*ww  w .j  a v  a 2  s . co m*/
 * 
 * @param error
 *            The throwable that was intercepted.
 * @see #printError(String)
 */
private static void printError(final Throwable error) {
    if (error instanceof SAXParseException) {
        final SAXParseException spe = (SAXParseException) error;
        Pep.printError("line " + spe.getLineNumber() + ": " + spe.getMessage());
    } else {
        String msg = error.getMessage();
        final Throwable cause = error.getCause();
        if (cause != null && !cause.equals(error)) {
            msg += ": " + cause.getMessage();
        }

        Pep.printError(msg);
    }
}

From source file:at.alladin.rmbt.qos.testserver.util.TestServerConsole.java

/**
 * /*from  ww w.ja v a  2s  . c o m*/
 * @param info
 * @param t
 * @param verboseLevelNeeded
 * @param service
 */
public static void errorReport(String errorReportKey, String info, Throwable t, int verboseLevelNeeded,
        TestServerServiceEnum service) {
    StringWriter stackTrace = new StringWriter();
    t.printStackTrace(new PrintWriter(stackTrace));
    if (!errorReportMap.containsKey(errorReportKey)) {
        errorReportMap.putIfAbsent(errorReportKey, new ErrorReport(
                info + ": [" + t.getClass().getCanonicalName() + " - " + t.getMessage() + "]", new Date()));
    }

    ErrorReport er = errorReportMap.get(errorReportKey);
    er.increaseCounter();

    LoggingService.fatal(t, info, service);
}

From source file:com.sap.nwcloudmanager.api.DeployAPI.java

public static void startApp(String appId, final StartStopAppResponseHandler handler) {

    NetWeaverCloudConfig config = NetWeaverCloudConfig.getInstance();
    getHttpClient().setBasicAuth(config.getUsername(), config.getPassword());
    getHttpClient().put("https://" + config.getHost() + "/domain_basic/spaces/" + config.getAccount()
            + "/appliances/" + appId + "/components/web", new JsonHttpResponseHandler() {

                @Override/*from w w w.  j a va 2s  .c om*/
                protected void handleFailureMessage(Throwable arg0, String arg1) {
                    handler.onFailure(arg0, arg1);
                }

                @Override
                public void onSuccess(JSONObject json) {
                    try {

                        handler.onSuccess(json.getString("status"), json.getString("message"));
                    } catch (JSONException e) {
                        Log.e(e.getMessage());
                    }
                }

                @Override
                public void onFailure(Throwable arg0) {
                    handler.onFailure(arg0, arg0.getMessage());
                }
            });
}

From source file:com.sap.nwcloudmanager.api.DeployAPI.java

public static void stopApp(String appId, final StartStopAppResponseHandler handler) {

    NetWeaverCloudConfig config = NetWeaverCloudConfig.getInstance();
    getHttpClient().setBasicAuth(config.getUsername(), config.getPassword());
    getHttpClient().delete("https://" + config.getHost() + "/domain_basic/spaces/" + config.getAccount()
            + "/appliances/" + appId + "/components/web", new JsonHttpResponseHandler() {

                @Override/*from  w w w.j  a  va 2  s .  com*/
                protected void handleFailureMessage(Throwable arg0, String arg1) {
                    handler.onFailure(arg0, arg1);
                }

                @Override
                public void onSuccess(JSONObject json) {
                    try {

                        handler.onSuccess(json.getString("status"), json.getString("message"));
                    } catch (JSONException e) {
                        Log.e(e.getMessage());
                    }
                }

                @Override
                public void onFailure(Throwable arg0) {
                    handler.onFailure(arg0, arg0.getMessage());
                }

            });
}

From source file:com.espertech.esper.core.EPServicesContextFactoryDefault.java

/**
 * Initialize event adapter service for config snapshot.
 * @param eventAdapterService is events adapter
 * @param configSnapshot is the config snapshot
 *///from ww w . j  a v  a2  s  .c o  m
protected static void init(EventAdapterService eventAdapterService, ConfigurationInformation configSnapshot) {
    // Extract legacy event type definitions for each event type name, if supplied.
    //
    // We supply this information as setup information to the event adapter service
    // to allow discovery of superclasses and interfaces during event type construction for bean events,
    // such that superclasses and interfaces can use the legacy type definitions.
    Map<String, ConfigurationEventTypeLegacy> classLegacyInfo = new HashMap<String, ConfigurationEventTypeLegacy>();
    for (Map.Entry<String, String> entry : configSnapshot.getEventTypeNames().entrySet()) {
        String typeName = entry.getKey();
        String className = entry.getValue();
        ConfigurationEventTypeLegacy legacyDef = configSnapshot.getEventTypesLegacy().get(typeName);
        if (legacyDef != null) {
            classLegacyInfo.put(className, legacyDef);
        }
    }
    eventAdapterService.setClassLegacyConfigs(classLegacyInfo);
    eventAdapterService.setDefaultPropertyResolutionStyle(
            configSnapshot.getEngineDefaults().getEventMeta().getClassPropertyResolutionStyle());
    eventAdapterService.setDefaultAccessorStyle(
            configSnapshot.getEngineDefaults().getEventMeta().getDefaultAccessorStyle());

    for (String javaPackage : configSnapshot.getEventTypeAutoNamePackages()) {
        eventAdapterService.addAutoNamePackage(javaPackage);
    }

    // Add from the configuration the Java event class names
    Map<String, String> javaClassNames = configSnapshot.getEventTypeNames();
    for (Map.Entry<String, String> entry : javaClassNames.entrySet()) {
        // Add Java class
        try {
            String typeName = entry.getKey();
            eventAdapterService.addBeanType(typeName, entry.getValue(), false, true, true, true);
        } catch (EventAdapterException ex) {
            throw new ConfigurationException("Error configuring engine: " + ex.getMessage(), ex);
        }
    }

    // Add from the configuration the XML DOM names and type def
    Map<String, ConfigurationEventTypeXMLDOM> xmlDOMNames = configSnapshot.getEventTypesXMLDOM();
    for (Map.Entry<String, ConfigurationEventTypeXMLDOM> entry : xmlDOMNames.entrySet()) {
        SchemaModel schemaModel = null;
        if ((entry.getValue().getSchemaResource() != null) || (entry.getValue().getSchemaText() != null)) {
            try {
                schemaModel = XSDSchemaMapper.loadAndMap(entry.getValue().getSchemaResource(),
                        entry.getValue().getSchemaText(), 2);
            } catch (Exception ex) {
                throw new ConfigurationException(ex.getMessage(), ex);
            }
        }

        // Add XML DOM type
        try {
            eventAdapterService.addXMLDOMType(entry.getKey(), entry.getValue(), schemaModel, true);
        } catch (EventAdapterException ex) {
            throw new ConfigurationException("Error configuring engine: " + ex.getMessage(), ex);
        }
    }

    // Add maps in dependency order such that supertypes are added before subtypes
    Set<String> dependentMapOrder;
    try {
        dependentMapOrder = GraphUtil.getTopDownOrder(configSnapshot.getMapTypeConfigurations());
    } catch (GraphCircularDependencyException e) {
        throw new ConfigurationException(
                "Error configuring engine, dependency graph between map type names is circular: "
                        + e.getMessage(),
                e);
    }

    Map<String, Properties> mapNames = configSnapshot.getEventTypesMapEvents();
    Map<String, Map<String, Object>> nestableMapNames = configSnapshot.getEventTypesNestableMapEvents();
    dependentMapOrder.addAll(mapNames.keySet());
    dependentMapOrder.addAll(nestableMapNames.keySet());
    try {
        for (String mapName : dependentMapOrder) {
            ConfigurationEventTypeMap mapConfig = configSnapshot.getMapTypeConfigurations().get(mapName);
            Properties propertiesUnnested = mapNames.get(mapName);
            if (propertiesUnnested != null) {
                Map<String, Object> propertyTypes = createPropertyTypes(propertiesUnnested);
                eventAdapterService.addNestableMapType(mapName, propertyTypes, mapConfig, true, true, true,
                        false, false);
            }

            Map<String, Object> propertiesNestable = nestableMapNames.get(mapName);
            if (propertiesNestable != null) {
                eventAdapterService.addNestableMapType(mapName, propertiesNestable, mapConfig, true, true, true,
                        false, false);
            }
        }
    } catch (EventAdapterException ex) {
        throw new ConfigurationException("Error configuring engine: " + ex.getMessage(), ex);
    }

    // Add plug-in event representations
    Map<URI, ConfigurationPlugInEventRepresentation> plugInReps = configSnapshot.getPlugInEventRepresentation();
    for (Map.Entry<URI, ConfigurationPlugInEventRepresentation> entry : plugInReps.entrySet()) {
        String className = entry.getValue().getEventRepresentationClassName();
        Class eventRepClass;
        try {
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
            eventRepClass = Class.forName(className, true, cl);
        } catch (ClassNotFoundException ex) {
            throw new ConfigurationException(
                    "Failed to load plug-in event representation class '" + className + "'", ex);
        }

        Object pluginEventRepObj;
        try {
            pluginEventRepObj = eventRepClass.newInstance();
        } catch (InstantiationException ex) {
            throw new ConfigurationException("Failed to instantiate plug-in event representation class '"
                    + className + "' via default constructor", ex);
        } catch (IllegalAccessException ex) {
            throw new ConfigurationException(
                    "Illegal access to instantiate plug-in event representation class '" + className
                            + "' via default constructor",
                    ex);
        }

        if (!(pluginEventRepObj instanceof PlugInEventRepresentation)) {
            throw new ConfigurationException("Plug-in event representation class '" + className
                    + "' does not implement the required interface "
                    + PlugInEventRepresentation.class.getName());
        }

        URI eventRepURI = entry.getKey();
        PlugInEventRepresentation pluginEventRep = (PlugInEventRepresentation) pluginEventRepObj;
        Serializable initializer = entry.getValue().getInitializer();
        PlugInEventRepresentationContext context = new PlugInEventRepresentationContext(eventAdapterService,
                eventRepURI, initializer);

        try {
            pluginEventRep.init(context);
            eventAdapterService.addEventRepresentation(eventRepURI, pluginEventRep);
        } catch (Throwable t) {
            throw new ConfigurationException("Plug-in event representation class '" + className + "' and URI '"
                    + eventRepURI + "' did not initialize correctly : " + t.getMessage(), t);
        }
    }

    // Add plug-in event type names
    Map<String, ConfigurationPlugInEventType> plugInNames = configSnapshot.getPlugInEventTypes();
    for (Map.Entry<String, ConfigurationPlugInEventType> entry : plugInNames.entrySet()) {
        String name = entry.getKey();
        ConfigurationPlugInEventType config = entry.getValue();
        eventAdapterService.addPlugInEventType(name, config.getEventRepresentationResolutionURIs(),
                config.getInitializer());
    }
}