Example usage for java.lang Exception getLocalizedMessage

List of usage examples for java.lang Exception getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:es.urjc.mctwp.service.ServiceDelegate.java

/**
 * This is responsible of command execution. A command may fail, this method
 * is responsible of cath exception, process and throw a CommandException that
 * view layer can understand./*  w  w w  .j a  v  a 2  s  .com*/
 * 
 * @param cmd
 * @return
 * @throws CommandException
 */
public Command runCommand(Command cmd) throws CommandException {
    TransactionStatus status = null;
    Command result = cmd;

    //Chechk command is well formed
    if ((cmd != null) && (cmd.isValidCommand())) {
        if (isCommandAuthorized(cmd)) {
            if (initLogCommand(cmd)) {

                try {
                    status = getTxStatus(cmd.getActionName(), cmd.isReadOnly(), cmd.getIsolation(),
                            cmd.getPropagation());
                    result = cmd.runCommand();
                } catch (Exception e) {
                    String msg = "Command failed: " + e.getLocalizedMessage();
                    txManager.rollback(status);
                    logger.error(msg);
                    throw new CommandException(msg, e);
                }

                try {
                    txManager.commit(status);
                } catch (Exception e) {
                    String msg = "Command commit failed: " + e.getLocalizedMessage();
                    logger.error(msg);
                    throw new CommandException(msg, e);
                }

                endsLogCommand(cmd);
            } else {
                String msg = "User action [" + cmd.getActionName() + "] can not be logged, execution aborted";
                logMessage(cmd, msg, null);
                throw new CommandException(msg);
            }
        } else {
            String msg = "User action [" + cmd.getActionName() + "] can not be authorized, execution aborted";
            logMessage(cmd, msg, null);
            throw new CommandException(msg);
        }
    } else {
        String msg = "The command [" + cmd.getClass().getName() + "] is not well formed";
        logMessage(cmd, msg, null);
        throw new CommandException(msg);
    }

    return result;
}

From source file:io.anyline.cordova.DebitCardActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    scanView = new DebitCardScanView(this, null);
    try {/*from  w w w.  j a  v  a2s  . c  om*/
        JSONObject json = new JSONObject(configJson);
        scanView.setConfig(new AnylineViewConfig(this, json));
    } catch (Exception e) {
        //JSONException or IllegalArgumentException is possible, return it to javascript
        finishWithError(Resources.getString(this, "error_invalid_json_data") + "\n" + e.getLocalizedMessage());
        return;
    }
    setContentView(scanView);

    initAnyline();
}

From source file:io.anyline.cordova.MrzActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mrzScanView = new MrzScanView(this, null);
    try {/*from ww w. j a  v a2s  .  c o  m*/
        JSONObject json = new JSONObject(configJson);
        mrzScanView.setConfig(new AnylineViewConfig(this, json));
    } catch (Exception e) {
        //JSONException or IllegalArgumentException is possible, return it to javascript
        finishWithError(Resources.getString(this, "error_invalid_json_data") + "\n" + e.getLocalizedMessage());
        return;
    }
    setContentView(mrzScanView);

    initAnyline();
}

From source file:ru.codemine.ccms.router.api.ApiRouter.java

@Secured("ROLE_USER")
@RequestMapping(value = "/api/shop", method = RequestMethod.GET)
public @ResponseBody ShopJson getShopJson(@RequestParam(required = false) Integer shopid,
        @RequestParam(required = false) String shopname) {
    if (shopid == null && shopname == null)
        throw new InvalidParametersException();
    if (shopid != null && shopname != null)
        throw new InvalidParametersException();

    try {//from   ww w. j av a 2 s  . co  m
        Shop shop = shopid == null ? shopService.getByName(shopname) : shopService.getById(shopid);

        return new ShopJson(shop);
    } catch (Exception e) {
        log.warn(" ?  API () - " + e.getLocalizedMessage());
        return null;
    }
}

From source file:ru.codemine.ccms.router.api.ApiRouter.java

@Secured("ROLE_USER")
@RequestMapping(value = "/api/shops", method = RequestMethod.GET)
public @ResponseBody List<ShopJson> getShopsJson() {
    try {/*from   ww w. j a va2 s .c  o  m*/
        List<ShopJson> result = new ArrayList<>();

        for (Shop shop : shopService.getAll()) {
            result.add(new ShopJson(shop));
        }

        return result;
    } catch (Exception e) {
        log.warn(" ?  API () - " + e.getLocalizedMessage());
        return new ArrayList<>();
    }
}

From source file:com.epam.dlab.configuration.SchedulerConfiguration.java

/** Build the schedule from user' schedule.
 * @throws ParseException/*from  w  w w. java 2  s .co  m*/
 */
public void build() throws ParseException {
    SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
    String[] unitArray = schedule.split(",");
    realSchedule.clear();
    for (int i = 0; i < unitArray.length; i++) {
        Calendar date = Calendar.getInstance();
        int[] time = getTime(unitArray[i]);
        try {
            df.parse(StringUtils.join(time, ':'));
        } catch (Exception e) {
            throw new ParseException("Cannot parse date " + unitArray[i] + ". " + e.getLocalizedMessage(), e);
        }
        date.clear();
        date.set(1, 1, 1, time[0], time[1], time[2]);
        realSchedule.put(df.format(date.getTime()), date);
    }
    adjustStartTime();
}

From source file:org.zenoss.zep.dao.impl.EventIndexQueueDaoImpl.java

@Override
@TransactionalRollbackAllExceptions//from ww  w . j a v a2s  .  co  m
public List<Long> indexEvents(final EventIndexHandler handler, final int limit, final long maxUpdateTime)
        throws ZepException {
    final Map<String, Object> selectFields = new HashMap<String, Object>();
    selectFields.put("_limit", limit);

    final String sql;

    // Used for partition pruning
    final String queryJoinLastSeen = (this.isArchive) ? "AND iq.last_seen=es.last_seen " : "";

    if (maxUpdateTime > 0L) {
        selectFields.put("_max_update_time", timestampConverter.toDatabaseType(maxUpdateTime));
        sql = "SELECT iq.id AS iq_id, iq.uuid AS iq_uuid, iq.update_time AS iq_update_time," + "es.* FROM "
                + this.queueTableName + " AS iq " + "LEFT JOIN " + this.tableName + " es ON iq.uuid=es.uuid "
                + queryJoinLastSeen + "WHERE iq.update_time <= :_max_update_time "
                + "ORDER BY iq_id LIMIT :_limit";
    } else {
        sql = "SELECT iq.id AS iq_id, iq.uuid AS iq_uuid, iq.update_time AS iq_update_time," + "es.* FROM "
                + this.queueTableName + " AS iq " + "LEFT JOIN " + this.tableName + " es ON iq.uuid=es.uuid "
                + queryJoinLastSeen + "ORDER BY iq_id LIMIT :_limit";
    }

    final Set<String> eventUuids = new HashSet<String>();
    final List<Long> indexQueueIds = this.template.query(sql, new RowMapper<Long>() {
        @Override
        public Long mapRow(ResultSet rs, int rowNum) throws SQLException {
            final long iqId = rs.getLong("iq_id");
            final String iqUuid = uuidConverter.fromDatabaseType(rs, "iq_uuid");
            // Don't process the same event multiple times.
            if (eventUuids.add(iqUuid)) {
                final Object uuid = rs.getObject("uuid");
                if (uuid != null) {
                    EventSummary summary = rowMapper.mapRow(rs, rowNum);
                    try {
                        handler.handle(summary);
                    } catch (Exception e) {
                        throw new RuntimeException(e.getLocalizedMessage(), e);
                    }
                } else {
                    try {
                        handler.handleDeleted(iqUuid);
                    } catch (Exception e) {
                        throw new RuntimeException(e.getLocalizedMessage(), e);
                    }
                }
            }
            return iqId;
        }
    }, selectFields);

    if (!indexQueueIds.isEmpty()) {
        try {
            handler.handleComplete();
        } catch (Exception e) {
            throw new ZepException(e.getLocalizedMessage(), e);
        }
    }

    // publish current size of event_*_index_queue table
    this.lastQueueSize = this.template.queryForInt("SELECT COUNT(1) FROM " + this.queueTableName);
    this.applicationEventPublisher
            .publishEvent(new EventIndexQueueSizeEvent(this, tableName, this.lastQueueSize, limit));

    return indexQueueIds;
}

From source file:io.anyline.cordova.BarcodeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    barcodeScanView = new BarcodeScanView(this, null);
    try {//from  ww w  .  j  a  v a  2s  .c o m
        JSONObject json = new JSONObject(configJson);
        barcodeScanView.setConfig(new AnylineViewConfig(this, json));
    } catch (Exception e) {
        //JSONException or IllegalArgumentException is possible, return it to javascript
        finishWithError(Resources.getString(this, "error_invalid_json_data") + "\n" + e.getLocalizedMessage());
        return;
    }
    setContentView(barcodeScanView);

    initAnyline();
}

From source file:it.geosolutions.geobatch.migrationmonitor.monitor.MonitorAction.java

@Override
public Queue<FileSystemEvent> execute(Queue<FileSystemEvent> events) throws ActionException {

    // return object
    final Queue<FileSystemEvent> outputEvents = new LinkedList<FileSystemEvent>();

    try {/*from w  w  w.  j a v  a  2  s .  c o m*/
        // looking for file
        if (events.size() == 0)
            throw new IllegalArgumentException(
                    "MonitorAction::execute(): Wrong number of elements for this action: " + events.size());

        listenerForwarder.setTask("config");
        listenerForwarder.started();

        if (configuration == null) {
            final String message = "MonitorAction::execute(): DataFlowConfig is null.";
            if (LOGGER.isErrorEnabled())
                LOGGER.error(message);
            throw new IllegalStateException(message);
        }

        // retrieve all the ELEMENTS table from the DB
        List<MigrationMonitor> migrationList = migrationMonitorDAO.findTablesToMigrate();
        DS2DSTokenResolver tknRes = null;

        // init some usefull counters
        int failsCounter = 0;
        int iterCounter = 0;
        int totElem = migrationList.size();

        // Process all MigrationMonitors retrieved
        for (MigrationMonitor mm : migrationList) {
            iterCounter++;
            try {
                tknRes = new DS2DSTokenResolver(mm, getConfigDir());
            } catch (IOException e) {
                failsCounter++;
                LOGGER.error(e.getMessage(), e);
                LOGGER.error("error while processing MigrationMonitor " + mm.toString()
                        + " let's skip it! (the error happens while resolving tokens...)");
                LOGGER.error("fail number: " + failsCounter + " MigrationMonitor processed " + iterCounter + "/"
                        + totElem);
                continue;
            }

            String filename = getTempDir() + File.separator + mm.getTableName() + mm.getLayerId() + ".xml";
            Writer writer = null;
            try {
                writer = new FileWriter(filename);
                writer.append(tknRes.getOutputFileContent());
            } catch (IOException e) {
                LOGGER.error("error while processing MigrationMonitor " + mm.toString()
                        + " let's skip it! (the error happens while writing on the output file)");
                LOGGER.error("fail number: " + failsCounter + " MigrationMonitor processed " + iterCounter + "/"
                        + totElem);
                continue;
            } finally {
                try {
                    writer.close();
                    FileSystemEvent fse = new FileSystemEvent(new File(filename),
                            FileSystemEventType.FILE_ADDED);
                    outputEvents.add(fse);
                } catch (IOException e) {
                    LOGGER.error(e.getMessage(), e);
                }
            }

            mm.setMigrationStatus(MigrationStatus.INPROGRESS.toString().toUpperCase());
            migrationMonitorDAO.merge(mm);
        }

    } catch (Exception t) {
        final String message = "MonitorAction::execute(): " + t.getLocalizedMessage();
        if (LOGGER.isErrorEnabled())
            LOGGER.error(message, t);
        final ActionException exc = new ActionException(this, message, t);
        listenerForwarder.failed(exc);
        throw exc;
    }

    return outputEvents;
}

From source file:com.amalto.workbench.actions.XSDSetAnnotationDocumentationAction.java

public IStatus doAction() {
    try {// www . jav  a2  s. c  om

        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        XSDAnnotationsStructure struc = new XSDAnnotationsStructure((XSDComponent) selection.getFirstElement());
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.XSDSetXX_ExceptionInfo,
                    selection.getFirstElement().getClass().getName()));
        }

        InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDSetXX_DialogTitle,
                Messages.XSDSetXX_DialogTip, struc.getDocumentation(), new IInputValidator() {

                    public String isValid(String newText) {
                        return null;
                    };
                });

        id.setBlockOnOpen(true);
        int ret = id.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }

        struc.setDocumentation("".equals(id.getValue()) ? null : id.getValue());//$NON-NLS-1$

        if (struc.hasChanged()) {
            page.refresh();
            page.getTreeViewer().expandToLevel(selection.getFirstElement(), 2);
            page.markDirty();
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.bind(Messages.XSDSetXX_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }

    return Status.OK_STATUS;
}