Search in sources :

Example 6 with ConfigBeanProxy

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

the class WebContainerImpl method bind.

private void bind(Port port, WebListener webListener, String vsId) {
    String protocol = Port.HTTP_PROTOCOL;
    final int portNumber = port.getPortNumber();
    final String defaultVS = vsId;
    final WebListener listener = webListener;
    if (webListener == null) {
        listenerName = getListenerName();
        webListener = new HttpListener();
        webListener.setId(listenerName);
        webListener.setPort(portNumber);
    } else {
        listenerName = webListener.getId();
        protocol = webListener.getProtocol();
    }
    listeners.add(webListener);
    if (protocol.equals(Port.HTTP_PROTOCOL)) {
        securityEnabled = "false";
    } else if (protocol.equals(Port.HTTPS_PROTOCOL)) {
        securityEnabled = "true";
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Protocols>() {

            public Object run(Protocols param) throws TransactionFailure {
                final Protocol protocol = param.createChild(Protocol.class);
                protocol.setName(listenerName);
                protocol.setSecurityEnabled(securityEnabled);
                param.getProtocol().add(protocol);
                final Http http = protocol.createChild(Http.class);
                http.setDefaultVirtualServer(defaultVS);
                http.setFileCache(http.createChild(FileCache.class));
                protocol.setHttp(http);
                return protocol;
            }
        }, networkConfig.getProtocols());
        ConfigSupport.apply(new ConfigCode() {

            public Object run(ConfigBeanProxy... params) throws TransactionFailure {
                NetworkListeners nls = (NetworkListeners) params[0];
                Transports transports = (Transports) params[1];
                final NetworkListener listener = nls.createChild(NetworkListener.class);
                listener.setName(listenerName);
                listener.setPort(Integer.toString(portNumber));
                listener.setProtocol(listenerName);
                listener.setThreadPool("http-thread-pool");
                if (listener.findThreadPool() == null) {
                    final ThreadPool pool = nls.createChild(ThreadPool.class);
                    pool.setName(listenerName);
                    listener.setThreadPool(listenerName);
                }
                listener.setTransport("tcp");
                if (listener.findTransport() == null) {
                    final Transport transport = transports.createChild(Transport.class);
                    transport.setName(listenerName);
                    listener.setTransport(listenerName);
                }
                nls.getNetworkListener().add(listener);
                return listener;
            }
        }, networkConfig.getNetworkListeners(), networkConfig.getTransports());
        if (webListener.getProtocol().equals("https")) {
            NetworkListener networkListener = networkConfig.getNetworkListener(listenerName);
            Protocol httpProtocol = networkListener.findHttpProtocol();
            ConfigSupport.apply(new SingleConfigCode<Protocol>() {

                public Object run(Protocol param) throws TransactionFailure {
                    Ssl newSsl = param.createChild(Ssl.class);
                    populateSslElement(newSsl, listener);
                    System.out.println("SSL " + newSsl.getKeyStore() + " " + newSsl.getKeyStorePassword() + " " + newSsl.getTrustStore() + " " + newSsl.getTrustStorePassword());
                    param.setSsl(newSsl);
                    return newSsl;
                }
            }, httpProtocol);
        }
        com.sun.enterprise.config.serverbeans.VirtualServer vs = httpService.getVirtualServerByName(config.getVirtualServerId());
        ConfigSupport.apply(new SingleConfigCode<com.sun.enterprise.config.serverbeans.VirtualServer>() {

            public Object run(com.sun.enterprise.config.serverbeans.VirtualServer avs) throws PropertyVetoException {
                avs.addNetworkListener(listenerName);
                return avs;
            }
        }, vs);
    } catch (Exception e) {
        if (listeners.contains(webListener)) {
            listeners.remove(webListener);
        }
        e.printStackTrace();
    }
}
Also used : Protocols(org.glassfish.grizzly.config.dom.Protocols) ThreadPool(org.glassfish.grizzly.config.dom.ThreadPool) Http(org.glassfish.grizzly.config.dom.Http) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) HttpListener(org.glassfish.embeddable.web.HttpListener) Protocol(org.glassfish.grizzly.config.dom.Protocol) Transports(org.glassfish.grizzly.config.dom.Transports) Ssl(org.glassfish.grizzly.config.dom.Ssl) VirtualServer(org.glassfish.embeddable.web.VirtualServer) PropertyVetoException(java.beans.PropertyVetoException) ConfigException(org.glassfish.embeddable.web.ConfigException) GlassFishException(org.glassfish.embeddable.GlassFishException) PropertyVetoException(java.beans.PropertyVetoException) WebListener(org.glassfish.embeddable.web.WebListener) Transport(org.glassfish.grizzly.config.dom.Transport) org.jvnet.hk2.config(org.jvnet.hk2.config) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 7 with ConfigBeanProxy

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

the class ParentTest method parents.

@Test
public void parents() {
    NetworkListeners service = getHabitat().getService(NetworkListeners.class);
    assertNotNull(service);
    NetworkListener listener = service.getNetworkListener().get(0);
    assertNotNull(listener);
    ConfigBeanProxy parent = service.getParent();
    assertNotNull(parent);
    NetworkListeners myService = listener.getParent(NetworkListeners.class);
    assertNotNull(myService);
    assertNotNull(myService.getNetworkListener().get(0).getName());
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test)

Example 8 with ConfigBeanProxy

use of org.jvnet.hk2.config.ConfigBeanProxy 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 9 with ConfigBeanProxy

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

the class BasicModularityTest method serializeConfigBean.

@Test
public void serializeConfigBean() {
    Config config = habitat.<Config>getService(Config.class, ServerEnvironmentImpl.DEFAULT_INSTANCE_NAME);
    ConfigBeanProxy prox = (ConfigBeanProxy) config.getExtensionByType(ConfigExtensionZero.class);
    String content = configModularityUtils.serializeConfigBean(prox);
    assertEquals("Cannot serialize config beans properly", "<config-extension-zero dummy=\"dummy-value\"></config-extension-zero>", content);
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Config(com.sun.enterprise.config.serverbeans.Config) ConfigApiTest(com.sun.enterprise.configapi.tests.ConfigApiTest) Test(org.junit.Test)

Example 10 with ConfigBeanProxy

use of org.jvnet.hk2.config.ConfigBeanProxy 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)

Aggregations

ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)41 PropertyVetoException (java.beans.PropertyVetoException)21 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)14 Method (java.lang.reflect.Method)11 ArrayList (java.util.ArrayList)11 ConfigCode (org.jvnet.hk2.config.ConfigCode)10 Config (com.sun.enterprise.config.serverbeans.Config)8 Server (com.sun.enterprise.config.serverbeans.Server)6 IOException (java.io.IOException)6 List (java.util.List)6 ActionReport (org.glassfish.api.ActionReport)6 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)6 Protocol (org.glassfish.grizzly.config.dom.Protocol)6 MultiException (org.glassfish.hk2.api.MultiException)6 ConfigModel (org.jvnet.hk2.config.ConfigModel)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 XMLStreamException (javax.xml.stream.XMLStreamException)5 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)5 ConfigBean (org.jvnet.hk2.config.ConfigBean)5 Property (org.jvnet.hk2.config.types.Property)5