Search in sources :

Example 6 with Mapper

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;
    }
}
Also used : Mapper(org.glassfish.grizzly.http.server.util.Mapper) ContextMapper(org.glassfish.internal.grizzly.ContextMapper) ContainerMapper(com.sun.enterprise.v3.services.impl.ContainerMapper) ContextMapper(org.glassfish.internal.grizzly.ContextMapper)

Example 7 with Mapper

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);
                }
            }
        }
    }
}
Also used : PECoyoteConnector(com.sun.enterprise.web.connector.coyote.PECoyoteConnector) Connector(org.apache.catalina.Connector) Mapper(org.glassfish.grizzly.http.server.util.Mapper) ContextMapper(org.glassfish.internal.grizzly.ContextMapper) ContainerMapper(com.sun.enterprise.v3.services.impl.ContainerMapper) LifecycleException(org.apache.catalina.LifecycleException) PECoyoteConnector(com.sun.enterprise.web.connector.coyote.PECoyoteConnector) LifecycleException(org.apache.catalina.LifecycleException) NamingException(javax.naming.NamingException) BindException(java.net.BindException) MalformedURLException(java.net.MalformedURLException)

Aggregations

Mapper (org.glassfish.grizzly.http.server.util.Mapper)7 ContainerMapper (com.sun.enterprise.v3.services.impl.ContainerMapper)5 ContextMapper (org.glassfish.internal.grizzly.ContextMapper)5 LifecycleException (org.apache.catalina.LifecycleException)4 BindException (java.net.BindException)3 MalformedURLException (java.net.MalformedURLException)3 NamingException (javax.naming.NamingException)3 MappingData (org.glassfish.grizzly.http.server.util.MappingData)2 PECoyoteConnector (com.sun.enterprise.web.connector.coyote.PECoyoteConnector)1 IOException (java.io.IOException)1 Constructor (java.lang.reflect.Constructor)1 PrivilegedActionException (java.security.PrivilegedActionException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 HttpServletMapping (javax.servlet.http.HttpServletMapping)1 Connector (org.apache.catalina.Connector)1 ClientAbortException (org.apache.catalina.connector.ClientAbortException)1 MappingImpl (org.apache.catalina.connector.MappingImpl)1 StandardEngine (org.apache.catalina.core.StandardEngine)1 ContextRootInfo (org.glassfish.grizzly.config.ContextRootInfo)1 CharChunk (org.glassfish.grizzly.http.util.CharChunk)1