Example usage for org.apache.commons.lang UnhandledException UnhandledException

List of usage examples for org.apache.commons.lang UnhandledException UnhandledException

Introduction

In this page you can find the example usage for org.apache.commons.lang UnhandledException UnhandledException.

Prototype

public UnhandledException(String message, Throwable cause) 

Source Link

Document

Constructs the exception using a message and cause.

Usage

From source file:cf.janga.javafire.eventing.core.EventImpl.java

@Override
public String getKey() {
    try {// w w w. j av a 2  s.c  o m
        return (String) this.eventKeyMethod.invoke(this.event);
    } catch (Exception e) {
        throw new UnhandledException("Error getting key for event " + this.event.getClass(), e);
    }
}

From source file:info.magnolia.cms.taglibs.util.ImgTagBeanInfo.java

/**
 * @see java.beans.BeanInfo#getPropertyDescriptors()
 *///ww  w. j  a v  a2 s  .co  m
public PropertyDescriptor[] getPropertyDescriptors() {

    try {
        List proplist = new ArrayList();
        for (int j = 0; j < properties.length; j++) {
            proplist.add(createPropertyDescriptor(properties[j]));
        }
        PropertyDescriptor[] result = new PropertyDescriptor[proplist.size()];
        return ((PropertyDescriptor[]) proplist.toArray(result));

    } catch (IntrospectionException ex) {
        // should never happen
        throw new UnhandledException(ex.getMessage(), ex);
    }

}

From source file:gov.nih.nci.caarray.upgrade.FixOrganismsMigrator.java

/**
 * {@inheritDoc}/*from   w  ww.j  a  v a 2 s . c  om*/
 */
public void doHibernateExecute(final SingleConnectionHibernateHelper hibernateHelper) {
    try {
        List<Organism> allOrganisms = getAllOrganisms(hibernateHelper);
        Map<String, List<Organism>> nameToOrganismsListMap = buildNamesToOrganismsListMap(allOrganisms);
        for (List<Organism> organismsWithSameNameList : nameToOrganismsListMap.values()) {
            if (organismsWithSameNameList.size() > 1) {
                processOrganismsWithSameName(hibernateHelper,
                        organismsWithSameNameList.get(0).getScientificName(), organismsWithSameNameList);
            } else if (organismsWithSameNameList.size() == 1) {
                Organism organism = organismsWithSameNameList.get(0);
                if (null != organism.getTermSource() && !ExperimentOntology.NCBI.getOntologyName()
                        .equals(organism.getTermSource().getName())) {
                    organism.setTermSource(getNcbiTermSource(hibernateHelper));
                }
            }
        }
    } catch (Exception exception) {
        throw new UnhandledException("Cannot fix the Organisms in DB.", exception);
    }
}

From source file:ar.com.zauber.commons.web.uri.UriJspFunctions.java

/** Construye un uri */
public static String buildVarArgs(final ServletRequest request, final String uriKey, final Object... params) {
    Validate.notNull(uriKey);/*from  w  w w .  j  a v  a2 s .  c  o  m*/
    Validate.notNull(request);

    if (!initialized.getAndSet(true)) {
        try {
            logger.info("Resolving Urifactory bean.");
            WebApplicationContext appCtx = RequestContextUtils.getWebApplicationContext(request);

            try {
                uriFactory = appCtx.getBean(SpringBeans.LINK_URIFACTORY_KEY, UriFactory.class);
                logger.info("Using {} UriFactory.", SpringBeans.LINK_URIFACTORY_KEY);
            } catch (NoSuchBeanDefinitionException e) {
                logger.info("Using Default UriFactory.");
                uriFactory = new RelativePathUriFactory(new IdentityUriFactory());
            }
        } catch (Throwable e) {
            initialized.set(false);
            throw new UnhandledException("inicializando urifactory", e);
        }
    }

    return uriFactory.buildUri(uriKey, params);
}

From source file:ar.com.zauber.commons.web.uri.UriJspFunctions.java

/** Construye un uri con el bean factory de UriBean. de no ser posible usa el default*/
public static String buildVarArgs(final ServletRequest request, final String uriKey, final String uriBean,
        final Object... params) {
    Validate.notNull(uriKey);//ww  w. ja v  a  2  s . co m
    Validate.notNull(uriBean);
    Validate.notNull(request);
    UriFactory uFactory = null;
    try {
        logger.info("Resolving Urifactory bean.");
        WebApplicationContext appCtx = RequestContextUtils.getWebApplicationContext(request);

        try {
            uFactory = appCtx.getBean(uriBean, UriFactory.class);
            logger.info("Using {} UriFactory.", uriBean);
        } catch (NoSuchBeanDefinitionException e) {
            return buildVarArgs(request, uriKey, params);
        }
    } catch (Throwable e) {
        throw new UnhandledException("inicializando urifactory", e);
    }
    return uFactory.buildUri(uriKey, params);

}

From source file:gov.nih.nci.caarray.upgrade.FixHybridizationsWithMissingArraysMigrator.java

/**
 * Execute the change given a connection.
 * @param connection the connection// ww w  . j a  va 2 s  . co  m
 */
public void execute(Connection connection) {
    setup(connection);
    try {
        List<Long> hybIdsWithoutArray = dao.getHybIdsWithNoArrayOrNoArrayDesign();
        for (Long hid : hybIdsWithoutArray) {
            ensureArrayDesignSetForHyb(hid);
        }
    } catch (Exception e) {
        throw new UnhandledException("Could not fix hybridizations", e);
    }
}

From source file:ar.com.zauber.labs.kraken.providers.wikipedia.model.impl.HttpWikiPageRetriever.java

/** @see WikiPageRetriever#get(String) */
public final WikiPage get(final Language wikipediaLang, final String pageTitle) {
    Validate.isTrue(StringUtils.isNotBlank(pageTitle), "pageTitle is blank");
    Validate.notNull(wikipediaLang, "wikipediaLang is null");
    final UriTemplate uriTemplate;

    uriTemplate = new UriTemplate("http://" + wikipediaLang.getIsoName()
            + ".wikipedia.org/w/api.php?action=query&redirects=true&format=xml"
            + "&titles={title}&prop=langlinks{llcontinue}");

    Reader reader = null;//w w w . j  ava2s  .  co m
    try {
        String llcontinue = null;
        final Set<String> titles = new TreeSet<String>();
        final Map<Language, WikiPage> langLink = new TreeMap<Language, WikiPage>();
        long pageid = 0;
        do {
            final URI url = uriTemplate.expand(pageTitle,
                    llcontinue == null ? "" : "&llcontinue=" + llcontinue);
            try {
                reader = contentProvider.getContent(url);
                final Api api = (Api) unmarshaller.unmarshal(reader);
                IOUtils.closeQuietly(reader);
                reader = null;

                final Query query = api.getQuery();

                if (query.getRedirects() != null) {
                    for (final R r : query.getRedirects().getR()) {
                        titles.add(r.getFrom());
                        titles.add(r.getTo());
                    }
                }
                final List<Page> pages = query.getPages().getPage();
                if (pages.size() == 1) {
                    final Page page = pages.get(0);
                    pageid = page.getPageid().longValue();
                    titles.add(page.getTitle());
                    if (page.getLanglinks() != null) {
                        for (final Ll ll : page.getLanglinks().getLl()) {
                            try {
                                final Language lang = LangUtils.getLang(ll.getLang());
                                langLink.put(lang, lazyWikiPageRetriever.get(lang, ll.getValue()));
                            } catch (final NoSuchEntityException e) {
                                final StringBuilder sb = new StringBuilder();
                                new Formatter(sb).format("Unknown language %s on wiki page `%s' (%s):" + " %s",
                                        e.getEntity(), pageTitle, wikipediaLang, url);
                                throw new IllegalArgumentException(sb.toString(), e);
                            }
                        }
                    }
                    if (api.getQueryContinue() == null) {
                        llcontinue = null;
                    } else {
                        llcontinue = api.getQueryContinue().getLanglinks().getLlcontinue();
                    }
                } else {
                    throw new AssertionError("1 page expected. got " + pages.size() + "unable to parse page "
                            + pageTitle + " (" + url + ")");
                }
            } catch (final NoSuchEntityException e) {
                throw new NoSuchEntityException(pageTitle + " (" + wikipediaLang + ")", e);
            } catch (final JAXBException e) {
                final StringBuilder sb = new StringBuilder();
                new Formatter(sb).format("parsing wiki page `%s' (%s): %s\n%s", pageTitle, wikipediaLang, url,
                        e);
                throw new UnhandledException(sb.toString(), e);
            }
        } while (llcontinue != null);

        return new SimpleWikiPage(pageid, wikipediaLang, titles, langLink);
    } finally {
        if (reader != null) {
            IOUtils.closeQuietly(reader);
        }
    }
}

From source file:ar.com.zauber.commons.web.proxy.HttpClientRequestProxy.java

/**
 * @param request// w w  w .ja v a  2  s.  c  o m
 * @return
 */
private HttpMethod buildRequest(final HttpServletRequest request, final URLResult urlResult) {
    final String method = request.getMethod().toUpperCase();
    final HttpMethod ret;

    final String uri = urlResult.getURL().toExternalForm();
    if ("GET".equals(method)) {
        ret = new GetMethod(uri);
        proxyHeaders(request, ret);
    } else if ("POST".equals(method) || "PUT".equals(method)) {
        final EntityEnclosingMethod pm = "POST".equals(method) ? new PostMethod(uri) : new PutMethod(uri);
        proxyHeaders(request, pm);
        try {
            pm.setRequestEntity(new InputStreamRequestEntity(request.getInputStream()));
        } catch (IOException e) {
            throw new UnhandledException("No pudo abrirse el InputStream" + "del request.", e);
        }
        ret = pm;

    } else if ("DELETE".equals(method)) {
        /*
        rfc2616
        The Content-Length field of a request or response is added or deleted
        according to the rules in section 4.4. A transparent proxy MUST
        preserve the entity-length (section 7.2.2) of the entity-body,
        although it MAY change the transfer-length (section 4.4).
        */
        final DeleteMethod dm = new DeleteMethod(uri);
        proxyHeaders(request, dm);
        //No body => No Header
        dm.removeRequestHeader("Content-Length");
        ret = dm;
    } else {
        throw new NotImplementedException("i accept patches :)");
    }

    if (request.getQueryString() != null) {
        ret.setQueryString(request.getQueryString());
    }

    return ret;
}

From source file:com.mirth.connect.connectors.jms.JmsConnector.java

protected Connection createConnection() throws NamingException, JMSException, InitialisationException {
    Connection connection = null;

    if (connectionFactory == null) {
        connectionFactory = createConnectionFactory();
    }// w ww  .  j  a v  a2s  .c om

    if (connectionFactory != null && connectionFactory instanceof XAConnectionFactory) {
        if (MuleManager.getInstance().getTransactionManager() != null) {
            connectionFactory = new ConnectionFactoryWrapper(connectionFactory,
                    MuleManager.getInstance().getTransactionManager());
        }
    }

    if (username != null) {
        connection = jmsSupport.createConnection(connectionFactory, replacer.replaceValues(username),
                replacer.replaceValues(password));
    } else {
        connection = jmsSupport.createConnection(connectionFactory);
    }

    if (clientId != null) {
        connection.setClientID(replacer.replaceValues(getClientId()));
    }

    if (recoverJmsConnections && connection != null) {
        connection.setExceptionListener(new ExceptionListener() {
            public void onException(JMSException jmsException) {
                logger.debug("About to recycle myself due to remote JMS connection shutdown.");
                final JmsConnector jmsConnector = JmsConnector.this;
                try {
                    jmsConnector.doStop();
                    jmsConnector.initialised.set(false);
                } catch (UMOException e) {
                    logger.warn(e.getMessage(), e);
                }

                try {
                    jmsConnector.doConnect();
                    jmsConnector.doInitialise();
                    jmsConnector.doStart();
                } catch (FatalConnectException fcex) {
                    logger.fatal("Failed to reconnect to JMS server. I'm giving up.");
                } catch (UMOException umoex) {
                    throw new UnhandledException("Failed to recover a connector.", umoex);
                }
            }
        });
    }

    return connection;
}

From source file:ar.com.zauber.commons.gis.street.impl.GMapsStreetDao.java

/**
 * @param key nombre del tag a buscar/* ww w .ja  v  a2s.  c o  m*/
 * @param node estructura donde buscar.
 * @return el nodo con el tag con ese key como nombre
 */
private Node find(final String key, final Node node) {
    Validate.notNull(node);
    Validate.isTrue(StringUtils.isNotBlank(key));
    NodeList list = node.getChildNodes();
    Node res = null;
    for (int index = 0; index < list.getLength(); index++) {
        String name = list.item(index).getNodeName();
        if (name.equals(key) && res == null) {
            res = list.item(index);
        } else if (name.equals(key)) {
            throw new UnhandledException("Este metodo debe ser llamado cuando se sabe que"
                    + "no existen mas de un nodo con este nombre", null);
        } else if (res == null) {
            res = find(key, list.item(index));
        }
    }
    return res;
}