Search in sources :

Example 6 with TYPE

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

the class GetHttpListener method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    // Check that a configuration can be found
    if (targetUtil.getConfig(target) == null) {
        report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_CONFIG), target));
        return;
    }
    Config config = targetUtil.getConfig(target);
    // Check that a matching listener can be found
    List<NetworkListener> listeners = config.getNetworkConfig().getNetworkListeners().getNetworkListener();
    Optional<NetworkListener> optionalListener = listeners.stream().filter(listener -> listener.getName().equals(listenerName)).findFirst();
    if (!optionalListener.isPresent()) {
        report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_NETWORK_LISTENER), listenerName, target));
        return;
    }
    NetworkListener listener = optionalListener.get();
    // Write message body
    report.appendMessage(String.format("Name: %s\n", listener.getName()));
    report.appendMessage(String.format("Enabled: %s\n", listener.getEnabled()));
    report.appendMessage(String.format("Port: %s\n", listener.getPort()));
    if (listener.getPortRange() != null) {
        report.appendMessage(String.format("Port Range: %s\n", listener.getPortRange()));
    }
    report.appendMessage(String.format("Address: %s\n", listener.getAddress()));
    report.appendMessage(String.format("Protocol: %s\n", listener.getProtocol()));
    if (verbose) {
        report.appendMessage(String.format("Transport: %s\n", listener.getTransport()));
        report.appendMessage(String.format("Type: %s\n", listener.getType()));
        report.appendMessage(String.format("Thread Pool: %s\n", listener.getThreadPool()));
        report.appendMessage(String.format("JK Enabled: %s\n", listener.getJkEnabled()));
        report.appendMessage(String.format("JK Configuration File: %s\n", listener.getJkConfigurationFile()));
    }
    // Write the variables as properties
    Properties properties = new Properties();
    properties.put("name", listener.getName());
    properties.put("enabled", listener.getEnabled());
    properties.put("port", listener.getPort());
    if (listener.getPortRange() != null) {
        properties.put("portRange", listener.getPortRange());
    }
    properties.put("address", listener.getAddress());
    properties.put("protocol", listener.getProtocol());
    properties.put("transport", listener.getTransport());
    properties.put("type", listener.getType());
    properties.put("threadPool", listener.getThreadPool());
    properties.put("jkEnabled", listener.getJkEnabled());
    properties.put("jkConfigurationFile", listener.getJkConfigurationFile());
    report.setExtraProperties(properties);
}
Also used : Param(org.glassfish.api.Param) LogFacade(org.glassfish.web.admin.LogFacade) RestEndpoint(org.glassfish.api.admin.RestEndpoint) CommandLock(org.glassfish.api.admin.CommandLock) MessageFormat(java.text.MessageFormat) I18n(org.glassfish.api.I18n) PerLookup(org.glassfish.hk2.api.PerLookup) Inject(javax.inject.Inject) ActionReport(org.glassfish.api.ActionReport) ExecuteOn(org.glassfish.api.admin.ExecuteOn) RuntimeType(org.glassfish.api.admin.RuntimeType) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) RestEndpoints(org.glassfish.api.admin.RestEndpoints) AdminCommand(org.glassfish.api.admin.AdminCommand) Properties(java.util.Properties) TargetType(org.glassfish.config.support.TargetType) Logger(java.util.logging.Logger) List(java.util.List) Target(org.glassfish.internal.api.Target) Service(org.jvnet.hk2.annotations.Service) AdminCommandContext(org.glassfish.api.admin.AdminCommandContext) CommandTarget(org.glassfish.config.support.CommandTarget) HttpService(com.sun.enterprise.config.serverbeans.HttpService) Optional(java.util.Optional) SystemPropertyConstants(com.sun.enterprise.util.SystemPropertyConstants) Config(com.sun.enterprise.config.serverbeans.Config) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 7 with TYPE

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

the class DomainXml method parseDomainXml.

/**
 * Parses <tt>domain.xml</tt>
 * @param parser
 * @param domainXml
 * @param serverName
 */
protected void parseDomainXml(ConfigParser parser, final URL domainXml, final String serverName) {
    long startNano = System.nanoTime();
    try {
        ServerReaderFilter xsr = null;
        // Set the resolver so that any external entity references, such
        // as a reference to a DTD, return an empty file.  The domain.xml
        // file doesn't support entity references.
        xif.setXMLResolver(new XMLResolver() {

            @Override
            public Object resolveEntity(String publicID, String systemID, String baseURI, String namespace) throws XMLStreamException {
                return new ByteArrayInputStream(new byte[0]);
            }
        });
        if (null == env.getRuntimeType()) {
            throw new RuntimeException("Internal Error: Unknown server type: " + env.getRuntimeType());
        } else {
            switch(env.getRuntimeType()) {
                case DAS:
                case EMBEDDED:
                case MICRO:
                    xsr = new DasReaderFilter(domainXml, xif);
                    break;
                case INSTANCE:
                    xsr = new InstanceReaderFilter(env.getInstanceName(), domainXml, xif);
                    break;
                default:
                    throw new RuntimeException("Internal Error: Unknown server type: " + env.getRuntimeType());
            }
        }
        Lock lock = null;
        try {
            // lock the domain.xml for reading if not embedded
            try {
                lock = configAccess.accessRead();
            } catch (Exception e) {
            // ignore
            }
            parser.parse(xsr, getDomDocument());
            xsr.close();
        } finally {
            if (lock != null) {
                lock.unlock();
            }
        }
        String errorMessage = xsr.configWasFound();
        if (errorMessage != null) {
            LogRecord lr = new LogRecord(Level.WARNING, errorMessage);
            lr.setLoggerName(getClass().getName());
            EarlyLogHandler.earlyMessages.add(lr);
        }
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        } else {
            throw new RuntimeException("Fatal Error.  Unable to parse " + domainXml, e);
        }
    }
    Long l = System.nanoTime() - startNano;
    LogRecord lr = new LogRecord(Level.FINE, totalTimeToParseDomain + l.toString());
    lr.setLoggerName(getClass().getName());
    EarlyLogHandler.earlyMessages.add(lr);
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ConfigPopulatorException(org.jvnet.hk2.config.ConfigPopulatorException) Lock(java.util.concurrent.locks.Lock) XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) LogRecord(java.util.logging.LogRecord) XMLResolver(javax.xml.stream.XMLResolver)

Example 8 with TYPE

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

the class GenericCrudCommand method elementName.

/**
 * Returns the element name used by the parent to store instances of the child
 *
 * @param document the dom document this configuration element lives in.
 * @param parent type of the parent
 * @param child type of the child
 * @return the element name holding child's instances in the parent
 * @throws ClassNotFoundException when subclasses cannot be loaded
 */
public static String elementName(DomDocument document, Class<?> parent, Class<?> child) throws ClassNotFoundException {
    ConfigModel cm = document.buildModel(parent);
    for (String elementName : cm.getElementNames()) {
        ConfigModel.Property prop = cm.getElement(elementName);
        if (prop instanceof ConfigModel.Node) {
            ConfigModel childCM = ((ConfigModel.Node) prop).getModel();
            String childTypeName = childCM.targetTypeName;
            if (childTypeName.equals(child.getName())) {
                return childCM.getTagName();
            }
            // check the inheritance hierarchy
            List<ConfigModel> subChildrenModels = document.getAllModelsImplementing(childCM.classLoaderHolder.loadClass(childTypeName));
            if (subChildrenModels != null) {
                for (ConfigModel subChildModel : subChildrenModels) {
                    if (subChildModel.targetTypeName.equals(child.getName())) {
                        return subChildModel.getTagName();
                    }
                }
            }
        }
    }
    return null;
}
Also used : ConfigModel(org.jvnet.hk2.config.ConfigModel)

Example 9 with TYPE

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

the class TargetBasedResolver method getTarget.

private <T extends ConfigBeanProxy> T getTarget(Class<? extends ConfigBeanProxy> targetType, Class<T> type) throws ClassNotFoundException {
    // when using the target based parameter, we look first for a configuration of that name,
    // then we look for a cluster of that name and finally we look for a subelement of the right type
    final String name = getName();
    ConfigBeanProxy config = habitat.getService(targetType, target);
    if (config != null) {
        try {
            return type.cast(config);
        } catch (ClassCastException e) {
        // ok we need to do more work to find which object is really requested.
        }
        Dom parentDom = Dom.unwrap(config);
        String elementName = GenericCrudCommand.elementName(parentDom.document, targetType, type);
        if (elementName == null) {
            return null;
        }
        ConfigModel.Property property = parentDom.model.getElement(elementName);
        if (property.isCollection()) {
            Collection<Dom> collection;
            synchronized (parentDom) {
                collection = parentDom.nodeElements(elementName);
            }
            if (collection == null) {
                return null;
            }
            for (Dom child : collection) {
                if (name.equals(child.attribute("ref"))) {
                    return type.cast(child.<ConfigBeanProxy>createProxy());
                }
            }
        }
    }
    return null;
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Dom(org.jvnet.hk2.config.Dom) ConfigModel(org.jvnet.hk2.config.ConfigModel)

Example 10 with TYPE

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

the class ConfigBeanJMXSupport method getTypeString.

public String getTypeString(final Class<? extends ConfigBeanProxy> intf) {
    String type = null;
    final Configured configuredAnnotation = intf.getAnnotation(Configured.class);
    if (configuredAnnotation != null && configuredAnnotation.name().length() != 0) {
        type = configuredAnnotation.name();
        if (type == null || type.length() == 0) {
            throw new IllegalArgumentException("ConfigBeanJMXSupport.getTypeString(): Malformed @Configured annotation on " + intf.getName());
        }
    } else {
        final Package pkg = intf.getPackage();
        String simple = intf.getName().substring(pkg.getName().length() + 1, intf.getName().length());
        type = Util.typeFromName(simple);
        if (type == null || type.length() == 0) {
            throw new IllegalArgumentException("ConfigBeanJMXSupport.getTypeString(): Malformed type generated from " + intf.getName());
        }
    }
    return type;
}
Also used : Configured(org.jvnet.hk2.config.Configured)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)15 Property (org.jvnet.hk2.config.types.Property)15 IOException (java.io.IOException)13 ActionReport (org.glassfish.api.ActionReport)13 PropertyVetoException (java.beans.PropertyVetoException)12 List (java.util.List)10 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)10 Method (java.lang.reflect.Method)9 HashMap (java.util.HashMap)9 Map (java.util.Map)7 Logger (java.util.logging.Logger)7 Service (org.jvnet.hk2.annotations.Service)7 ArrayList (java.util.ArrayList)6 Inject (javax.inject.Inject)6 MultiException (org.glassfish.hk2.api.MultiException)6 ConfigBean (org.jvnet.hk2.config.ConfigBean)6 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)5 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)4 Collection (java.util.Collection)4 DeploymentException (org.glassfish.deployment.common.DeploymentException)4