Example usage for java.lang Exception getCause

List of usage examples for java.lang Exception getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.messic.server.facade.controllers.rest.exceptions.MusicTagsMessicRESTException.java

public MusicTagsMessicRESTException(Exception e) {
    super(e.getMessage(), e.getCause());
}

From source file:org.messic.server.facade.controllers.rest.exceptions.NotFoundMessicRESTException.java

public NotFoundMessicRESTException(Exception e) {
    super(e.getMessage(), e.getCause());
}

From source file:org.messic.server.facade.controllers.rest.exceptions.NotValidUserNameMessicRESTException.java

public NotValidUserNameMessicRESTException(Exception e) {
    super(e.getMessage(), e.getCause());
}

From source file:fr.paris.lutece.plugins.search.solr.indexer.SolrIndexerService.java

/**
 * Process the indexing//from ww  w. jav a2s  .  c  o  m
 * @param bCreate tell if it's total indexing or total (total = true)
 * @return the result log of the indexing
 */
public static synchronized String processIndexing(boolean bCreate) {
    // String buffer for building the response page;
    _sbLogs = new StringBuffer();

    Plugin plugin = PluginService.getPlugin(SolrPlugin.PLUGIN_NAME);

    boolean bCreateIndex = bCreate;
    String strWebappName = getWebAppName();

    try {
        Directory dir = IndexationService.getDirectoryIndex();

        if (!DirectoryReader.indexExists(dir)) { //init index
            bCreateIndex = true;
        }

        Date start = new Date();

        if (bCreateIndex) {
            _sbLogs.append("\r\nIndexing all contents ...\r\n");

            // Remove all indexed values of this site
            SOLR_SERVER.deleteByQuery(SearchItem.FIELD_UID + ":" + strWebappName
                    + SolrConstants.CONSTANT_UNDERSCORE + SolrConstants.CONSTANT_WILDCARD);

            for (SolrIndexer solrIndexer : INDEXERS) {
                if (solrIndexer.isEnable()) {
                    _sbLogs.append("\r\n<strong>Indexer : ");
                    _sbLogs.append(solrIndexer.getName());
                    _sbLogs.append(" - ");
                    _sbLogs.append(solrIndexer.getDescription());
                    _sbLogs.append("</strong>\r\n");

                    //the indexer will call write(doc)
                    List<String> lstErrors = solrIndexer.indexDocuments();

                    if (lstErrors != null) {
                        for (String strError : lstErrors) {
                            _sbLogs.append("<strong>ERROR : ");
                            _sbLogs.append(strError);
                            _sbLogs.append("</strong>\r\n");
                        }
                    }
                }
            }

            // Remove all actions of the database
            SolrIndexerActionHome.removeAll(plugin);
        } else {
            _sbLogs.append("\r\nIncremental Indexing ...\r\n");

            //incremental indexing
            Collection<SolrIndexerAction> actions = SolrIndexerActionHome.getList(plugin);

            for (SolrIndexerAction action : actions) {
                // catch any exception coming from an indexer to prevent global indexation to fail
                try {
                    SolrIndexer indexer = findSolrIndexer(action.getTypeResource());

                    if (indexer == null) {
                        _sbLogs.append(" - ERROR : ");
                        _sbLogs.append(" No indexer found for the resource name : ")
                                .append(action.getTypeResource());
                        _sbLogs.append("</strong>\r\n");

                        continue;
                    }

                    if (action.getIdTask() == IndexerAction.TASK_DELETE) {
                        if (action.getIdPortlet() != IndexationService.ALL_DOCUMENT) {
                            //delete only the index linked to this portlet
                            SOLR_SERVER.deleteByQuery(SearchItem.FIELD_DOCUMENT_PORTLET_ID + ":"
                                    + action.getIdDocument() + "&" + Integer.toString(action.getIdPortlet()));
                        } else {
                            //delete all index linked to uid. We get the uid of the resource to prefix it like we do during the indexation 
                            SOLR_SERVER.deleteByQuery(SearchItem.FIELD_UID + ":" + strWebappName
                                    + SolrConstants.CONSTANT_UNDERSCORE
                                    + indexer.getResourceUid(action.getIdDocument(), action.getTypeResource()));
                        }

                        _sbLogs.append("Deleting ");
                        _sbLogs.append(" #");
                        _sbLogs.append(action.getIdDocument());
                        _sbLogs.append("\r\n");
                    } else {
                        List<SolrItem> lstItems = indexer.getDocuments(action.getIdDocument());

                        if ((lstItems != null) && !lstItems.isEmpty()) {
                            for (SolrItem item : lstItems) {
                                if ((action.getIdPortlet() == IndexationService.ALL_DOCUMENT)
                                        || ((item.getDocPortletId() != null) && item.getDocPortletId()
                                                .equals(item.getUid() + "&" + action.getIdPortlet()))) {
                                    if (action.getIdTask() == IndexerAction.TASK_CREATE) {
                                        _sbLogs.append("Adding ");
                                    } else if (action.getIdTask() == IndexerAction.TASK_MODIFY) {
                                        _sbLogs.append("Updating ");
                                    }

                                    SOLR_SERVER.add(solrItem2SolrInputDocument(item));
                                    SOLR_SERVER.commit();

                                    _sbLogs.append(item.getType());
                                    _sbLogs.append(" #");
                                    _sbLogs.append(item.getUid());
                                    _sbLogs.append(" - ");
                                    _sbLogs.append(item.getTitle());
                                    _sbLogs.append("\r\n");
                                }
                            }
                        }
                    }

                    SolrIndexerActionHome.remove(action.getIdAction(), plugin);
                } catch (Exception e) {
                    _sbLogs.append("\r\n<strong>Action from indexer : ");
                    _sbLogs.append(action.getIndexerName());
                    _sbLogs.append(" Action ID : ").append(action.getIdAction()).append(" - Document ID : ")
                            .append(action.getIdDocument());
                    _sbLogs.append(" - ERROR : ");
                    _sbLogs.append(e.getMessage())
                            .append((e.getCause() != null) ? (" : " + e.getCause().getMessage())
                                    : SolrConstants.CONSTANT_EMPTY_STRING);
                    _sbLogs.append("</strong>\r\n");
                }
            }

            //reindexing all pages.
            SOLR_SERVER.deleteByQuery(SearchItem.FIELD_TYPE + ":" + PARAM_TYPE_PAGE);

            for (SolrIndexer indexer : INDEXERS) {
                if (indexer.isEnable() && SolrPageIndexer.NAME.equals(indexer.getName())) {
                    indexer.indexDocuments();

                    break;
                }
            }
        }

        SOLR_SERVER.commit();
        SOLR_SERVER.optimize();

        Date end = new Date();
        _sbLogs.append("Duration of the treatment : ");
        _sbLogs.append(end.getTime() - start.getTime());
        _sbLogs.append(" milliseconds\r\n");
    } catch (Exception e) {
        _sbLogs.append(" caught a ");
        _sbLogs.append(e.getClass());
        _sbLogs.append("\n with message: ");
        _sbLogs.append(e.getMessage());
        _sbLogs.append("\r\n");
        AppLogService.error("Indexing error : " + e.getMessage(), e);
    }

    return _sbLogs.toString();
}

From source file:org.messic.server.facade.controllers.rest.exceptions.IOMessicRESTException.java

public IOMessicRESTException(Exception e) {
    super(e.getMessage(), e.getCause());
}

From source file:org.messic.server.facade.controllers.rest.exceptions.NotAuthorizedMessicRESTException.java

public NotAuthorizedMessicRESTException(Exception e) {
    super(e.getMessage(), e.getCause());
}

From source file:org.messic.server.facade.controllers.rest.exceptions.UnknownMessicRESTException.java

public UnknownMessicRESTException(Exception e) {
    super(e.getMessage(), e.getCause());
}

From source file:com.garethahealy.resteastpathparamescape.ParamPathTest.java

@Test
public void test() throws URISyntaxException {
    try {/*ww w. j  a v  a 2 s  .c  o  m*/
        PathHandler handler = createClient();
        handler.getEntityHash("t;unit-testing/e;mzn7vykz");
    } catch (Exception ex) {
        if (ex.getCause() instanceof NoHttpResponseException
                || ex.getCause() instanceof HttpHostConnectException) {
            //Worked, as attempted to call endpoint but couldn't connect/send
            Assert.assertTrue(true);
        } else {
            Assert.fail(ex.getCause().getMessage());
        }
    }
}

From source file:org.statefulj.demo.ddd.customer.application.impl.CustomerApplicationServiceImpl.java

@Override
public void registerAndLogin(Customer customer, RegistrationForm regForm, HttpSession session) {
    try {/*w  w w .java2  s . c o  m*/
        Long id = customerService.nextId();
        customer.register(id, regForm.getPassword(), ContactInfoFactory.derivedFrom(regForm));
        customerService.save(customer);
        customerSessionService.login(session, customer);
    } catch (Exception e) {
        if (e.getCause() instanceof ConstraintViolationException) {
            throw new DuplicateUserException();
        } else {
            throw new RuntimeException(e);
        }
    }
}

From source file:org.openmrs.logic.rule.definition.RuleDefinitionValidator.java

public void validate(Object obj, Errors errors) {
    RuleDefinition rule = (RuleDefinition) obj;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.null");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "language", "error.null");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "ruleContent", "error.null");

    if (StringUtils.isNotBlank(rule.getLanguage()) && StringUtils.isNotBlank(rule.getRuleContent())) {
        RuleDefinitionService service = Context.getService(RuleDefinitionService.class);
        LanguageHandler handler = service.getLanguageHandler(rule.getLanguage());
        Date originalDateChanged = rule.getDateChanged();
        try {//from w ww.j a  v  a  2 s . c  o  m
            rule.setDateChanged(new Date());
            Rule r = handler.compile(rule);
            if (r == null)
                throw new LogicException("Unknown error compiling rule");
        } catch (Exception ex) {
            while (ex.getCause() != null && ex.getCause() != ex && ex.getCause() instanceof Exception)
                ex = (Exception) ex.getCause();
            errors.rejectValue("ruleContent", ex.getMessage());
        } finally {
            rule.setDateChanged(originalDateChanged);
        }
    }
}