Example usage for java.lang.reflect UndeclaredThrowableException UndeclaredThrowableException

List of usage examples for java.lang.reflect UndeclaredThrowableException UndeclaredThrowableException

Introduction

In this page you can find the example usage for java.lang.reflect UndeclaredThrowableException UndeclaredThrowableException.

Prototype

public UndeclaredThrowableException(Throwable undeclaredThrowable) 

Source Link

Document

Constructs an UndeclaredThrowableException with the specified Throwable .

Usage

From source file:info.novatec.testit.livingdoc.util.ClassUtils.java

public static <C> C createInstanceFromClassNameWithArguments(ClassLoader classLoader, String classWithArguments,
        Class<C> expectedType) throws UndeclaredThrowableException {
    try {//from w  ww  .jav  a 2  s.co m
        List<String> parameters = toList(escapeValues(classWithArguments.split(";")));
        Class<?> klass = ClassUtils.loadClass(classLoader, shift(parameters));

        if (!expectedType.isAssignableFrom(klass)) {
            throw new IllegalArgumentException(
                    "Class " + expectedType.getName() + " is not assignable from " + klass.getName());
        }

        if (parameters.size() == 0) {
            return expectedType.cast(klass.newInstance());
        }

        String[] args = parameters.toArray(new String[parameters.size()]);
        Constructor<?> constructor = klass.getConstructor(args.getClass());
        return expectedType.cast(constructor.newInstance(new Object[] { args }));
    } catch (ClassNotFoundException e) {
        throw new UndeclaredThrowableException(e);
    } catch (InstantiationException e) {
        throw new UndeclaredThrowableException(e);
    } catch (IllegalAccessException e) {
        throw new UndeclaredThrowableException(e);
    } catch (NoSuchMethodException e) {
        throw new UndeclaredThrowableException(e);
    } catch (InvocationTargetException e) {
        throw new UndeclaredThrowableException(e);
    }
}

From source file:org.forgerock.openidm.provisioner.Id.java

public URI getId() {
    try {/* w ww.j av a2 s . com*/
        URI id = getObjectSetId();
        if (null != localId) {
            id = id.resolve(URLEncoder.encode(localId, CHARACTER_ENCODING_UTF_8));
        }
        return id;
    } catch (UnsupportedEncodingException e) {
        // Should never happen.
        throw new UndeclaredThrowableException(e);
    }
}

From source file:org.forgerock.openidm.provisioner.Id.java

public URI getQualifiedId() {
    try {// w  w w.j a  va 2s . c  o  m
        URI id = getObjectSetId();
        if (null != localId) {
            id = id.resolve(URLEncoder.encode(localId, CHARACTER_ENCODING_UTF_8));
        }
        return baseURI.resolve(SYSTEM_BASE).resolve(id);
    } catch (UnsupportedEncodingException e) {
        // Should never happen.
        throw new UndeclaredThrowableException(e);
    }
}

From source file:httpfailover.FailoverHttpClient.java

/**
 * Executes a request using the default context and processes the
 * response using the given response handler.
 *
 * @param targets   the candidate target hosts for the request.
 *                  The request is executed on each hosts until one succeeds.
 * @param request   the request to execute
 * @param responseHandler the response handler
 * @param context   the context to use for the execution, or
 *                  <code>null</code> to use the default context
 *
 * @return  the response object as generated by the response handler.
 * @throws IOException in case of a problem or the connection was aborted
 * @throws ClientProtocolException in case of an http protocol error
 *//*from  ww w.  j  a v a 2s .  c o  m*/
public <T> T execute(List<HttpHost> targets, HttpRequest request, ResponseHandler<? extends T> responseHandler,
        HttpContext context) throws IOException, ClientProtocolException {

    HttpResponse response = execute(targets, request, context);
    T result;
    try {
        result = responseHandler.handleResponse(response);
    } catch (Exception t) {
        HttpEntity entity = response.getEntity();
        try {
            EntityUtils.consume(entity);
        } catch (Exception t2) {
            // Log this exception. The original exception is more
            // important and will be thrown to the caller.
            this.log.warn("Error consuming content after an exception.", t2);
        }
        if (t instanceof RuntimeException) {
            throw (RuntimeException) t;
        }
        if (t instanceof IOException) {
            throw (IOException) t;
        }
        throw new UndeclaredThrowableException(t);
    }

    // Handling the response was successful. Ensure that the content has
    // been fully consumed.
    HttpEntity entity = response.getEntity();
    EntityUtils.consumeQuietly(entity);

    return result;
}

From source file:org.forgerock.openidm.provisioner.Id.java

/**
 * Safely escapes the {@code uid} value/*from  w ww. j  av a2 s.  c o  m*/
 *
 * @param uid
 * @return
 * @throws IllegalArgumentException if the {@code uid} is blank
 * @throws NullPointerException     if the {@code uid} is null
 */
public static String escapeUid(String uid) {
    if (StringUtils.isBlank(uid)) {
        throw new IllegalArgumentException("UID can not be blank");
    }
    try {
        return URLEncoder.encode(uid, CHARACTER_ENCODING_UTF_8);
    } catch (UnsupportedEncodingException e) {
        // Should never happen.
        throw new UndeclaredThrowableException(e);
    }
}

From source file:io.soabase.client.apache.WrappedHttpClient.java

private <T> T internalExecute(final HttpUriRequest uriRequest, final HttpHost target, final HttpRequest request,
        final ResponseHandler<? extends T> responseHandler, final HttpContext context) throws IOException {
    Args.notNull(responseHandler, "Response handler");

    final HttpResponse response = (uriRequest != null) ? execute(uriRequest, context)
            : execute(target, request, context);

    final T result;
    try {//w  w w.  jav a  2s. co m
        result = responseHandler.handleResponse(response);
    } catch (final Exception t) {
        final HttpEntity entity = response.getEntity();
        try {
            EntityUtils.consume(entity);
        } catch (final Exception t2) {
            // Log this exception. The original exception is more
            // important and will be thrown to the caller.
            // TODO this.log.warn("Error consuming content after an exception.", t2);
        }
        if (t instanceof RuntimeException) {
            throw (RuntimeException) t;
        }
        if (t instanceof IOException) {
            throw (IOException) t;
        }
        throw new UndeclaredThrowableException(t);
    }

    // Handling the response was successful. Ensure that the content has
    // been fully consumed.
    final HttpEntity entity = response.getEntity();
    EntityUtils.consume(entity);
    return result;
}

From source file:it.cnr.icar.eric.client.ui.swing.AdhocQuerySearchPanel.java

public void reloadModel() {
    final SwingWorker worker = new SwingWorker(this) {
        public Object doNonUILogic() {
            try {
                // This might take a while. Contructor should be running as SwingWorker
                JAXRClient client = RegistryBrowser.getInstance().getClient();
                Connection connection = client.getConnection();
                RegistryService service = connection.getRegistryService();
                dqm = (it.cnr.icar.eric.client.xml.registry.DeclarativeQueryManagerImpl) service
                        .getDeclarativeQueryManager();
                lcm = (it.cnr.icar.eric.client.xml.registry.LifeCycleManagerImpl) service
                        .getBusinessLifeCycleManager();
                processConfiguration();//from   w  w w  . j  a  v a  2 s .c o  m
                // model!!!
            } catch (JAXRException e) {
                throw new UndeclaredThrowableException(e);
            }
            return null;
        }

        @SuppressWarnings({ "unchecked", "rawtypes" })
        public void doUIUpdateLogic() {
            try {
                selectQueryCombo.setModel(new DefaultComboBoxModel(getQueryNames()));
                if (queries.size() > 0) {
                    setQuery(queries.get(0));
                }
            } catch (JAXRException e) {
                throw new UndeclaredThrowableException(e);
            }
        }
    };
    worker.start();
}

From source file:org.kitodo.production.model.Subfolder.java

/**
 * Returns a file format by its MIME type, if any.
 * // w  w  w . j a v a  2  s. c  o  m
 * @return the file format, if any
 */
public FileFormat getFileFormat() {
    try {
        Optional<FileFormat> optionalFileFormat = FileFormatsConfig.getFileFormat(folder.getMimeType());
        if (optionalFileFormat.isPresent()) {
            return optionalFileFormat.get();
        } else {
            throw new NoSuchElementException(
                    "kitodo_fileFormats.xml has no <fileFormat mimeType=\"" + folder.getMimeType() + "\">");
        }
    } catch (JAXBException e) {
        throw new UndeclaredThrowableException(e);
    }
}

From source file:org.forgerock.openidm.provisioner.Id.java

/**
 * Safely unescapes the {@code uid} value
 *
 * @param uid/*from   w ww.j  a  v a 2s . c om*/
 * @return
 * @throws IllegalArgumentException if the {@code uid} is blank
 * @throws NullPointerException     if the {@code uid} is null
 */
public static String unescapeUid(String uid) {
    if (StringUtils.isBlank(uid)) {
        throw new IllegalArgumentException("UID can not be blank");
    }
    try {
        return URLDecoder.decode(uid, CHARACTER_ENCODING_UTF_8);
    } catch (UnsupportedEncodingException e) {
        // Should never happen.
        throw new UndeclaredThrowableException(e);
    }
}

From source file:org.opennms.ng.services.poller.Poller.java

/**
 * <p>onInit</p>/*from   w  ww  . j  a  va 2s  . co m*/
 */

public void onInit() {

    // serviceUnresponsive behavior enabled/disabled?
    LOG.debug("init: serviceUnresponsive behavior: {}",
            (getPollerConfig().isServiceUnresponsiveEnabled() ? "enabled" : "disabled"));

    createScheduler();

    try {
        LOG.debug("init: Closing outages for unmanaged services");

        closeOutagesForUnmanagedServices();
    } catch (Throwable e) {
        LOG.error("init: Failed to close ouates for unmanage services", e);
    }

    // Schedule the interfaces currently in the database
    //
    try {
        LOG.debug("start: Scheduling existing interfaces");

        scheduleExistingServices();
    } catch (Throwable sqlE) {
        LOG.error("start: Failed to schedule existing interfaces", sqlE);
    }

    // Create an event receiver. The receiver will
    // receive events, process them, creates network
    // interfaces, and schedulers them.
    //
    try {
        LOG.debug("start: Creating event broadcast event processor");

        setEventProcessor(new PollerEventProcessor(this));
    } catch (Throwable t) {
        LOG.error("start: Failed to initialized the broadcast event receiver", t);

        throw new UndeclaredThrowableException(t);
    }

    m_initialized = true;
    onStart();
}