Search in sources :

Example 6 with VirtualServer

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

the class GrizzlyConfigSchemaMigrator method promoteVirtualServerProperties.

private void promoteVirtualServerProperties(HttpService service) throws TransactionFailure {
    for (VirtualServer virtualServer : service.getVirtualServer()) {
        ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {

            @Override
            public Object run(VirtualServer param) throws PropertyVetoException {
                if (param.getHttpListeners() != null && !"".equals(param.getHttpListeners())) {
                    param.setNetworkListeners(param.getHttpListeners());
                }
                param.setHttpListeners(null);
                final List<Property> propertyList = new ArrayList<Property>(param.getProperty());
                final Iterator<Property> it = propertyList.iterator();
                while (it.hasNext()) {
                    final Property property = it.next();
                    if ("docroot".equals(property.getName())) {
                        param.setDocroot(property.getValue());
                        it.remove();
                    } else if ("accesslog".equals(property.getName())) {
                        param.setAccessLog(property.getValue());
                        it.remove();
                    } else if ("sso-enabled".equals(property.getName())) {
                        param.setSsoEnabled(property.getValue());
                        it.remove();
                    }
                }
                param.getProperty().clear();
                param.getProperty().addAll(propertyList);
                return null;
            }
        }, virtualServer);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Property(org.jvnet.hk2.config.types.Property) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer)

Example 7 with VirtualServer

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

the class AttributeRemovalTest method removeAttributeTest.

@Test
public void removeAttributeTest() throws TransactionFailure {
    HttpService httpService = Utils.instance.getHabitat(this).getService(HttpService.class);
    VirtualServer vs = httpService.getVirtualServerByName("server");
    ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {

        public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
            param.setDefaultWebModule("/context/bar");
            return null;
        }
    }, vs);
    // ensure it's here
    org.junit.Assert.assertNotNull(vs.getDefaultWebModule());
    ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {

        public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
            param.setDefaultWebModule(null);
            return null;
        }
    }, vs);
    // ensure it's removed
    org.junit.Assert.assertNull(vs.getDefaultWebModule());
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) HttpService(com.sun.enterprise.config.serverbeans.HttpService) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) Test(org.junit.Test)

Example 8 with VirtualServer

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

the class DuplicateKeyedElementTest method identicalKeyTest.

@Test(expected = TransactionFailure.class)
public void identicalKeyTest() throws TransactionFailure {
    HttpService httpService = getHabitat().getService(HttpService.class);
    assertNotNull(httpService);
    // let's find a acceptable target.
    VirtualServer target = null;
    for (VirtualServer vs : httpService.getVirtualServer()) {
        if (!vs.getProperty().isEmpty()) {
            target = vs;
            break;
        }
    }
    assertNotNull(target);
    Property newProp = (Property) ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {

        public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
            // first one is fine...
            Property firstProp = param.createChild(Property.class);
            firstProp.setName("foo");
            firstProp.setValue("bar");
            param.getProperty().add(firstProp);
            // this should fail...
            Property secondProp = param.createChild(Property.class);
            secondProp.setName("foo");
            secondProp.setValue("bar");
            param.getProperty().add(secondProp);
            return secondProp;
        }
    }, target);
    // if we arrive here, this is an error, we succeeded adding a property with
    // the same key name.
    assertTrue(false);
}
Also used : SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) HttpService(com.sun.enterprise.config.serverbeans.HttpService) Property(org.jvnet.hk2.config.types.Property) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) Test(org.junit.Test)

Example 9 with VirtualServer

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

the class GetHostAndPortCommand method getHostAndPort.

private HostAndPort getHostAndPort(HttpService httpService, VirtualServer vs, boolean securityEnabled) {
    List<VirtualServer> virtualServerList = httpService.getVirtualServer();
    List<NetworkListener> httpListenerList = httpService.getParent(Config.class).getNetworkConfig().getNetworkListeners().getNetworkListener();
    for (VirtualServer virtualServer : virtualServerList) {
        if (!virtualServer.getId().equals(vs.getId())) {
            continue;
        }
        String vsHttpListeners = virtualServer.getNetworkListeners();
        if (vsHttpListeners == null) {
            continue;
        }
        List<String> vsHttpListenerList = StringUtils.parseStringList(vsHttpListeners, " ,");
        for (String vsHttpListener : vsHttpListenerList) {
            for (NetworkListener httpListener : httpListenerList) {
                if (!httpListener.getName().equals(vsHttpListener)) {
                    continue;
                }
                if (!Boolean.valueOf(httpListener.getEnabled())) {
                    continue;
                }
                final Protocol protocol = httpListener.findHttpProtocol();
                if (Boolean.valueOf(protocol.getSecurityEnabled()) == securityEnabled) {
                    String serverName = protocol.getHttp().getServerName();
                    if (serverName == null || serverName.trim().equals("")) {
                        serverName = DeploymentCommandUtils.getLocalHostName();
                    }
                    String portStr = httpListener.getPort();
                    String redirPort = protocol.getHttp().getRedirectPort();
                    if (redirPort != null && !redirPort.trim().equals("")) {
                        portStr = redirPort;
                    }
                    int port = Integer.parseInt(portStr);
                    return new HostAndPort(serverName, port, securityEnabled);
                }
            }
        }
    }
    return null;
}
Also used : HostAndPort(com.sun.enterprise.util.HostAndPort) Config(com.sun.enterprise.config.serverbeans.Config) Protocol(org.glassfish.grizzly.config.dom.Protocol) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) RestEndpoint(org.glassfish.api.admin.RestEndpoint) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 10 with VirtualServer

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

the class GetHostAndPortCommand method getHostAndPortForRequest.

private HostAndPort getHostAndPortForRequest(HttpService httpService) throws Exception {
    if (moduleId == null) {
        if (virtualServer == null) {
            return getHostAndPort(httpService, securityEnabled);
        } else {
            VirtualServer vs = httpService.getVirtualServerByName(virtualServer);
            if (vs == null) {
                throw new Exception("Virtual server: " + virtualServer + " does not exist!");
            }
            return getHostAndPort(httpService, vs, securityEnabled);
        }
    }
    ApplicationRef appRef = domain.getApplicationRefInTarget(moduleId, target);
    List<String> vsList = null;
    if (appRef != null) {
        vsList = StringUtils.parseStringList(appRef.getVirtualServers(), " ,");
    }
    if (vsList == null) {
        return getHostAndPort(httpService, securityEnabled);
    }
    for (String virtualServer : vsList) {
        HostAndPort hp = getHostAndPort(httpService, httpService.getVirtualServerByName(virtualServer), securityEnabled);
        if (hp != null) {
            return hp;
        }
    }
    return null;
}
Also used : HostAndPort(com.sun.enterprise.util.HostAndPort) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer)

Aggregations

VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)23 HttpService (com.sun.enterprise.config.serverbeans.HttpService)10 Property (org.jvnet.hk2.config.types.Property)8 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)7 Config (com.sun.enterprise.config.serverbeans.Config)6 PropertyVetoException (java.beans.PropertyVetoException)6 ActionReport (org.glassfish.api.ActionReport)5 Protocol (org.glassfish.grizzly.config.dom.Protocol)5 Target (org.glassfish.internal.api.Target)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 CommandTarget (org.glassfish.config.support.CommandTarget)4 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)4 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)4 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)3 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)2 HostAndPort (com.sun.enterprise.util.HostAndPort)2 List (java.util.List)2 ThreadPool (org.glassfish.grizzly.config.dom.ThreadPool)2 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)2