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;
}
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);
}
}
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);
}
Aggregations