use of org.glassfish.embeddable.web.config.WebContainerConfig in project Payara by payara.
the class WebContainerImpl method setConfiguration.
// --------------------------------------------------------- Public Methods
public void setConfiguration(WebContainerConfig config) {
if (!initialized) {
init();
}
this.config = config;
final WebContainerConfig webConfig = config;
try {
VirtualServer vs = getVirtualServer(config.getVirtualServerId());
if (vs != null) {
((StandardHost) vs).setDefaultWebXmlLocation(config.getDefaultWebXml().getPath());
}
com.sun.enterprise.config.serverbeans.VirtualServer vsBean = httpService.getVirtualServerByName(config.getVirtualServerId());
if (vsBean != null) {
ConfigSupport.apply(new SingleConfigCode<com.sun.enterprise.config.serverbeans.VirtualServer>() {
public Object run(com.sun.enterprise.config.serverbeans.VirtualServer avs) throws PropertyVetoException, TransactionFailure {
avs.setId(webConfig.getVirtualServerId());
if (webConfig.getDocRootDir() != null) {
avs.setDocroot(webConfig.getDocRootDir().getAbsolutePath());
}
avs.setHosts(webConfig.getHostNames());
avs.setNetworkListeners(webConfig.getListenerName());
Property property = avs.createChild(Property.class);
property.setName("default-web-xml");
property.setValue(webConfig.getDefaultWebXml().getPath());
avs.getProperty().add(property);
return avs;
}
}, vsBean);
} else {
vs = createVirtualServer(config.getVirtualServerId(), config.getDocRootDir());
addVirtualServer(vs);
}
EmbeddedWebArchivist archivist = habitat.<EmbeddedWebArchivist>getService(EmbeddedWebArchivist.class);
archivist.setDefaultWebXml(config.getDefaultWebXml());
embedded.setDirectoryListing(config.getListings());
WebListener listener = getWebListener(config.getListenerName());
if (listener == null) {
listener = getWebListener(config.getPort());
if (listener == null) {
boolean found = false;
for (Map.Entry entry : webContainer.getConnectorMap().entrySet()) {
if (((WebConnector) entry.getValue()).getPort() == config.getPort()) {
found = true;
log.info("Port " + config.getPort() + " is already configured");
}
}
if (!found) {
listener = createWebListener(config.getListenerName(), HttpListener.class);
listener.setPort(config.getPort());
addWebListener(listener, config.getVirtualServerId());
}
}
} else {
if (listener.getPort() != config.getPort()) {
listener.setPort(config.getPort());
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.glassfish.embeddable.web.config.WebContainerConfig in project Payara by payara.
the class WebContainerImpl method init.
// --------------------------------------------------------- Private Methods
private void init() {
if (initialized) {
return;
}
if (config == null) {
// use default settings
config = new WebContainerConfig();
}
container = habitat.getServiceHandle(org.glassfish.api.container.Container.class, "com.sun.enterprise.web.WebContainer");
if (container == null) {
log.severe("Cannot find webcontainer implementation");
return;
}
ActiveDescriptor<?> activeDescriptor = habitat.getBestDescriptor(BuilderHelper.createContractFilter("com.sun.enterprise.web.EmbeddedWebContainer"));
if (activeDescriptor == null) {
log.severe("Cannot find embedded implementation");
return;
}
embeddedInhabitant = habitat.getServiceHandle(activeDescriptor);
try {
webContainer = (com.sun.enterprise.web.WebContainer) container.getService();
embedded = (EmbeddedWebContainer) embeddedInhabitant.getService();
if ((webContainer == null) || (embedded == null)) {
log.severe("Cannot find webcontainer implementation");
return;
}
engine = webContainer.getEngine();
if (engine == null) {
log.severe("Cannot find engine implementation");
return;
}
initialized = true;
} catch (Exception e) {
log.severe("Init exception " + e.getMessage());
}
}
Aggregations