Search in sources :

Example 1 with ContextRootInfo

use of org.glassfish.grizzly.config.ContextRootInfo in project Payara by payara.

the class ContainerMapper method map.

HttpHandler map(final Request req, final DataChunk decodedURI, MappingData mappingData) throws Exception {
    if (mappingData == null) {
        mappingData = req.getNote(MAPPING_DATA);
    }
    // Map the request to its Adapter/Container and also it's Servlet if
    // the request is targetted to the CoyoteAdapter.
    mapper.map(req.getRequest().serverName(), decodedURI, mappingData);
    updatePaths(req, mappingData);
    ContextRootInfo contextRootInfo;
    if (mappingData.context != null && (mappingData.context instanceof ContextRootInfo || mappingData.wrapper instanceof ContextRootInfo)) {
        if (mappingData.wrapper != null) {
            contextRootInfo = (ContextRootInfo) mappingData.wrapper;
        } else {
            contextRootInfo = (ContextRootInfo) mappingData.context;
        }
        return contextRootInfo.getHttpHandler();
    } else if (mappingData.context != null && "com.sun.enterprise.web.WebModule".equals(mappingData.context.getClass().getName())) {
        return mapper.getHttpHandler();
    }
    return null;
}
Also used : ContextRootInfo(org.glassfish.grizzly.config.ContextRootInfo)

Example 2 with ContextRootInfo

use of org.glassfish.grizzly.config.ContextRootInfo 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 = grizzlyService.getRealPort(listener);
    WebConnector connector;
    checkHostnameUniqueness(listener.getName(), httpService);
    if (mapper == null) {
        for (Mapper m : serviceLocator.getAllServices(Mapper.class)) {
            if (m.getPort() == port && m instanceof ContextMapper) {
                ContextMapper contextMapper = (ContextMapper) m;
                if (listener.getName().equals(contextMapper.getId())) {
                    mapper = m;
                    break;
                }
            }
        }
    }
    String defaultVirtualServer = listener.findHttpProtocol().getHttp().getDefaultVirtualServer();
    if (!defaultVirtualServer.equals(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[] defaultVirtualServerAsChars = defaultVirtualServer.toCharArray();
        host.setChars(defaultVirtualServerAsChars, 0, defaultVirtualServerAsChars.length);
        DataChunk dataChunk = DataChunk.newInstance();
        dataChunk.setChars(new char[] { '/' }, 0, 1);
        MappingData mappingData = new MappingData();
        try {
            mapper.map(host, dataChunk, mappingData);
        } catch (Exception e) {
            logger.log(FINE, "", e);
        }
        if (mappingData.context != null && mappingData.context instanceof ContextRootInfo) {
            ContextRootInfo rootInfo = (ContextRootInfo) mappingData.context;
            if (!(rootInfo.getHttpHandler() instanceof ContainerMapper)) {
                new BindException("Port " + port + " is already used by Container: " + rootInfo.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());
    logger.log(INFO, HTTP_LISTENER_CREATED, new Object[] { listener.getName(), listener.getAddress(), Integer.toString(port) });
    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 3 with ContextRootInfo

use of org.glassfish.grizzly.config.ContextRootInfo in project Payara by payara.

the class ContainerMapper method configureMapper.

/**
 * Configure the {@link ContextMapper}.
 */
protected void configureMapper() {
    mapperLock.writeLock().lock();
    try {
        mapper.setDefaultHostName(defaultHostName);
        mapper.addHost(defaultHostName, new String[] {}, null);
        mapper.addContext(defaultHostName, ROOT, new ContextRootInfo(this, null), new String[] { "index.html", "index.htm" }, null);
        // Container deployed have the right to override the default setting.
        Mapper.setAllowReplacement(true);
    } finally {
        mapperLock.writeLock().unlock();
    }
}
Also used : ContextRootInfo(org.glassfish.grizzly.config.ContextRootInfo)

Example 4 with ContextRootInfo

use of org.glassfish.grizzly.config.ContextRootInfo in project Payara by payara.

the class ContainerMapper method initializeFileURLPattern.

private void initializeFileURLPattern(String ext) {
    for (Sniffer sniffer : grizzlyService.getHabitat().<Sniffer>getAllServices(Sniffer.class)) {
        boolean match = false;
        if (sniffer.getURLPatterns() != null) {
            for (String pattern : sniffer.getURLPatterns()) {
                if (pattern.equalsIgnoreCase(ext)) {
                    match = true;
                    break;
                }
            }
            HttpHandler httpHandler;
            if (match) {
                httpHandler = grizzlyService.getHabitat().getService(SnifferAdapter.class);
                ((SnifferAdapter) httpHandler).initialize(sniffer, this);
                ContextRootInfo c = new ContextRootInfo(httpHandler, null);
                mapperLock.readLock().unlock();
                mapperLock.writeLock().lock();
                try {
                    for (String pattern : sniffer.getURLPatterns()) {
                        for (String host : grizzlyService.hosts) {
                            mapper.addWrapper(host, ROOT, pattern, c, "*.jsp".equals(pattern) || "*.jspx".equals(pattern));
                        }
                    }
                } finally {
                    mapperLock.readLock().lock();
                    mapperLock.writeLock().unlock();
                }
                return;
            }
        }
    }
}
Also used : Sniffer(org.glassfish.api.container.Sniffer) ContextRootInfo(org.glassfish.grizzly.config.ContextRootInfo)

Example 5 with ContextRootInfo

use of org.glassfish.grizzly.config.ContextRootInfo in project Payara by payara.

the class ContainerMapper method register.

public void register(final Endpoint endpoint) {
    if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.log(Level.FINE, "MAPPER({0}) REGISTER endpoint: {1}", new Object[] { this, endpoint });
    }
    mapMultipleAdapter = true;
    final String contextRoot = endpoint.getContextRoot();
    final Collection<String> vs = endpoint.getVirtualServers();
    ContextRootInfo c = new ContextRootInfo(new ContextRootInfo.Holder() {

        @Override
        public HttpHandler getHttpHandler() {
            return endpoint.getEndpointHandler();
        }

        @Override
        public Object getContainer() {
            return endpoint.getContainer();
        }
    });
    for (String host : vs) {
        mapper.addContext(host, contextRoot, c, new String[0], null);
    /*
            if (adapter instanceof StaticResourcesAdapter) {
            mapper.addWrapper(host, ctx, wrapper, c);
            }
             */
    }
}
Also used : ContextRootInfo(org.glassfish.grizzly.config.ContextRootInfo)

Aggregations

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