Example usage for org.springframework.beans.factory NoSuchBeanDefinitionException getCause

List of usage examples for org.springframework.beans.factory NoSuchBeanDefinitionException getCause

Introduction

In this page you can find the example usage for org.springframework.beans.factory NoSuchBeanDefinitionException 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.infoscoop.admin.web.ServiceCommandServlet.java

@SuppressWarnings("unchecked")
protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String uri = req.getRequestURI();
    String services = "/services/";
    String path = uri.substring(uri.indexOf(services) + services.length());

    String[] servicePaths = path.split("/");
    String serviceName = servicePaths[0];
    String commandName = servicePaths[1];
    if (log.isInfoEnabled())
        log.info("Call " + commandName + " comman of " + serviceName + " service.");

    Object temp = null;/* w ww . j  a va  2s  .co m*/
    try {
        temp = SpringUtil.getBean(serviceName);
    } catch (NoSuchBeanDefinitionException ex) {
        log.error("", ex);
    }

    if (temp == null || !(temp instanceof ServiceCommand)) {
        resp.sendError(500, "Service Not Found");
        return;
    }

    ServiceCommand serviceCommand = (ServiceCommand) temp;
    try {
        resp.setContentType("text/plain; charset=UTF-8");
        resp.setHeader("Pragma", "no-cache");
        resp.setHeader("Cache-Control", "no-cache");

        CommandResponse commandResp;
        try {
            // check the roll.
            Properties notPermittedPatterns = serviceCommand.getNotPermittedPatterns();

            Set permissionTypeList = notPermittedPatterns.keySet();
            List<String> myPermissionList = PortalAdminsService.getHandle().getMyPermissionList();
            String notPermittedPattern = ".*";

            boolean notMatched = false;
            myPermissionList.add("*");
            for (String myPermissionType : myPermissionList) {
                notPermittedPattern = notPermittedPatterns.getProperty(myPermissionType, ".*");
                if (commandName.matches(notPermittedPattern))
                    continue;

                // when there is no pattern that isn't permitted
                notMatched = true;
                break;
            }

            if (!notMatched)
                resp.sendError(403, "It is an access to the service that has not been permitted.");

            commandResp = serviceCommand.execute(commandName, req, resp);
        } catch (Throwable ex) {
            log.error(ex.getMessage(), ex);
            Throwable cause;
            while ((cause = ex.getCause()) != null)
                ex = cause;

            commandResp = new CommandResponse(false, ex.getClass().getName() + ": " + ex.getMessage());
        }

        int status = 200;
        String responseBody = commandResp.getResponseBody();
        if (!commandResp.isSuccess())
            status = 500;

        resp.setStatus(status);
        if (responseBody == null)
            responseBody = "command is " + ((status == 200) ? "succeed!" : "failed");

        resp.getWriter().write(responseBody);

        if (log.isInfoEnabled())
            log.info("Execution result of service command is " + commandResp.isSuccess() + ".");

    } catch (Exception ex) {
        log.error("Unexpected error occurred.", ex);
        resp.sendError(500, ex.getMessage());
    }
}

From source file:org.springframework.richclient.application.ApplicationLauncher.java

/**
 * Launches the rich client application. If no startup context has so far
 * been provided, the main application context will be searched for a splash
 * screen to display. The main application context will then be searched for
 * the {@link Application} to be launched, using the bean name
 * {@link #APPLICATION_BEAN_ID}. If the application is found, it will be
 * started./*from w ww.jav  a  2 s  .c  o  m*/
 *
 */
private void launchMyRichClient() {

    if (startupContext == null) {
        displaySplashScreen(rootApplicationContext);
    }

    final Application application;

    try {
        application = (Application) rootApplicationContext.getBean(APPLICATION_BEAN_ID, Application.class);
    } catch (NoSuchBeanDefinitionException e) {
        throw new IllegalArgumentException(
                "A single bean definition with id " + APPLICATION_BEAN_ID + ", of type "
                        + Application.class.getName() + " must be defined in the main application context",
                e);
    }

    try {
        // To avoid deadlocks when events fire during initialization of some swing components
        // Possible to do: in theory not a single Swing component should be created (=modified) in the launcher thread...
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                application.start();
            }
        });
    } catch (InterruptedException e) {
        logger.warn("Application start interrupted", e);
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        throw new IllegalStateException("Application start thrown an exception: " + cause.getMessage(), cause);
    }

    logger.debug("Launcher thread exiting...");

}