Search in sources :

Example 16 with Element

use of org.jvnet.hk2.config.Element in project Payara by payara.

the class CreateSsl method addSslToJMXConnector.

private void addSslToJMXConnector(Config config, ActionReport report) {
    AdminService adminService = config.getAdminService();
    // ensure we have the specified listener
    JmxConnector jmxConnector = null;
    for (JmxConnector jmxConn : adminService.getJmxConnector()) {
        if (jmxConn.getName().equals(listenerId)) {
            jmxConnector = jmxConn;
        }
    }
    if (jmxConnector == null) {
        report.setMessage(localStrings.getLocalString("create.ssl.jmx.notfound", "JMX Connector named {0} to which this ssl element is " + "being added does not exist.", listenerId));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (jmxConnector.getSsl() != null) {
        report.setMessage(localStrings.getLocalString("create.ssl.jmx.alreadyExists", "IIOP Listener named {0} to which this ssl element is " + "being added already has an ssl element.", listenerId));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<JmxConnector>() {

            @Override
            public Object run(JmxConnector param) throws PropertyVetoException, TransactionFailure {
                Ssl newSsl = param.createChild(Ssl.class);
                populateSslElement(newSsl);
                param.setSsl(newSsl);
                return newSsl;
            }
        }, jmxConnector);
    } catch (TransactionFailure e) {
        reportError(report, e);
    }
    reportSuccess(report);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) AdminService(com.sun.enterprise.config.serverbeans.AdminService) JmxConnector(com.sun.enterprise.config.serverbeans.JmxConnector) Ssl(org.glassfish.grizzly.config.dom.Ssl)

Example 17 with Element

use of org.jvnet.hk2.config.Element in project Payara by payara.

the class DeleteSsl method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the parameter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    Target targetUtil = habitat.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    if (!type.equals("iiop-service")) {
        if (listenerId == null) {
            report.setMessage(localStrings.getLocalString("create.ssl.listenerid.missing", "Listener id needs to be specified"));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    try {
        SslConfigHandler sslConfigHandler = habitat.getService(SslConfigHandler.class, type);
        if (sslConfigHandler != null) {
            sslConfigHandler.delete(this, report);
        } else if ("jmx-connector".equals(type)) {
            JmxConnector jmxConnector = null;
            for (JmxConnector listener : config.getAdminService().getJmxConnector()) {
                if (listener.getName().equals(listenerId)) {
                    jmxConnector = listener;
                }
            }
            if (jmxConnector == null) {
                report.setMessage(localStrings.getLocalString("delete.ssl.jmx.connector.notfound", "Iiop Listener named {0} not found", listenerId));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
            if (jmxConnector.getSsl() == null) {
                report.setMessage(localStrings.getLocalString("delete.ssl.element.doesnotexist", "Ssl element does " + "not exist for Listener named {0}", listenerId));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
            ConfigSupport.apply(new SingleConfigCode<JmxConnector>() {

                public Object run(JmxConnector param) throws PropertyVetoException {
                    param.setSsl(null);
                    return null;
                }
            }, jmxConnector);
            report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        }
    } catch (TransactionFailure e) {
        reportError(report, e);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) ActionReport(org.glassfish.api.ActionReport)

Example 18 with Element

use of org.jvnet.hk2.config.Element in project Payara by payara.

the class ResourceUtil method getResourceLinks.

public static Map<String, String> getResourceLinks(List<Dom> proxyList, UriInfo uriInfo) {
    Map<String, String> links = new TreeMap<String, String>();
    Collections.sort(proxyList, new DomConfigurator());
    for (Dom proxy : proxyList) {
        // for each element
        try {
            links.put(getKey(proxy), getElementLink(uriInfo, getKey(proxy)));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return links;
}
Also used : Dom(org.jvnet.hk2.config.Dom) TreeMap(java.util.TreeMap) LoginException(javax.security.auth.login.LoginException) URISyntaxException(java.net.URISyntaxException) MultiException(org.glassfish.hk2.api.MultiException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Example 19 with Element

use of org.jvnet.hk2.config.Element in project Payara by payara.

the class ResourceUtil method getResourceLinks.

public static Map<String, String> getResourceLinks(Dom dom, UriInfo uriInfo, boolean canShowDeprecated) {
    Map<String, String> links = new TreeMap<String, String>();
    for (String elementName : dom.model.getElementNames()) {
        // for each element
        if (elementName.equals("*")) {
            ConfigModel.Node node = (ConfigModel.Node) dom.model.getElement(elementName);
            ConfigModel childModel = node.getModel();
            List<ConfigModel> lcm = getRealChildConfigModels(childModel, dom.document);
            Collections.sort(lcm, new ConfigModelComparator());
            if (lcm != null) {
                for (ConfigModel cmodel : lcm) {
                    if ((!isDeprecated(cmodel) || canShowDeprecated)) {
                        links.put(cmodel.getTagName(), ProviderUtil.getElementLink(uriInfo, cmodel.getTagName()));
                    }
                }
            }
        } else {
            ConfigModel.Property childElement = dom.model.getElement(elementName);
            boolean deprec = false;
            if (childElement instanceof ConfigModel.Node) {
                ConfigModel.Node node = (ConfigModel.Node) childElement;
                deprec = isDeprecated(node.getModel());
            }
            for (String annotation : childElement.getAnnotations()) {
                if (annotation.equals(Deprecated.class.getName())) {
                    deprec = true;
                }
            }
            if ((!deprec || canShowDeprecated)) {
                links.put(elementName, ProviderUtil.getElementLink(uriInfo, elementName));
            }
        }
    }
    String beanName = getUnqualifiedTypeName(dom.model.targetTypeName);
    for (CommandResourceMetaData cmd : CommandResourceMetaData.getCustomResourceMapping(beanName)) {
        links.put(cmd.resourcePath, ProviderUtil.getElementLink(uriInfo, cmd.resourcePath));
    }
    return links;
}
Also used : ConfigModel(org.jvnet.hk2.config.ConfigModel) CommandResourceMetaData(org.glassfish.admin.rest.generator.CommandResourceMetaData) TreeMap(java.util.TreeMap)

Example 20 with Element

use of org.jvnet.hk2.config.Element in project Payara by payara.

the class ConfigBeanJMXSupport method descriptor.

public static DescriptorSupport descriptor(final Element e) {
    final DescriptorSupport d = new DescriptorSupport();
    d.setField(DESC_KIND, Element.class.getName());
    d.setField(DESC_KEY, e.key());
    d.setField(DESC_REQUIRED, e.required());
    d.setField(DESC_REFERENCE, e.reference());
    d.setField(DESC_VARIABLE_EXPANSION, e.variableExpansion());
    return d;
}
Also used : Element(org.jvnet.hk2.config.Element) DescriptorSupport(javax.management.modelmbean.DescriptorSupport)

Aggregations

Property (org.jvnet.hk2.config.types.Property)14 PropertyVetoException (java.beans.PropertyVetoException)13 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)13 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 List (java.util.List)4 TreeMap (java.util.TreeMap)4 ActionReport (org.glassfish.api.ActionReport)4 MultiException (org.glassfish.hk2.api.MultiException)4 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)4 ConfigModel (org.jvnet.hk2.config.ConfigModel)4 Dom (org.jvnet.hk2.config.Dom)4 Application (com.sun.enterprise.config.serverbeans.Application)3 Domain (com.sun.enterprise.config.serverbeans.Domain)3 Server (com.sun.enterprise.config.serverbeans.Server)3 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)3 File (java.io.File)3 HashSet (java.util.HashSet)3 Iterator (java.util.Iterator)3