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