Search in sources :

Example 21 with VirtualServer

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

the class GrizzlyService method getAddressInfoFromVirtualServers.

// get the ports from the http listeners that are associated with
// the virtual servers
private List<AddressInfo> getAddressInfoFromVirtualServers(Collection<String> virtualServers) {
    List<AddressInfo> addressInfos = new ArrayList<AddressInfo>();
    List<NetworkListener> networkListenerList = config.getNetworkConfig().getNetworkListeners().getNetworkListener();
    for (String vs : virtualServers) {
        VirtualServer virtualServer = config.getHttpService().getVirtualServerByName(vs);
        if (virtualServer == null) {
            // non-existent virtual server
            LOGGER.log(Level.WARNING, KernelLoggerInfo.grizzlyNonExistentVS, vs);
            continue;
        }
        String vsNetworkListeners = virtualServer.getNetworkListeners();
        List<String> vsNetworkListenerList = StringUtils.parseStringList(vsNetworkListeners, ",");
        if (vsNetworkListenerList != null && !vsNetworkListenerList.isEmpty()) {
            for (String vsNetworkListener : vsNetworkListenerList) {
                for (NetworkListener networkListener : networkListenerList) {
                    if (networkListener.getName().equals(vsNetworkListener) && Boolean.valueOf(networkListener.getEnabled())) {
                        addressInfos.add(new AddressInfo(networkListener.getAddress(), networkListener.getPort()));
                        break;
                    }
                }
            }
        }
    }
    return addressInfos;
}
Also used : ArrayList(java.util.ArrayList) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 22 with VirtualServer

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

the class TranslatedViewCreationTest method createVirtualServerTest.

@Test
public void createVirtualServerTest() throws TransactionFailure {
    httpService = getHabitat().getService(HttpService.class);
    final TransactionListener listener = new TransactionListener() {

        public void transactionCommited(List<PropertyChangeEvent> changes) {
            events = changes;
        }

        public void unprocessedTransactedEvents(List<UnprocessedChangeEvents> changes) {
        }
    };
    Transactions transactions = getHabitat().getService(Transactions.class);
    try {
        transactions.addTransactionsListener(listener);
        assertTrue(httpService != null);
        ConfigSupport.apply(new SingleConfigCode<HttpService>() {

            public Object run(HttpService param) throws PropertyVetoException, TransactionFailure {
                VirtualServer newVirtualServer = param.createChild(VirtualServer.class);
                newVirtualServer.setDocroot("${" + propName + "}");
                newVirtualServer.setId("translated-view-creation");
                param.getVirtualServer().add(newVirtualServer);
                return null;
            }
        }, httpService);
        // first let check that our new virtual server has the right translated value
        VirtualServer vs = httpService.getVirtualServerByName("translated-view-creation");
        assertTrue(vs != null);
        String docRoot = vs.getDocroot();
        assertTrue("/foo/bar/docroot".equals(docRoot));
        transactions.waitForDrain();
        assertTrue(events != null);
        logger.fine("Number of events " + events.size());
        assertTrue(events.size() == 3);
        for (PropertyChangeEvent event : events) {
            if ("virtual-server".equals(event.getPropertyName())) {
                VirtualServer newVS = (VirtualServer) event.getNewValue();
                assertTrue(event.getOldValue() == null);
                docRoot = newVS.getDocroot();
                assertTrue("/foo/bar/docroot".equals(docRoot));
                VirtualServer rawView = GlassFishConfigBean.getRawView(newVS);
                assertTrue(rawView != null);
                assertTrue(rawView.getDocroot().equalsIgnoreCase("${" + propName + "}"));
                return;
            }
        }
        assertTrue(false);
    } finally {
        transactions.removeTransactionsListener(listener);
    }
}
Also used : TransactionListener(org.jvnet.hk2.config.TransactionListener) PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Transactions(org.jvnet.hk2.config.Transactions) PropertyChangeEvent(java.beans.PropertyChangeEvent) HttpService(com.sun.enterprise.config.serverbeans.HttpService) List(java.util.List) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) Test(org.junit.Test)

Example 23 with VirtualServer

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

the class DuplicateKeyedElementTest method duplicateKeyTest.

@Test(expected = TransactionFailure.class)
public void duplicateKeyTest() 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);
    final Property prop = target.getProperty().get(0);
    Property newProp = (Property) ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {

        public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
            // first one is fine...
            Property dupProp = param.createChild(Property.class);
            dupProp.setName(prop.getName());
            dupProp.setValue(prop.getValue().toUpperCase());
            // this should fail...
            param.getProperty().add(dupProp);
            return dupProp;
        }
    }, 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)

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