Search in sources :

Example 1 with ContextMapper

use of org.glassfish.internal.grizzly.ContextMapper in project Payara by payara.

the class WebContainer method createHttpListener.

protected WebConnector createHttpListener(NetworkListener listener, HttpService httpService, Mapper mapper) {
    if (!Boolean.valueOf(listener.getEnabled())) {
        return null;
    }
    int port = 8080;
    WebConnector connector;
    checkHostnameUniqueness(listener.getName(), httpService);
    try {
        port = Integer.parseInt(listener.getPort());
    } catch (NumberFormatException nfe) {
        String msg = rb.getString(LogFacade.HTTP_LISTENER_INVALID_PORT);
        msg = MessageFormat.format(msg, listener.getPort(), listener.getName());
        throw new IllegalArgumentException(msg);
    }
    if (mapper == null) {
        for (Mapper m : habitat.<Mapper>getAllServices(Mapper.class)) {
            if (m.getPort() == port && m instanceof ContextMapper) {
                ContextMapper cm = (ContextMapper) m;
                if (listener.getName().equals(cm.getId())) {
                    mapper = m;
                    break;
                }
            }
        }
    }
    String defaultVS = listener.findHttpProtocol().getHttp().getDefaultVirtualServer();
    if (!defaultVS.equals(org.glassfish.api.web.Constants.ADMIN_VS)) {
        // Before we start a WebConnector, let's makes sure there is
        // not another Container already listening on that port
        DataChunk host = DataChunk.newInstance();
        char[] c = defaultVS.toCharArray();
        host.setChars(c, 0, c.length);
        DataChunk mb = DataChunk.newInstance();
        mb.setChars(new char[] { '/' }, 0, 1);
        MappingData md = new MappingData();
        try {
            mapper.map(host, mb, md);
        } catch (Exception e) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "", e);
            }
        }
        if (md.context != null && md.context instanceof ContextRootInfo) {
            ContextRootInfo r = (ContextRootInfo) md.context;
            if (!(r.getHttpHandler() instanceof ContainerMapper)) {
                new BindException("Port " + port + " is already used by Container: " + r.getHttpHandler() + " and will not get started.").printStackTrace();
                return null;
            }
        }
    }
    /*
         * Create Connector. Connector is SSL-enabled if
         * 'security-enabled' attribute in <http-listener>
         * element is set to TRUE.
         */
    boolean isSecure = Boolean.valueOf(listener.findHttpProtocol().getSecurityEnabled());
    if (isSecure && defaultRedirectPort == -1) {
        defaultRedirectPort = port;
    }
    String address = listener.getAddress();
    if ("any".equals(address) || "ANY".equals(address) || "INADDR_ANY".equals(address)) {
        address = null;
    /*
             * Setting 'address' to NULL will cause Tomcat to pass a
             * NULL InetAddress argument to the java.net.ServerSocket
             * constructor, meaning that the server socket will accept
             * connections on any/all local addresses.
             */
    }
    connector = (WebConnector) _embedded.createConnector(address, port, isSecure);
    connector.setMapper(mapper);
    connector.setJvmRoute(engine.getJvmRoute());
    if (logger.isLoggable(Level.INFO)) {
        logger.log(Level.INFO, LogFacade.HTTP_LISTENER_CREATED, new Object[] { listener.getName(), listener.getAddress(), listener.getPort() });
    }
    connector.setDefaultHost(listener.findHttpProtocol().getHttp().getDefaultVirtualServer());
    connector.setName(listener.getName());
    connector.setInstanceName(instanceName);
    connector.configure(listener, isSecure, httpService);
    _embedded.addConnector(connector);
    connectorMap.put(listener.getName(), connector);
    // If we already know the redirect port, then set it now
    // This situation will occurs when dynamic reconfiguration occurs
    String redirectPort = listener.findHttpProtocol().getHttp().getRedirectPort();
    if (redirectPort != null) {
        connector.setRedirectPort(Integer.parseInt(redirectPort));
    } else if (defaultRedirectPort != -1) {
        connector.setRedirectPort(defaultRedirectPort);
    }
    ObservableBean httpListenerBean = (ObservableBean) ConfigSupport.getImpl(listener);
    httpListenerBean.addListener(configListener);
    return connector;
}
Also used : BindException(java.net.BindException) LifecycleException(org.apache.catalina.LifecycleException) NamingException(javax.naming.NamingException) BindException(java.net.BindException) MalformedURLException(java.net.MalformedURLException) ContextRootInfo(org.glassfish.grizzly.config.ContextRootInfo) Mapper(org.glassfish.grizzly.http.server.util.Mapper) ContextMapper(org.glassfish.internal.grizzly.ContextMapper) ContainerMapper(com.sun.enterprise.v3.services.impl.ContainerMapper) MappingData(org.glassfish.grizzly.http.server.util.MappingData) DataChunk(org.glassfish.grizzly.http.util.DataChunk) ObservableBean(org.jvnet.hk2.config.ObservableBean) ContextMapper(org.glassfish.internal.grizzly.ContextMapper) ContainerMapper(com.sun.enterprise.v3.services.impl.ContainerMapper)

Example 2 with ContextMapper

use of org.glassfish.internal.grizzly.ContextMapper in project Payara by payara.

the class WebContainer method createJKConnector.

/**
 * Starts the AJP connector that will listen to call from Apache using
 * mod_jk, mod_jk2 or mod_ajp.
 * @param listener
 * @param httpService
 * @return
 */
protected WebConnector createJKConnector(NetworkListener listener, HttpService httpService) {
    int port = 8009;
    boolean isSecure = false;
    String address = null;
    if (listener == null) {
        String portString = System.getProperty("com.sun.enterprise.web.connector.enableJK");
        if (portString == null) {
            // do not create JK Connector if property is not set
            return null;
        } else {
            try {
                port = Integer.parseInt(portString);
            } catch (NumberFormatException ex) {
                // use default port 8009
                port = 8009;
            }
        }
    } else {
        port = Integer.parseInt(listener.getPort());
        isSecure = Boolean.valueOf(listener.findHttpProtocol().getSecurityEnabled());
        address = listener.getAddress();
    }
    if (isSecure && defaultRedirectPort == -1) {
        defaultRedirectPort = port;
    }
    if ("any".equals(address) || "ANY".equals(address) || "INADDR_ANY".equals(address)) {
        address = null;
    /*
             * Setting 'address' to NULL will cause Tomcat to pass a
             * NULL InetAddress argument to the java.net.ServerSocket
             * constructor, meaning that the server socket will accept
             * connections on any/all local addresses.
             */
    }
    jkConnector = (WebConnector) _embedded.createConnector(address, port, "ajp");
    jkConnector.configureJKProperties(listener);
    String defaultHost = "server";
    String jkConnectorName = "jk-connector";
    if (listener != null) {
        defaultHost = listener.findHttpProtocol().getHttp().getDefaultVirtualServer();
        jkConnectorName = listener.getName();
    }
    jkConnector.setDefaultHost(defaultHost);
    jkConnector.setName(jkConnectorName);
    jkConnector.setDomain(_serverContext.getDefaultDomainName());
    jkConnector.setInstanceName(instanceName);
    if (listener != null) {
        jkConnector.configure(listener, isSecure, httpService);
        connectorMap.put(listener.getName(), jkConnector);
    }
    if (logger.isLoggable(Level.INFO)) {
        logger.log(Level.INFO, LogFacade.JK_LISTENER_CREATED, new Object[] { listener.getName(), listener.getAddress(), listener.getPort() });
    }
    for (Mapper m : habitat.<Mapper>getAllServices(Mapper.class)) {
        if (m.getPort() == port && m instanceof ContextMapper) {
            ContextMapper cm = (ContextMapper) m;
            if (listener.getName().equals(cm.getId())) {
                jkConnector.setMapper(m);
                break;
            }
        }
    }
    _embedded.addConnector(jkConnector);
    return jkConnector;
}
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 3 with ContextMapper

use of org.glassfish.internal.grizzly.ContextMapper 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 = Integer.parseInt(httpListener.getPort());
        // 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 : habitat.<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)

Aggregations

ContainerMapper (com.sun.enterprise.v3.services.impl.ContainerMapper)3 Mapper (org.glassfish.grizzly.http.server.util.Mapper)3 ContextMapper (org.glassfish.internal.grizzly.ContextMapper)3 BindException (java.net.BindException)1 MalformedURLException (java.net.MalformedURLException)1 NamingException (javax.naming.NamingException)1 LifecycleException (org.apache.catalina.LifecycleException)1 ContextRootInfo (org.glassfish.grizzly.config.ContextRootInfo)1 MappingData (org.glassfish.grizzly.http.server.util.MappingData)1 DataChunk (org.glassfish.grizzly.http.util.DataChunk)1 ObservableBean (org.jvnet.hk2.config.ObservableBean)1