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

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

Introduction

In this page you can find the example usage for org.springframework.beans.factory NoSuchBeanDefinitionException getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

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;//from www  . j a  va 2  s .  c  o 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());
    }
}