use of org.glassfish.grizzly.http.server.util.Mapper in project Payara by payara.
the class WebContainer method addConnector.
public WebConnector addConnector(NetworkListener httpListener, HttpService httpService, boolean start) throws LifecycleException {
synchronized (mapperUpdateSync) {
int port = grizzlyService.getRealPort(httpListener);
// Add the listener name of the new http-listener to its
// default-virtual-server, so that when the new http-listener
// and its MapperListener are started, they will recognize the
// default-virtual-server as one of their own, and add it to the
// Mapper
String virtualServerName = httpListener.findHttpProtocol().getHttp().getDefaultVirtualServer();
VirtualServer vs = (VirtualServer) getEngine().findChild(virtualServerName);
List<String> list = Arrays.asList(vs.getNetworkListenerNames());
// Avoid adding duplicate network-listener name
if (!list.contains(httpListener.getName())) {
String[] oldListenerNames = vs.getNetworkListenerNames();
String[] newListenerNames = new String[oldListenerNames.length + 1];
System.arraycopy(oldListenerNames, 0, newListenerNames, 0, oldListenerNames.length);
newListenerNames[oldListenerNames.length] = httpListener.getName();
vs.setNetworkListenerNames(newListenerNames);
}
Mapper mapper = null;
for (Mapper m : serviceLocator.<Mapper>getAllServices(Mapper.class)) {
if (m.getPort() == port && m instanceof ContextMapper) {
ContextMapper cm = (ContextMapper) m;
if (httpListener.getName().equals(cm.getId())) {
mapper = m;
break;
}
}
}
WebConnector connector = createHttpListener(httpListener, httpService, mapper);
if (connector.getRedirectPort() == -1) {
connector.setRedirectPort(defaultRedirectPort);
}
if (start) {
connector.start();
}
return connector;
}
}
use of org.glassfish.grizzly.http.server.util.Mapper in project Payara by payara.
the class WebContainer method updateDefaultWebModule.
/**
* Updates the given virtual server with the given default path.
*
* The given default path corresponds to the context path of one of the web contexts deployed on the virtual server that
* has been designated as the virtual server's new default-web-module.
*
* @param virtualServer The virtual server to update
*
* @param ports The port numbers of the HTTP listeners with which the given virtual server is associated
*
* @param defaultContextPath The context path of the web module that has been designated as the virtual server's new
* default web module, or null if the virtual server no longer has any default-web-module
*/
protected void updateDefaultWebModule(VirtualServer virtualServer, String[] listenerNames, WebModuleConfig webModuleConfig) throws LifecycleException {
String defaultContextPath = null;
if (webModuleConfig != null) {
defaultContextPath = webModuleConfig.getContextPath();
if (defaultContextPath != null && !defaultContextPath.startsWith("/")) {
defaultContextPath = "/" + defaultContextPath;
webModuleConfig.getDescriptor().setContextRoot(defaultContextPath);
}
}
Connector[] connectors = _embedded.findConnectors();
for (Connector connector : connectors) {
PECoyoteConnector coyoteConnector = (PECoyoteConnector) connector;
String name = coyoteConnector.getName();
for (String listenerName : listenerNames) {
if (name.equals(listenerName)) {
Mapper mapper = coyoteConnector.getMapper();
try {
mapper.setDefaultContextPath(virtualServer.getName(), defaultContextPath);
for (String alias : virtualServer.findAliases()) {
mapper.setDefaultContextPath(alias, defaultContextPath);
}
virtualServer.setDefaultContextPath(defaultContextPath);
} catch (Exception e) {
throw new LifecycleException(e);
}
}
}
}
}
Aggregations