Example usage for java.lang Throwable getLocalizedMessage

List of usage examples for java.lang Throwable getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:it.geosolutions.geobatch.geotiff.publish.GeotiffGeoServerAction.java

public Queue<FileSystemEvent> execute(Queue<FileSystemEvent> events) throws ActionException {
    try {/*  w w w.j a  v a2s.com*/
        listenerForwarder.started();
        final GeoServerActionConfiguration configuration = getConfiguration();
        // //
        // data flow configuration and dataStore name must not be null.
        // //
        if (configuration == null) {
            final String message = "DataFlowConfig is null.";
            if (LOGGER.isErrorEnabled())
                LOGGER.error(message);
            throw new IllegalStateException(message);
        }

        if (events == null) {
            final String message = "Incoming events queue is null.";
            if (LOGGER.isErrorEnabled())
                LOGGER.error(message);
            throw new IllegalStateException(message);
        }

        // returning queue
        final Queue<FileSystemEvent> ret = new LinkedList<FileSystemEvent>();

        // for each incoming file
        for (FileSystemEvent event : events) {

            final File inputFile = event.getSource();

            // checks on input file
            if (!inputFile.exists()) {
                // ERROR or LOG since it does not exists
                if (!configuration.isFailIgnored())
                    throw new IllegalStateException(
                            "File: " + inputFile.getAbsolutePath() + " does not exist!");
                else {
                    if (LOGGER.isWarnEnabled()) {
                        LOGGER.warn("File: " + inputFile.getAbsolutePath() + " does not exist!");
                    }
                }
            }
            // check if is File
            if (!inputFile.isFile()) {
                // ERROR or LOG
                if (!configuration.isFailIgnored())
                    throw new IllegalStateException("File: " + inputFile.getAbsolutePath() + " is not a file!");
                else {
                    if (LOGGER.isWarnEnabled()) {
                        LOGGER.warn("File: " + inputFile.getAbsolutePath() + " is not a file!");
                    }
                }
            }

            // check if we can read it
            if (!inputFile.canRead()) {
                // ERROR or LOG
                if (!configuration.isFailIgnored())
                    throw new IllegalStateException(
                            "File: " + inputFile.getAbsolutePath() + " is not readable!");
                else {
                    if (LOGGER.isWarnEnabled()) {
                        LOGGER.warn("File: " + inputFile.getAbsolutePath() + " is not readablet!");
                    }
                }
            }

            // do your magic
            listenerForwarder.setTask("Publishing: " + inputFile);
            // try to publish on geoserver
            if (publishGeoTiff(inputFile, configuration)) {
                // if success add the geotiff to the output queue
                ret.add(event);
            }
        }
        listenerForwarder.completed();
        return ret;
    } catch (Throwable t) {
        final String message = "FATAL -> " + t.getLocalizedMessage();
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error(message, t); // no need to
        }
        listenerForwarder.failed(t);
        throw new ActionException(this, message, t);
    }
}

From source file:edu.usu.sdl.opencatalog.web.extension.OpenCatalogExceptionHandler.java

public Resolution handleAll(Throwable error, HttpServletRequest request, HttpServletResponse response) {
    ActionBean action = (ActionBean) request.getAttribute(StripesConstants.REQ_ATTR_ACTION_BEAN);

    //TODO: Generate Error Ticket
    // Capture all request information, stacktraces, user info
    if (action != null) {

    }//from  w w w  .jav  a2s.c o  m

    //Strip and senstive info (See Checklist Q: 410)

    systemErrorModel.setMessage(error.getLocalizedMessage());

    final ObjectMapper objectMapper = new ObjectMapper();
    return new StreamingResolution(MediaType.APPLICATION_JSON) {

        @Override
        protected void stream(HttpServletResponse response) throws Exception {
            objectMapper.writeValue(response.getOutputStream(), systemErrorModel);
        }
    };
}

From source file:edu.usu.sdl.openstorefront.web.extension.OpenStorefrontExceptionHandler.java

public Resolution handleAll(Throwable error, HttpServletRequest request, HttpServletResponse response) {
    ActionBean action = (ActionBean) request.getAttribute(StripesConstants.REQ_ATTR_ACTION_BEAN);

    //TODO: Generate Error Ticket
    // Capture all request information, stacktraces, user info
    if (action != null) {

    }//from  ww w . j a v  a 2 s. c o m

    //Strip and senstive info (See Checklist Q: 410)

    systemErrorModel.setMessage(error.getLocalizedMessage());

    final ObjectMapper objectMapper = ServiceUtil.defaultObjectMapper();
    return new StreamingResolution(MediaType.APPLICATION_JSON) {

        @Override
        protected void stream(HttpServletResponse response) throws Exception {
            objectMapper.writeValue(response.getOutputStream(), systemErrorModel);
        }
    };
}

From source file:org.opennms.ng.services.eventd.BroadcastEventProcessor.java

/**
 * {@inheritDoc}/*from   w w  w  .  j  a v  a  2s  . c o m*/
 *
 * This method is invoked by the event manager when a new event is
 * available for processing.  Each message is examined for its Universal
 * Event Identifier and the appropriate action is taking based on each UEI.
 */
@Override
public void onEvent(Event event) {

    LOG.debug("onEvent: received event, UEI = {}", event.getUei());
    EventBuilder ebldr = null;

    if (isReloadConfigEvent(event)) {
        try {
            m_eventConfDao.reload();
            ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, getName());
            ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "Eventd");

        } catch (Throwable e) {
            LOG.error("onEvent: Could not reload events config", e);
            ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, getName());
            ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "Eventd");
            ebldr.addParam(EventConstants.PARM_REASON, e.getLocalizedMessage().substring(0, 128));
        }

        if (ebldr != null) {
            m_eventIpcManager.sendNow(ebldr.getEvent());
        }
    }
}

From source file:im.ene.lab.attiq.ui.activities.BaseActivity.java

protected void getMasterUser(final String token) {
    ApiClient.me().enqueue(new Callback<Profile>() {
        @Override/*from   w  w w. ja v a2s  .  c om*/
        public void onResponse(Call<Profile> call, final Response<Profile> response) {
            mMyProfile = response.body();
            if (mMyProfile != null) {
                mMyProfile.setToken(token);
                // save to Realm
                mTransactionTask = Attiq.realm().executeTransaction(new Realm.Transaction() {
                    @Override
                    public void execute(Realm realm) {
                        realm.copyToRealmOrUpdate(mMyProfile);
                    }
                }, new Realm.Transaction.Callback() {
                    @Override
                    public void onSuccess() {
                        super.onSuccess();
                        EventBus.getDefault().post(
                                new ProfileEvent(HomeActivity.class.getSimpleName(), true, null, mMyProfile));
                    }

                    @Override
                    public void onError(Exception e) {
                        super.onError(e);
                        EventBus.getDefault().post(new ProfileEvent(HomeActivity.class.getSimpleName(), false,
                                new Event.Error(Event.Error.ERROR_UNKNOWN, e.getLocalizedMessage()), null));
                    }
                });
            } else {
                EventBus.getDefault().post(new ProfileEvent(HomeActivity.class.getSimpleName(), false,
                        new Event.Error(response.code(), response.message()), null));
            }
        }

        @Override
        public void onFailure(Call<Profile> call, Throwable error) {
            EventBus.getDefault().post(new ProfileEvent(HomeActivity.class.getSimpleName(), false,
                    new Event.Error(Event.Error.ERROR_UNKNOWN, error.getLocalizedMessage()), null));
        }
    });
}

From source file:org.geoserver.wms.WMSTestSupport.java

/**
 * Performs some checks on an image response such as the mime type and attempts to read the 
 * actual image into a buffered image.// w w  w. j a  va 2s.c  o m
 * 
 */
protected void checkImage(MockHttpServletResponse response, String mimeType) {
    assertEquals(mimeType, response.getContentType());
    try {
        BufferedImage image = ImageIO.read(getBinaryInputStream(response));
        assertNotNull(image);
        assertEquals(image.getWidth(), 550);
        assertEquals(image.getHeight(), 250);
    } catch (Throwable t) {
        t.printStackTrace();
        fail("Could not read image returned from GetMap:" + t.getLocalizedMessage());
    }
}

From source file:org.pentaho.platform.scheduler.QuartzSubscriptionScheduler.java

/**
 * Returns a list of exception messages/*  ww  w . j  a v  a2s  . c  om*/
 */
public List syncSchedule(final List newSchedules) throws Exception {
    List exceptionList = new ArrayList();
    if (newSchedules == null) {
        return (exceptionList);
    }

    Scheduler scheduler = QuartzSystemListener.getSchedulerInstance();
    HashSet jobSet = new HashSet(Arrays.asList(scheduler.getJobNames(QuartzSubscriptionScheduler.GROUP_NAME)));

    // Add/modify the good schedules
    for (int i = 0; i < newSchedules.size(); ++i) {
        ISchedule sched = (ISchedule) newSchedules.get(i);
        try {
            syncSchedule(sched.getScheduleReference(), sched);
        } catch (Throwable t) {
            exceptionList.add(Messages.getString("QuartzSubscriptionScheduler.ERROR_SCHEDULING", //$NON-NLS-1$
                    sched.getScheduleReference(), t.getLocalizedMessage()));
        }
        jobSet.remove(sched.getScheduleReference());
    }

    // Now delete the left overs
    for (Iterator it = jobSet.iterator(); it.hasNext();) {
        scheduler.deleteJob((String) it.next(), QuartzSubscriptionScheduler.GROUP_NAME);
    }

    return (exceptionList);
}

From source file:org.darkware.wpman.wpcli.WPCLI.java

/**
 * Executes the command, ignoring any messages or data and only checking for success
 * or failure response codes.//from www  .  ja  va2 s.  co  m
 *
 * @return {@code true} if the command returned no error, {@code false} if any error
 * is returned.
 */
public boolean checkSuccess() {
    try {
        this.execute();
        return true;
    } catch (WPCLIError e) {
        WPCLI.log.debug("Command returned error: {}", e.getLocalizedMessage());
        return false;
    } catch (Throwable t) {
        WPCLI.log.warn("Saw unexpected exception while running a command for success/failure: {}: {}",
                t.getClass().getName(), t.getLocalizedMessage());
        return false;
    }
}

From source file:org.apache.cayenne.modeler.dialog.pref.DataSourcePreferences.java

/**
 * Tries to establish a DB connection, reporting the status of this
 * operation.//  w ww .jav a 2  s.c om
 */
public void testDataSourceAction() {
    DBConnectionInfo currentDataSource = getConnectionInfo();
    if (currentDataSource == null) {
        return;
    }

    if (currentDataSource.getJdbcDriver() == null) {
        JOptionPane.showMessageDialog(null, "No JDBC Driver specified", "Warning", JOptionPane.WARNING_MESSAGE);
        return;
    }

    if (currentDataSource.getUrl() == null) {
        JOptionPane.showMessageDialog(null, "No Database URL specified", "Warning",
                JOptionPane.WARNING_MESSAGE);
        return;
    }

    try {

        FileClassLoadingService classLoader = new FileClassLoadingService();

        List<File> oldPathFiles = ((FileClassLoadingService) getApplication().getClassLoadingService())
                .getPathFiles();

        Collection<String> details = new ArrayList<>();
        for (File oldPathFile : oldPathFiles) {
            details.add(oldPathFile.getAbsolutePath());
        }

        Preferences classPathPreferences = getApplication().getPreferencesNode(ClasspathPreferences.class, "");
        if (editor.getChangedPreferences().containsKey(classPathPreferences)) {
            Map<String, String> map = editor.getChangedPreferences().get(classPathPreferences);

            for (Map.Entry<String, String> en : map.entrySet()) {
                String key = en.getKey();
                if (!details.contains(key)) {
                    details.add(key);
                }
            }
        }

        if (editor.getRemovedPreferences().containsKey(classPathPreferences)) {
            Map<String, String> map = editor.getRemovedPreferences().get(classPathPreferences);

            for (Map.Entry<String, String> en : map.entrySet()) {
                String key = en.getKey();
                if (details.contains(key)) {
                    details.remove(key);
                }
            }
        }

        if (details.size() > 0) {

            // transform preference to file...
            Transformer transformer = new Transformer() {

                public Object transform(Object object) {
                    String pref = (String) object;
                    return new File(pref);
                }
            };

            classLoader.setPathFiles(CollectionUtils.collect(details, transformer));
        }

        Class<Driver> driverClass = classLoader.loadClass(Driver.class, currentDataSource.getJdbcDriver());
        Driver driver = driverClass.newInstance();

        // connect via Cayenne DriverDataSource - it addresses some driver
        // issues...
        // can't use try with resource here as we can loose meaningful exception
        Connection c = new DriverDataSource(driver, currentDataSource.getUrl(), currentDataSource.getUserName(),
                currentDataSource.getPassword()).getConnection();
        try {
            c.close();
        } catch (SQLException ignored) {
            // i guess we can ignore this...
        }

        JOptionPane.showMessageDialog(null, "Connected Successfully", "Success",
                JOptionPane.INFORMATION_MESSAGE);
    } catch (Throwable th) {
        th = Util.unwindException(th);
        String message = "Error connecting to DB: " + th.getLocalizedMessage();

        StringTokenizer st = new StringTokenizer(message);
        StringBuilder sbMessage = new StringBuilder();
        int len = 0;

        String tempString;
        while (st.hasMoreTokens()) {
            tempString = st.nextElement().toString();
            if (len < 110) {
                len = len + tempString.length() + 1;
            } else {
                sbMessage.append("\n");
                len = 0;
            }
            sbMessage.append(tempString).append(" ");
        }

        JOptionPane.showMessageDialog(null, sbMessage.toString(), "Warning", JOptionPane.WARNING_MESSAGE);
    }
}