Search in sources :

Example 6 with AdminCommand

use of org.glassfish.api.admin.AdminCommand in project Payara by payara.

the class CommandResourceMetaData method getRestRedirectPointToBean.

@SuppressWarnings("unchecked")
public static List<CommandResourceMetaData> getRestRedirectPointToBean(String beanName) {
    synchronized (restRedirects) {
        if (restRedirects.isEmpty()) {
            final ServiceLocator habitat = Globals.getDefaultHabitat();
            processConfigBeans(habitat);
            List<ActiveDescriptor<?>> iter = habitat.getDescriptors(BuilderHelper.createContractFilter(AdminCommand.class.getName()));
            for (ActiveDescriptor<?> ad : iter) {
                if (!(ad.getQualifiers().contains(RestEndpoints.class.getName()))) {
                    continue;
                }
                if (!ad.isReified()) {
                    try {
                        habitat.reifyDescriptor(ad);
                    } catch (MultiException me) {
                        // If we can't see the command, forget it
                        continue;
                    }
                }
                final Class<? extends AdminCommand> clazz = (Class<? extends AdminCommand>) ad.getImplementationClass();
                RestEndpoints endpoints = clazz.getAnnotation(RestEndpoints.class);
                if (endpoints != null) {
                    RestEndpoint[] list = endpoints.value();
                    if ((list != null) && (list.length > 0)) {
                        for (RestEndpoint endpoint : list) {
                            Service service = clazz.getAnnotation(Service.class);
                            String configBean = endpoint.configBean().getSimpleName();
                            CommandResourceMetaData metaData = new CommandResourceMetaData();
                            metaData.command = service.name();
                            metaData.httpMethod = endpoint.opType().name();
                            metaData.resourcePath = endpoint.path().isEmpty() ? service.name() : endpoint.path();
                            metaData.displayName = endpoint.description().isEmpty() ? metaData.resourcePath : endpoint.description();
                            metaData.commandParams = new ParameterMetaData[endpoint.params().length];
                            int index = 0;
                            for (RestParam param : endpoint.params()) {
                                ParameterMetaData currentParam = new ParameterMetaData();
                                metaData.commandParams[index] = currentParam;
                                currentParam.name = param.name();
                                currentParam.value = param.value();
                                index++;
                            }
                            addCommandMetaData(configBean, metaData);
                        }
                    }
                }
            }
        }
    }
    return restRedirects.get(beanName);
}
Also used : ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) Service(org.jvnet.hk2.annotations.Service) RestEndpoints(org.glassfish.api.admin.RestEndpoints) RestEndpoint(org.glassfish.api.admin.RestEndpoint) RestEndpoint(org.glassfish.api.admin.RestEndpoint) RestParam(org.glassfish.api.admin.RestParam) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) AdminCommand(org.glassfish.api.admin.AdminCommand) MultiException(org.glassfish.hk2.api.MultiException)

Aggregations

AdminCommand (org.glassfish.api.admin.AdminCommand)6 CommandRunner (org.glassfish.api.admin.CommandRunner)2 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)2 RemoteRestAdminCommand (com.sun.enterprise.admin.remote.RemoteRestAdminCommand)1 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)1 RestartDomainCommand (com.sun.enterprise.v3.admin.RestartDomainCommand)1 PlainTextActionReporter (com.sun.enterprise.v3.common.PlainTextActionReporter)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 LoginException (javax.security.auth.login.LoginException)1 ActionReport (org.glassfish.api.ActionReport)1 AdminCommandContext (org.glassfish.api.admin.AdminCommandContext)1 AdminCommandContextImpl (org.glassfish.api.admin.AdminCommandContextImpl)1 ParameterMap (org.glassfish.api.admin.ParameterMap)1 Payload (org.glassfish.api.admin.Payload)1 RestEndpoint (org.glassfish.api.admin.RestEndpoint)1 RestEndpoints (org.glassfish.api.admin.RestEndpoints)1 RestParam (org.glassfish.api.admin.RestParam)1 ActiveDescriptor (org.glassfish.hk2.api.ActiveDescriptor)1 MultiException (org.glassfish.hk2.api.MultiException)1