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:org.apache.hadoop.hdfs.AvatarShell.java

private void printError(Throwable e) {
    System.err.println(e.getLocalizedMessage());
}

From source file:org.geoserver.taskmanager.web.panel.BatchesPanel.java

@Override
public void onInitialize() {
    super.onInitialize();

    add(dialog = new GeoServerDialog("dialog"));
    dialog.setInitialHeight(100);//from w ww  . j a  v a 2 s  .c o m
    ((ModalWindow) dialog.get("dialog")).showUnloadConfirmation(false);

    add(new AjaxLink<Object>("addNew") {
        private static final long serialVersionUID = -9184383036056499856L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            Batch batch = TaskManagerBeans.get().getFac().createBatch();
            if (configurationModel != null) {
                batch.setConfiguration(configurationModel.getObject());
                batch.setWorkspace(configurationModel.getObject().getWorkspace());
            }
            setResponsePage(new BatchPage(new Model<Batch>(batch), getPage()));
        }

        @Override
        public boolean isVisible() {
            return configurationModel == null || configurationModel.getObject().getId() != null;
        }
    });

    // the removal button
    add(remove = new AjaxLink<Object>("removeSelected") {
        private static final long serialVersionUID = 3581476968062788921L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            boolean someCant = false;
            for (Batch batch : batchesPanel.getSelection()) {
                if (!TaskManagerBeans.get().getDataUtil().isDeletable(batch)) {
                    error(new ParamResourceModel("stillRunning", BatchesPanel.this, batch.getFullName())
                            .getString());
                    someCant = true;
                } else if (!TaskManagerBeans.get().getSecUtil()
                        .isAdminable(((GeoServerBasePage) getPage()).getSession().getAuthentication(), batch)) {
                    error(new ParamResourceModel("noDeleteRights", BatchesPanel.this, batch.getName())
                            .getString());
                    someCant = true;
                }
            }
            if (someCant) {
                ((GeoServerBasePage) getPage()).addFeedbackPanels(target);
            } else {

                dialog.setTitle(new ParamResourceModel("confirmDeleteBatchesDialog.title", BatchesPanel.this));
                dialog.showOkCancel(target, new GeoServerDialog.DialogDelegate() {

                    private static final long serialVersionUID = -5552087037163833563L;

                    private String error = null;

                    @Override
                    protected Component getContents(String id) {
                        StringBuilder sb = new StringBuilder();
                        sb.append(
                                new ParamResourceModel("confirmDeleteBatchesDialog.content", BatchesPanel.this)
                                        .getString());
                        for (Batch batch : batchesPanel.getSelection()) {
                            sb.append("\n&nbsp;&nbsp;");
                            sb.append(escapeHtml(batch.getFullName()));
                        }
                        return new MultiLineLabel(id, sb.toString()).setEscapeModelStrings(false);
                    }

                    @Override
                    protected boolean onSubmit(AjaxRequestTarget target, Component contents) {
                        try {
                            for (Batch batch : batchesPanel.getSelection()) {
                                if (configurationModel != null) {
                                    configurationModel.getObject().getBatches().remove(batch.getName());
                                    if (batch.getId() != null) {
                                        removedBatches.add(batch);
                                    }
                                } else {
                                    TaskManagerBeans.get().getDao().remove(batch);
                                }
                            }
                            batchesPanel.clearSelection();
                            remove.setEnabled(false);
                        } catch (Exception e) {
                            LOGGER.log(Level.WARNING, e.getMessage(), e);
                            Throwable rootCause = ExceptionUtils.getRootCause(e);
                            error = rootCause == null ? e.getLocalizedMessage()
                                    : rootCause.getLocalizedMessage();
                        }
                        return true;
                    }

                    @Override
                    public void onClose(AjaxRequestTarget target) {
                        if (error != null) {
                            error(error);
                            target.add(remove);
                            ((GeoServerBasePage) getPage()).addFeedbackPanels(target);
                        } else {
                            target.add(batchesPanel);
                        }
                    }
                });
            }
        }
    });
    remove.setOutputMarkupId(true);
    remove.setEnabled(false);

    add(new AjaxLink<Object>("refresh") {

        private static final long serialVersionUID = 3905640474193868255L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            ((MarkupContainer) batchesPanel.get("listContainer").get("items")).removeAll();
            target.add(batchesPanel);
        }
    });

    //the panel
    add(new Form<>("form")
            .add(batchesPanel = new GeoServerTablePanel<Batch>("batchesPanel", batchesModel, true) {
                private static final long serialVersionUID = -8943273843044917552L;

                @Override
                protected void onSelectionUpdate(AjaxRequestTarget target) {
                    remove.setEnabled(batchesPanel.getSelection().size() > 0);
                    target.add(remove);
                }

                @SuppressWarnings("unchecked")
                @Override
                protected Component getComponentForProperty(String id, IModel<Batch> itemModel,
                        Property<Batch> property) {
                    if ((property.equals(BatchesModel.NAME) || property.equals(BatchesModel.FULL_NAME))
                            && itemModel.getObject().getId() != null) {
                        if (findParent(Form.class) == null) {
                            return new SimpleAjaxLink<String>(id,
                                    (IModel<String>) property.getModel(itemModel)) {
                                private static final long serialVersionUID = -9184383036056499856L;

                                @Override
                                protected void onClick(AjaxRequestTarget target) {
                                    setResponsePage(new BatchPage(itemModel, getPage()));
                                }
                            };
                        } else {
                            return new SimpleAjaxSubmitLink(id, (IModel<String>) property.getModel(itemModel)) {
                                private static final long serialVersionUID = -9184383036056499856L;

                                @Override
                                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                                    setResponsePage(new BatchPage(itemModel, getPage()));
                                }
                            };
                        }

                    } else if (property == BatchesModel.ENABLED) {
                        PackageResourceReference icon = itemModel.getObject().isEnabled()
                                ? CatalogIconFactory.get().getEnabledIcon()
                                : CatalogIconFactory.get().getDisabledIcon();
                        Fragment f = new Fragment(id, "iconFragment", BatchesPanel.this);
                        f.add(new Image("enabledIcon", icon));
                        return f;
                    } else if (property == BatchesModel.FREQUENCY) {
                        return new Label(id, formatFrequency(itemModel.getObject().getFrequency()));
                    } else if (property == BatchesModel.STATUS) {
                        return new SimpleAjaxLink<String>(id, (IModel<String>) property.getModel(itemModel)) {
                            private static final long serialVersionUID = -9184383036056499856L;

                            @Override
                            public void onClick(AjaxRequestTarget target) {
                                setResponsePage(new BatchRunsPage(itemModel, getPage()));
                            }
                        };
                    } else if (property == BatchesModel.RUN) {
                        if (itemModel.getObject().getId() == null
                                || itemModel.getObject().getElements().isEmpty()
                                || (configurationModel != null && configurationModel.getObject().isTemplate())
                                || !TaskManagerBeans.get().getSecUtil().isWritable(
                                        ((GeoServerSecuredPage) getPage()).getSession().getAuthentication(),
                                        itemModel.getObject())) {
                            return new Label(id);
                        } else {
                            SimpleAjaxSubmitLink link = new SimpleAjaxSubmitLink(id, null) {
                                private static final long serialVersionUID = -9184383036056499856L;

                                @Override
                                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                                    TaskManagerBeans.get().getBjService().scheduleNow(itemModel.getObject());
                                    info(new ParamResourceModel("batchStarted", BatchesPanel.this).getString());

                                    ((GeoServerBasePage) getPage()).addFeedbackPanels(target);
                                }
                            };
                            link.getLink().add(new AttributeAppender("class", "play-link", ","));
                            return link;
                        }
                    } else {

                        return null;
                    }
                }
            }));
    batchesPanel.setOutputMarkupId(true);
}

From source file:com.alkacon.opencms.newsletter.CmsNewsletterMail.java

/**
 * @see java.lang.Thread#run()/*from  w  w  w.j  a v  a2  s.  c  om*/
 */
@Override
public void run() {

    try {
        // send the newsletter mails
        sendMail();
    } catch (Throwable t) {
        // general failure, log it and add detailed error message to report
        if (LOG.isErrorEnabled()) {
            LOG.error(Messages.get().getBundle().key(Messages.LOG_ERROR_NEWSLETTER_SEND_FAILED_1,
                    getNewsletterName()), t);
        }
        getMailErrors().add(0, Messages.get().getBundle().key(Messages.MAIL_ERROR_NEWSLETTER_SEND_FAILED_2,
                getNewsletterName(), t.getLocalizedMessage()) + "\n");
    }
    if (!getMailErrors().isEmpty() && CmsStringUtil.isNotEmptyOrWhitespaceOnly(getReportRecipientAddress())) {
        // there were errors found while sending the newsletter, send error report mail
        CmsSimpleMail errorMail = new CmsSimpleMail();
        try {
            // set from address using the newsletter configuration
            errorMail.setFrom(m_mailData.getEmail().getFromAddress().getAddress());
        } catch (Exception e) {
            // failed to set from address in error report mail
            getMailErrors().add(0, Messages.get().getBundle().key(Messages.MAIL_ERROR_EMAIL_FROM_ADDRESS_1,
                    m_mailData.getContent().getFile().getRootPath()) + "\n");
        }
        try {
            errorMail.addTo(getReportRecipientAddress());
            errorMail.setSubject(
                    Messages.get().getBundle().key(Messages.MAIL_ERROR_SUBJECT_1, getNewsletterName()));
            // generate the error report mail content
            StringBuffer msg = new StringBuffer(1024);
            msg.append(Messages.get().getBundle().key(Messages.MAIL_ERROR_BODY_1, getNewsletterName()));
            msg.append("\n\n");
            for (Iterator<String> i = getMailErrors().iterator(); i.hasNext();) {
                // loop the stored error messages
                msg.append(i.next());
                if (i.hasNext()) {
                    msg.append("\n");
                }
            }
            errorMail.setMsg(msg.toString());
            // send the error report mail
            errorMail.send();
        } catch (Throwable t) {
            // failed to send error mail, log failure
            if (LOG.isErrorEnabled()) {
                LOG.error(Messages.get().getBundle().key(Messages.LOG_ERROR_MAIL_REPORT_FAILED_1,
                        getReportRecipientAddress()), t);
            }
        }
    }
}

From source file:stellr.util.stores.admin.FileUploadServlet.java

/**
 * Get Column Descriptions/Names Ignore Header rows Create StoreEntity for
 * update Call update for each row/*from   w  w w. j a  v a2  s .c om*/
 *
 */
public void commitFileData() {
    ArrayList<ColumnSelection> colType = new ArrayList<>();
    StoreEntity storeData;
    boolean loadFirstRow = true;

    for (ArrayList<Object> cells : rowData) {
        //Create new row for storeData
        storeData = new StoreEntity(dataSourceGridController);

        int cellCounter = 0;
        for (Object cellData : cells) {
            //Initialize null cells
            if (cellData == null) {
                cellData = "";
            }

            //Get Column Types/names/Descriptions                    
            if (loadFirstRow) { //First row is column selections
                if (cellData.getClass().equals(java.lang.String.class)) {
                    if (cellData.toString().trim().isEmpty()) { //If no column selected make it N/A
                        colType.add(ColumnSelection.NOTAPPLICABLE);
                    } else {
                        colType.add(ColumnSelection.valueOf((String) cellData)); //Set column name to ENUM Value
                    }
                } else {
                    colType.add(ColumnSelection.NOTAPPLICABLE); //If not string columnmake it N/A column - i.e. header switch - boolean
                }

            } //Load cells as column names 
            else {
                if (cellData.getClass().equals(java.lang.Boolean.class)) { //Skip header rows (check header switch)
                    boolean isHeader = (boolean) cellData;

                    if (isHeader) {
                        cellCounter++;
                        break; //Skip Row
                    } else { //First Column - Header boolean switch is false - data will be String even if boolean value
                        cellCounter++;
                        continue; //Skip Cell - Not data to be saved, util data
                    }
                }

                //Get Column Type from ENUM and column array
                ColumnSelection cellName = colType.get(cellCounter);

                //Process Data row, load StoreEntity for Create() dependent on column type                                                 
                switch (cellName) {
                case DISTRIBUTIONPARTNERID:
                    storeData.setDistributionpartner_distributionpartnerid((String) cellData);
                    break;
                case STORETYPECODE:
                    try {
                        storeData.setStoretype_storetypecode(Long.parseLong((String) cellData));
                    } catch (Exception e) {
                        storeData.setStoretype_storetypecode(0);
                        System.out.println("STORETYPECODE Ex" + e.getMessage());
                    }
                    break;
                case SOURCEIDENTIFIER:
                    storeData.setSourceidentifier((String) cellData);
                    break;
                case NAME:
                    storeData.setStorename((String) cellData);
                    break;
                case EMAIL:
                    storeData.setEmail((String) cellData);
                    break;
                case PHONENUMBER:
                    break;
                case ACTIVE:
                    try {
                        String tmpCell = (String) cellData;

                        if (tmpCell != null && (tmpCell.trim().equals("1") || tmpCell.trim().toUpperCase()
                                .equals(Boolean.TRUE.toString().toUpperCase()))) {
                            tmpCell = Boolean.TRUE.toString();
                        } else {
                            tmpCell = Boolean.FALSE.toString();
                        }

                        storeData.setActive(Boolean.parseBoolean(tmpCell.trim().toUpperCase()));
                    } catch (Exception e) {
                        storeData.setActive(false);
                        System.out.println("setActive Ex" + e.getMessage());
                    }

                    break;
                case ADDRESS_MAIN:
                    storeData.setAddress_main((String) cellData);
                    storeData.setAddress1((String) cellData);
                    break;
                case ADDRESS_BLOCK:
                    storeData.setAddress_block((String) cellData);
                    break;
                case ADDRESS_BUILDING:
                    storeData.setAddress_building((String) cellData);
                    break;
                case ADDRESS_FLOOR:
                    storeData.setAddress_floor((String) cellData);
                    break;
                case ADDRESS_SHOPNO:
                    storeData.setAddress_shopNo((String) cellData);
                    break;
                case GPS_LON:
                    storeData.setGps_lon((String) cellData);
                    break;
                case GPS_LAT:
                    storeData.setGps_lat((String) cellData);
                    break;
                case REGION:
                    storeData.setRegion((String) cellData);
                    break;
                case CITY:
                    storeData.setCity((String) cellData);
                    break;
                case POSTALCODE:
                    storeData.setPostalcode((String) cellData);
                    break;
                case COUNTRY:
                    storeData.setCountry((String) cellData);
                    break;
                default:
                    //Ignore column where type is not set 
                    break;
                }
            }
            //increment cell counter
            cellCounter++;
        }
        loadFirstRow = false; //First Row Containing column types loaded

        //Call Store Create with new SrtoreEntity Object for creation
        try {
            if (storeData.getStorename() != null && !storeData.getStorename().trim().isEmpty()
                    && storeData.getDistributionpartner_distributionpartnerid() != null
                    && !storeData.getDistributionpartner_distributionpartnerid().trim().isEmpty()) {

                StoresController storeController = new StoresController();
                storeController.setDataSourceGridController(dataSourceGridController);

                storeController.prepareCreate();
                storeController.setSelectedStore(storeData);
                storeController.create();
            }

        } catch (Exception e1) {
            System.out.println("Create Store Exception : " + e1.getMessage());

            Throwable cause = e1.getCause();
            String msg = "";

            if (cause != null) {
                msg = cause.getLocalizedMessage();
            }

            JsfUtil.addErrorMessage("Exception : " + msg + " : " + e1.getMessage());

            Logger.getLogger(FileUploadServlet.class.getName()).log(Level.SEVERE, null, e1);
        }
    }

    JsfUtil.addSuccessMessage("All Store Data Rows Processed");
    initRowData();
}

From source file:org.pentaho.platform.engine.core.system.PentahoSystem.java

public static void globalStartup(final IPentahoSession session) {
    // getGlobalStartupActions doesn't pay any attention to session class
    List<ISessionStartupAction> globalStartupActions = PentahoSystem.getGlobalStartupActions();
    if (globalStartupActions == null) {
        // nothing to do...
        return;//  ww w.j a va  2  s  . c o  m
    }

    boolean doGlobals = PentahoSystem.globalAttributes.size() == 0;
    // see if this has been done already
    if (!doGlobals) {
        return;
    }

    if (globalStartupActions != null) {
        for (ISessionStartupAction globalStartupAction : globalStartupActions) {
            // now execute the action...

            SimpleOutputHandler outputHandler = null;

            String instanceId = null;

            ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
            solutionEngine.setLoggingLevel(PentahoSystem.loggingLevel);
            solutionEngine.init(session);

            String baseUrl = ""; //$NON-NLS-1$
            HashMap parameterProviderMap = new HashMap();
            IPentahoUrlFactory urlFactory = new SimpleUrlFactory(baseUrl);

            ArrayList messages = new ArrayList();

            IRuntimeContext context = null;
            try {
                context = solutionEngine.execute(globalStartupAction.getActionPath(), "Global startup actions",
                        false, true, instanceId, false, parameterProviderMap, outputHandler, null, urlFactory,
                        messages); //$NON-NLS-1$

                // if context is null, then we cannot check the status
                if (null == context) {
                    return;
                }

                if (context.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS) {
                    // now grab any outputs
                    Iterator outputNameIterator = context.getOutputNames().iterator();
                    while (outputNameIterator.hasNext()) {

                        String attributeName = (String) outputNameIterator.next();
                        IActionParameter output = context.getOutputParameter(attributeName);

                        Object data = output.getValue();
                        if (data != null) {
                            PentahoSystem.globalAttributes.remove(attributeName);
                            PentahoSystem.globalAttributes.put(attributeName, data);
                        }
                    }
                }
            } catch (Throwable th) {
                Logger.warn(PentahoSystem.class.getName(), Messages.getInstance().getString(
                        "PentahoSystem.WARN_UNABLE_TO_EXECUTE_GLOBAL_ACTION", th.getLocalizedMessage()), th); //$NON-NLS-1$
            } finally {
                if (context != null) {
                    context.dispose();
                }
            }

        }
    }
}

From source file:is.hello.go99.example.AmplitudesFragment.java

@Override
public void onAmplitudesUnavailable(@NonNull Throwable reason) {
    if (!isAdded()) {
        Log.e(getClass().getSimpleName(), "Amplitudes unavailable", reason);
        return;/*from w ww .j ava 2s.c o m*/
    }

    swipeRefreshLayout.setRefreshing(false);

    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.title_error);
    builder.setMessage(reason.getLocalizedMessage());
    builder.setPositiveButton(android.R.string.ok, null);
    builder.setCancelable(true);
    builder.create().show();
}

From source file:org.pentaho.platform.web.http.api.resources.UserRoleDaoResource.java

/**
 * Remove all roles from the selected user
 *
 * @param tenantPath (tenant path where the user exist, null of empty string assumes default tenant)
 * @param userName   (username)/*from w ww  .j  av  a 2 s . c  om*/
 * @return
 */
@PUT
@Path("/removeAllRolesFromUser")
@Consumes({ WILDCARD })
@Facet(name = "Unsupported")
public Response removeAllRolesFromUser(@QueryParam("tenant") String tenantPath,
        @QueryParam("userName") String userName) {
    if (canAdminister()) {
        try {
            IUserRoleDao roleDao = PentahoSystem.get(IUserRoleDao.class, "userRoleDaoProxy",
                    PentahoSessionHolder.getSession());
            roleDao.setUserRoles(getTenant(tenantPath), userName, new String[0]);
            return Response.ok().build();
        } catch (Throwable th) {
            return processErrorResponse(th.getLocalizedMessage());
        }
    } else {
        return Response.status(UNAUTHORIZED).build();
    }
}

From source file:org.pentaho.platform.web.http.api.resources.UserRoleDaoResource.java

/**
 * Removes all users from a particular role
 *
 * @param tenantPath (tenant path where the user exist, null of empty string assumes default tenant)
 * @param roleName   (role name)//from w ww . ja  v a  2  s .  co m
 * @return
 */
@PUT
@Path("/removeAllUsersFromRole")
@Consumes({ WILDCARD })
@Facet(name = "Unsupported")
public Response removeAllUsersFromRole(@QueryParam("tenant") String tenantPath,
        @QueryParam("roleName") String roleName) {
    if (canAdminister()) {
        try {
            IUserRoleDao roleDao = PentahoSystem.get(IUserRoleDao.class, "userRoleDaoProxy",
                    PentahoSessionHolder.getSession());
            roleDao.setRoleMembers(getTenant(tenantPath), roleName, new String[0]);
            return Response.ok().build();
        } catch (Throwable th) {
            return processErrorResponse(th.getLocalizedMessage());
        }
    } else {
        return Response.status(UNAUTHORIZED).build();
    }
}

From source file:org.pentaho.platform.web.http.api.resources.UserRoleDaoResource.java

/**
 * Delete role(s) from the platform//from  w w w  . ja va 2 s.  c o m
 *
 * @param roleNames (list of tab (\t) separated role names)
 * @return
 */
@PUT
@Path("/deleteRoles")
@Consumes({ WILDCARD })
@Facet(name = "Unsupported")
public Response deleteRole(@QueryParam("roleNames") String roleNames) {
    if (canAdminister()) {
        try {
            IUserRoleDao roleDao = PentahoSystem.get(IUserRoleDao.class, "userRoleDaoProxy",
                    PentahoSessionHolder.getSession());
            StringTokenizer tokenizer = new StringTokenizer(roleNames, "\t");
            while (tokenizer.hasMoreTokens()) {
                IPentahoRole role = roleDao.getRole(null, tokenizer.nextToken());
                if (role != null) {
                    roleDao.deleteRole(role);
                }
            }
        } catch (Throwable th) {
            return processErrorResponse(th.getLocalizedMessage());
        }
        return Response.ok().build();
    } else {
        return Response.status(UNAUTHORIZED).build();
    }
}

From source file:org.pentaho.platform.web.http.api.resources.UserRoleDaoResource.java

/**
 * Delete user(s) from the platform//from   w ww .  ja  va 2 s.c  o m
 *
 * @param userNames (list of tab (\t) separated user names)
 * @return
 */
@PUT
@Path("/deleteUsers")
@Consumes({ WILDCARD })
@Facet(name = "Unsupported")
public Response deleteUser(@QueryParam("userNames") String userNames) {
    if (canAdminister()) {
        try {
            IUserRoleDao roleDao = PentahoSystem.get(IUserRoleDao.class, "userRoleDaoProxy",
                    PentahoSessionHolder.getSession());
            StringTokenizer tokenizer = new StringTokenizer(userNames, "\t");
            while (tokenizer.hasMoreTokens()) {
                IPentahoUser user = roleDao.getUser(null, tokenizer.nextToken());
                if (user != null) {
                    roleDao.deleteUser(user);
                }
            }
        } catch (Throwable th) {
            return processErrorResponse(th.getLocalizedMessage());
        }
        return Response.ok().build();
    } else {
        return Response.status(UNAUTHORIZED).build();
    }
}