Search in sources :

Example 11 with TYPE

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

the class WebConfigListener method changed.

/**
 * Handles HttpService change events
 * @param events the PropertyChangeEvent
 */
@Override
public synchronized UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
    return ConfigSupport.sortAndDispatch(events, new Changed() {

        @Override
        public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> tClass, T t) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, LogFacade.CHANGE_INVOKED, new Object[] { type, tClass, t });
            }
            try {
                if (tClass == HttpService.class) {
                    container.updateHttpService((HttpService) t);
                } else if (tClass == NetworkListener.class) {
                    if (type == TYPE.ADD) {
                        container.addConnector((NetworkListener) t, httpService, true);
                    } else if (type == TYPE.REMOVE) {
                        container.deleteConnector((NetworkListener) t);
                    } else if (type == TYPE.CHANGE) {
                        container.updateConnector((NetworkListener) t, httpService);
                    }
                } else if (tClass == VirtualServer.class) {
                    if (type == TYPE.ADD) {
                        container.createHost((VirtualServer) t, httpService, null);
                        container.loadDefaultWebModule((VirtualServer) t);
                    } else if (type == TYPE.REMOVE) {
                        container.deleteHost(httpService);
                    } else if (type == TYPE.CHANGE) {
                        container.updateHost((VirtualServer) t);
                    }
                } else if (tClass == AccessLog.class) {
                    container.updateAccessLog(httpService);
                } else if (tClass == ManagerProperties.class) {
                    return new NotProcessed("ManagerProperties requires restart");
                } else if (tClass == WebContainerAvailability.class || tClass == AvailabilityService.class) {
                    // container.updateHttpService handles SingleSignOn valve configuration
                    container.updateHttpService(httpService);
                } else if (tClass == NetworkListeners.class) {
                // skip updates
                } else if (tClass == Property.class) {
                    ConfigBeanProxy config = ((Property) t).getParent();
                    if (config instanceof HttpService) {
                        container.updateHttpService((HttpService) config);
                    } else if (config instanceof VirtualServer) {
                        container.updateHost((VirtualServer) config);
                    } else if (config instanceof NetworkListener) {
                        container.updateConnector((NetworkListener) config, httpService);
                    } else {
                        container.updateHttpService(httpService);
                    }
                } else if (tClass == SystemProperty.class) {
                    if (((SystemProperty) t).getName().endsWith("LISTENER_PORT")) {
                        for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
                            if (listener.getPort().equals(((SystemProperty) t).getValue())) {
                                container.updateConnector(listener, httpService);
                            }
                        }
                    }
                } else if (tClass == JavaConfig.class) {
                    JavaConfig jc = (JavaConfig) t;
                    final List<String> jvmOptions = new ArrayList<String>(jc.getJvmOptions());
                    for (String jvmOption : jvmOptions) {
                        if (jvmOption.startsWith("-DjvmRoute=")) {
                            container.updateJvmRoute(httpService, jvmOption);
                        }
                    }
                } else {
                // Ignore other unrelated events
                }
            } catch (LifecycleException le) {
                logger.log(Level.SEVERE, LogFacade.EXCEPTION_WEB_CONFIG, le);
            }
            return null;
        }
    }, logger);
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) AvailabilityService(com.sun.enterprise.config.serverbeans.AvailabilityService) ArrayList(java.util.ArrayList) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) ManagerProperties(org.glassfish.web.config.serverbeans.ManagerProperties) WebContainerAvailability(org.glassfish.web.config.serverbeans.WebContainerAvailability) HttpService(com.sun.enterprise.config.serverbeans.HttpService) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) Property(org.jvnet.hk2.config.types.Property) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 12 with TYPE

use of org.jvnet.hk2.config.Changed.TYPE 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
 */
@Override
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")) && (listenerId == null)) {
        report.setMessage(LOCAL_STRINGS.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(LOCAL_STRINGS.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(LOCAL_STRINGS.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>() {

                @Override
                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 13 with TYPE

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

the class CompositeUtil method analyzeInterface.

private void analyzeInterface(Class<?> iface, Map<String, Map<String, Object>> properties) throws SecurityException {
    // find class level bean reference
    String defaultBean = null;
    if (iface.isAnnotationPresent(DefaultBeanReference.class)) {
        DefaultBeanReference beanRef = iface.getAnnotation(DefaultBeanReference.class);
        defaultBean = beanRef.bean();
    }
    for (Method method : iface.getMethods()) {
        String name = method.getName();
        final boolean isGetter = name.startsWith("get");
        if (isGetter || name.startsWith("set")) {
            name = name.substring(3);
            Map<String, Object> property = properties.get(name);
            if (property == null) {
                property = new HashMap<String, Object>();
                properties.put(name, property);
            }
            String bean = null;
            String attribute = null;
            AttributeReference ar = method.getAnnotation(AttributeReference.class);
            if (ar != null) {
                bean = ar.bean();
                attribute = ar.attribute();
            }
            if (!StringUtil.notEmpty(bean)) {
                bean = defaultBean;
            }
            if (!StringUtil.notEmpty(attribute)) {
                attribute = name;
            }
            if (StringUtil.notEmpty(bean) && StringUtil.notEmpty(attribute)) {
                property.put("annotations", gatherReferencedAttributes(bean, attribute));
            }
            Attribute attr = method.getAnnotation(Attribute.class);
            if (attr != null) {
                property.put("defaultValue", attr.defaultValue());
            }
            Class<?> type = isGetter ? method.getReturnType() : method.getParameterTypes()[0];
            property.put("type", type);
        }
    }
}
Also used : DefaultBeanReference(org.glassfish.admin.rest.composite.metadata.DefaultBeanReference) Attribute(org.jvnet.hk2.config.Attribute) AttributeReference(org.glassfish.admin.rest.composite.metadata.AttributeReference) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString) Method(java.lang.reflect.Method)

Example 14 with TYPE

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

the class ClientGenerator method processAttributes.

protected void processAttributes(ClientClassWriter writer, ConfigModel model, Set<String> processed) {
    Class clazz = model.getProxyType();
    for (Method method : clazz.getMethods()) {
        String methodName = method.getName();
        Attribute a = method.getAnnotation(Attribute.class);
        Param p = method.getAnnotation(Param.class);
        if ((a != null) || (p != null)) {
            String type = "String";
            if (a != null) {
                type = a.dataType().getName();
            }
            if (methodName.startsWith("get") || methodName.startsWith("set")) {
                methodName = methodName.substring(3);
            }
            String fieldName = Util.lowerCaseFirstLetter(methodName);
            if (processed.contains(fieldName)) {
                continue;
            }
            processed.add(fieldName);
            writer.generateGettersAndSetters(type, methodName, fieldName);
        }
    }
}
Also used : Attribute(org.jvnet.hk2.config.Attribute) Param(org.glassfish.api.Param) Method(java.lang.reflect.Method)

Example 15 with TYPE

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

the class ConfigModularityUtils method setConfigBean.

public <T extends ConfigBeanProxy> T setConfigBean(T finalConfigBean, ConfigBeanDefaultValue configBeanDefaultValue, ConfigBeanProxy parent) {
    Class owningClassForLocation = getOwningClassForLocation(configBeanDefaultValue.getLocation());
    Class configBeanClass = getClassForFullName(configBeanDefaultValue.getConfigBeanClassName());
    try {
        ConfigBeanProxy configBeanInstance = null;
        if (getNameForConfigBean(finalConfigBean, configBeanClass) == null) {
            List<ConfigBeanProxy> extensions = getExtensions(parent);
            for (ConfigBeanProxy extension : extensions) {
                try {
                    configBeanInstance = (ConfigBeanProxy) configBeanClass.cast(extension);
                    break;
                } catch (Exception e) {
                // ignore, not the right type.
                }
            }
            if (!configBeanDefaultValue.replaceCurrentIfExists() || !stackPositionHigher(finalConfigBean, configBeanInstance)) {
                if (configBeanInstance != null)
                    return (T) configBeanInstance;
            }
            if (configBeanInstance != null) {
                extensions.remove(configBeanInstance);
            }
        }
    } catch (InvocationTargetException e) {
        LOG.log(Level.INFO, cannotSetConfigBean, e);
    } catch (IllegalAccessException e) {
        LOG.log(Level.INFO, cannotSetConfigBean, e);
    }
    Method m = getMatchingSetterMethod(owningClassForLocation, configBeanClass);
    if (m != null) {
        try {
            if (configBeanClass.getAnnotation(HasCustomizationTokens.class) != null) {
                applyCustomTokens(configBeanDefaultValue, finalConfigBean, parent);
            }
            m.invoke(parent, finalConfigBean);
        } catch (Exception e) {
            LogHelper.log(LOG, Level.INFO, cannotSetConfigBeanFor, e, finalConfigBean.getClass().getName());
        }
        return finalConfigBean;
    }
    m = findSuitableCollectionGetter(owningClassForLocation, configBeanClass);
    if (m != null) {
        try {
            Collection col = (Collection) m.invoke(parent);
            String name = getNameForConfigBean(finalConfigBean, configBeanClass);
            ConfigBeanProxy itemToRemove = getNamedConfigBeanFromCollection(col, name, configBeanClass);
            if (configBeanDefaultValue.replaceCurrentIfExists()) {
                try {
                    if (itemToRemove != null) {
                        if (stackPositionHigher(finalConfigBean, itemToRemove)) {
                            col.remove(itemToRemove);
                        }
                    }
                } catch (Exception ex) {
                    LogHelper.log(LOG, Level.INFO, cannotRemoveConfigBean, ex, finalConfigBean.getClass().getName());
                }
            }
            if (configBeanClass.getAnnotation(HasCustomizationTokens.class) != null) {
                applyCustomTokens(configBeanDefaultValue, finalConfigBean, parent);
            }
            if (itemToRemove != null && !configBeanDefaultValue.replaceCurrentIfExists()) {
                // Check for duplication here.
                if (((ConfigView) Proxy.getInvocationHandler(itemToRemove)).getProxyType().isAssignableFrom(configBeanClass)) {
                    return finalConfigBean;
                }
            }
            col.add(finalConfigBean);
            return finalConfigBean;
        } catch (Exception e) {
            LogHelper.log(LOG, Level.INFO, cannotSetConfigBeanFor, e, finalConfigBean.getClass().getName());
        }
    }
    return null;
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Collection(java.util.Collection) Method(java.lang.reflect.Method) HasCustomizationTokens(com.sun.enterprise.config.modularity.annotation.HasCustomizationTokens) PropertyVetoException(java.beans.PropertyVetoException) XMLStreamException(javax.xml.stream.XMLStreamException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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