Search in sources :

Example 1 with JavaConfig

use of com.sun.enterprise.config.serverbeans.JavaConfig 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 2 with JavaConfig

use of com.sun.enterprise.config.serverbeans.JavaConfig in project Payara by payara.

the class DirectAccessTest method doTest.

public void doTest() throws TransactionFailure {
    NetworkConfig networkConfig = habitat.getService(NetworkConfig.class);
    final NetworkListener listener = networkConfig.getNetworkListeners().getNetworkListener().get(0);
    final Http http = listener.findHttpProtocol().getHttp();
    ConfigBean config = (ConfigBean) ConfigBean.unwrap(http.getFileCache());
    ConfigBean config2 = (ConfigBean) ConfigBean.unwrap(http);
    Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
    Map<String, String> configChanges = new HashMap<String, String>();
    configChanges.put("max-age-seconds", "12543");
    configChanges.put("max-cache-size-bytes", "1200");
    Map<String, String> config2Changes = new HashMap<String, String>();
    config2Changes.put("http2-enabled", "false");
    changes.put(config, configChanges);
    changes.put(config2, config2Changes);
    JavaConfig javaConfig = habitat.getService(JavaConfig.class);
    ConfigBean javaConfigBean = (ConfigBean) ConfigBean.unwrap(javaConfig);
    Map<String, String> javaConfigChanges = new HashMap<String, String>();
    javaConfigChanges.put("jvm-options", "-XFooBar=false");
    changes.put(javaConfigBean, javaConfigChanges);
    getHabitat().<ConfigSupport>getService(ConfigSupport.class).apply(changes);
}
Also used : JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) HashMap(java.util.HashMap) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Http(org.glassfish.grizzly.config.dom.Http) ConfigBean(org.jvnet.hk2.config.ConfigBean) Map(java.util.Map) HashMap(java.util.HashMap) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 3 with JavaConfig

use of com.sun.enterprise.config.serverbeans.JavaConfig in project Payara by payara.

the class DirectCreationTest method doTest.

public void doTest() throws TransactionFailure {
    AdminService service = habitat.getService(AdminService.class);
    ConfigBean serviceBean = (ConfigBean) ConfigBean.unwrap(service);
    Class<?>[] subTypes = null;
    try {
        subTypes = ConfigSupport.getSubElementsTypes(serviceBean);
    } catch (ClassNotFoundException e) {
        // To change body of catch statement use File | Settings | File Templates.
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    ConfigSupport support = getBaseServiceLocator().getService(ConfigSupport.class);
    assertNotNull("ConfigSupport not found", support);
    for (Class<?> subType : subTypes) {
        // TODO:  JL force compilation error to mark this probably edit point for grizzly config
        if (subType.getName().endsWith("DasConfig")) {
            Map<String, String> configChanges = new HashMap<String, String>();
            configChanges.put("dynamic-reload-enabled", "true");
            configChanges.put("autodeploy-dir", "funky-dir");
            support.createAndSet(serviceBean, (Class<? extends ConfigBeanProxy>) subType, configChanges);
            break;
        }
    }
    support.createAndSet(serviceBean, DasConfig.class, (List) null);
    List<AttributeChanges> profilerChanges = new ArrayList<AttributeChanges>();
    String[] values = { "-Xmx512m", "-RFtrq", "-Xmw24" };
    ConfigSupport.MultipleAttributeChanges multipleChanges = new ConfigSupport.MultipleAttributeChanges("jvm-options", values);
    String[] values1 = { "profile" };
    ConfigSupport.MultipleAttributeChanges multipleChanges1 = new ConfigSupport.MultipleAttributeChanges("name", values1);
    profilerChanges.add(multipleChanges);
    profilerChanges.add(multipleChanges1);
    support.createAndSet((ConfigBean) ConfigBean.unwrap(habitat.<JavaConfig>getService(JavaConfig.class)), Profiler.class, profilerChanges);
}
Also used : AdminService(com.sun.enterprise.config.serverbeans.AdminService) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) AttributeChanges(org.jvnet.hk2.config.AttributeChanges) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConfigBean(org.jvnet.hk2.config.ConfigBean) JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig)

Example 4 with JavaConfig

use of com.sun.enterprise.config.serverbeans.JavaConfig in project Payara by payara.

the class JavaConfigSubTypesTest method testSubTypesOfDomain.

@Test
public void testSubTypesOfDomain() {
    JavaConfig config = super.getHabitat().getService(JavaConfig.class);
    try {
        Class<?>[] subTypes = ConfigSupport.getSubElementsTypes((ConfigBean) ConfigBean.unwrap(config));
        boolean found = false;
        for (Class subType : subTypes) {
            Logger.getAnonymousLogger().fine("Found class " + subType);
            if (subType.getName().equals(List.class.getName())) {
                found = true;
            }
        }
        Assert.assertTrue(found);
        ;
    } catch (ClassNotFoundException e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
    }
}
Also used : JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) List(java.util.List) Test(org.junit.Test)

Example 5 with JavaConfig

use of com.sun.enterprise.config.serverbeans.JavaConfig in project Payara by payara.

the class CreateProfilerTest method tearDown.

@After
public void tearDown() throws TransactionFailure {
    // Delete the created profiler
    ConfigSupport.apply(new SingleConfigCode<JavaConfig>() {

        public Object run(JavaConfig param) throws PropertyVetoException, TransactionFailure {
            if (param.getProfiler() != null) {
                param.setProfiler(null);
            }
            return null;
        }
    }, javaConfig);
    parameters = new ParameterMap();
}
Also used : JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ParameterMap(org.glassfish.api.admin.ParameterMap) After(org.junit.After)

Aggregations

JavaConfig (com.sun.enterprise.config.serverbeans.JavaConfig)11 PropertyVetoException (java.beans.PropertyVetoException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Property (org.jvnet.hk2.config.types.Property)4 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)3 Config (com.sun.enterprise.config.serverbeans.Config)2 Profiler (com.sun.enterprise.config.serverbeans.Profiler)2 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)2 Map (java.util.Map)2 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)2 ConfigBean (org.jvnet.hk2.config.ConfigBean)2 ConfigSupport (org.jvnet.hk2.config.ConfigSupport)2 AdminService (com.sun.enterprise.config.serverbeans.AdminService)1 AvailabilityService (com.sun.enterprise.config.serverbeans.AvailabilityService)1 Cluster (com.sun.enterprise.config.serverbeans.Cluster)1 Domain (com.sun.enterprise.config.serverbeans.Domain)1 HttpService (com.sun.enterprise.config.serverbeans.HttpService)1