Search in sources :

Example 1 with Connection

use of org.glassfish.grizzly.Connection in project Payara by payara.

the class GenericGrizzlyListener method configureSsl.

protected static Filter configureSsl(final ServiceLocator habitat, final Ssl ssl, final FilterChainBuilder filterChainBuilder) {
    final SSLEngineConfigurator serverConfig = new SSLConfigurator(habitat, ssl);
    Filter sslFilter = null;
    if (Boolean.valueOf(ssl.getSniEnabled())) {
        SNIFilter sniFilter = new SNIFilter(serverConfig, null, isRenegotiateOnClientAuthWant(ssl));
        sniFilter.setHandshakeTimeout(Long.parseLong(ssl.getHandshakeTimeoutMillis()), TimeUnit.MILLISECONDS);
        sniFilter.setServerSSLConfigResolver(new SNIServerConfigResolver() {

            @Override
            public SNIConfig resolve(Connection cnctn, String hostname) {
                if (hostname == null) {
                    return SNIConfig.newServerConfig(serverConfig);
                } else {
                    SSLConfigurator newConfigurator = new SSLConfigurator(habitat, ssl);
                    newConfigurator.setSNICertAlias(hostname);
                    return SNIConfig.newServerConfig(newConfigurator);
                }
            }
        });
        sslFilter = sniFilter;
    } else {
        sslFilter = new SSLBaseFilter(serverConfig, // clientConfig,
        isRenegotiateOnClientAuthWant(ssl));
        ((SSLBaseFilter) sslFilter).setHandshakeTimeout(Long.parseLong(ssl.getHandshakeTimeoutMillis()), TimeUnit.MILLISECONDS);
    }
    filterChainBuilder.add(sslFilter);
    return sslFilter;
}
Also used : PUFilter(org.glassfish.grizzly.portunif.PUFilter) Filter(org.glassfish.grizzly.filterchain.Filter) SNIFilter(org.glassfish.grizzly.sni.SNIFilter) TransportFilter(org.glassfish.grizzly.filterchain.TransportFilter) IdleTimeoutFilter(org.glassfish.grizzly.utils.IdleTimeoutFilter) HttpServerFilter(org.glassfish.grizzly.http.server.HttpServerFilter) CompressionEncodingFilter(org.glassfish.grizzly.http.server.CompressionEncodingFilter) HttpRedirectFilter(org.glassfish.grizzly.config.portunif.HttpRedirectFilter) FileCacheFilter(org.glassfish.grizzly.http.server.FileCacheFilter) SSLBaseFilter(org.glassfish.grizzly.ssl.SSLBaseFilter) ProtocolFilter(org.glassfish.grizzly.config.dom.ProtocolFilter) SSLBaseFilter(org.glassfish.grizzly.ssl.SSLBaseFilter) SNIFilter(org.glassfish.grizzly.sni.SNIFilter) SNIConfig(org.glassfish.grizzly.sni.SNIConfig) SSLEngineConfigurator(org.glassfish.grizzly.ssl.SSLEngineConfigurator) SNIServerConfigResolver(org.glassfish.grizzly.sni.SNIServerConfigResolver) Connection(org.glassfish.grizzly.Connection)

Example 2 with Connection

use of org.glassfish.grizzly.Connection in project Payara by payara.

the class HttpProtocolFinder method find.

@Override
public Result find(final PUContext puContext, final FilterChainContext ctx) {
    final Connection connection = ctx.getConnection();
    final Buffer buffer = ctx.getMessage();
    final ParsingState parsingState = parsingStateAttribute.get(connection);
    final int limit = buffer.limit();
    int position;
    int state;
    if (parsingState == null) {
        position = buffer.position();
        state = 0;
    } else {
        position = parsingState.position;
        state = parsingState.state;
    }
    byte c = 0;
    byte c2;
    // Rule b - try to determine the context-root
    while (position < limit) {
        c2 = c;
        c = buffer.get(position++);
        // and the method
        _1: switch(state) {
            case 0:
                // Check method name
                for (int i = 0; i < METHOD_FIRST_LETTERS.length; i++) {
                    if (c == METHOD_FIRST_LETTERS[i]) {
                        state = 1;
                        break _1;
                    }
                }
                return Result.NOT_FOUND;
            case 1:
                // Search for first ' '
                if (c == 0x20) {
                    state = 2;
                }
                break;
            case 2:
                // Search for next ' '
                if (c == 0x20) {
                    state = 3;
                }
                break;
            case 3:
                // Check 'H' part of HTTP/
                if (c == 'H') {
                    state = 4;
                    break;
                }
                return Result.NOT_FOUND;
            case 4:
                // Search for P/ (part of HTTP/)
                if (c == 0x2f && c2 == 'P') {
                    // find SSL preprocessor
                    if (parsingState != null) {
                        parsingStateAttribute.remove(connection);
                    }
                    return Result.FOUND;
                }
                break;
            default:
                return Result.NOT_FOUND;
        }
    }
    if (position >= maxRequestLineSize) {
        return Result.NOT_FOUND;
    }
    if (parsingState == null) {
        parsingStateAttribute.set(connection, new ParsingState(position, state));
    } else {
        parsingState.position = position;
        parsingState.state = state;
    }
    return Result.NEED_MORE_DATA;
}
Also used : Buffer(org.glassfish.grizzly.Buffer) Connection(org.glassfish.grizzly.Connection)

Example 3 with Connection

use of org.glassfish.grizzly.Connection in project Payara by payara.

the class VirtualServer method addProbes.

/**
 * Sets all the monitoring probes used in the virtual server
 *
 * @param globalAccessLoggingEnabled
 * @see org.glassfish.grizzly.http.HttpProbe
 */
void addProbes(boolean globalAccessLoggingEnabled) {
    for (final NetworkListener listener : getGrizzlyNetworkListeners()) {
        try {
            final GrizzlyProxy proxy = (GrizzlyProxy) grizzlyService.lookupNetworkProxy(listener);
            if (proxy != null) {
                GenericGrizzlyListener grizzlyListener = (GenericGrizzlyListener) proxy.getUnderlyingListener();
                List<HttpCodecFilter> codecFilters = grizzlyListener.getFilters(HttpCodecFilter.class);
                if (codecFilters == null || codecFilters.isEmpty()) {
                    // if it's AJP listener - it's ok if we didn't find HttpCodecFilter
                    if (grizzlyListener.isAjpEnabled()) {
                        continue;
                    }
                    _logger.log(Level.SEVERE, LogFacade.CODE_FILTERS_NULL, new Object[] { listener.getName(), codecFilters });
                } else {
                    for (HttpCodecFilter codecFilter : codecFilters) {
                        if (codecFilter.getMonitoringConfig().getProbes().length == 0) {
                            HttpProbeImpl httpProbe = new HttpProbeImpl(listener, isAccessLoggingEnabled(globalAccessLoggingEnabled));
                            codecFilter.getMonitoringConfig().addProbes(httpProbe);
                        }
                    }
                }
                grizzlyListener.getTransport().getConnectionMonitoringConfig().addProbes(new ConnectionProbe.Adapter() {

                    RequestProbeProvider requestProbeProvider = webContainer.getRequestProbeProvider();

                    @Override
                    public void onReadEvent(Connection connection, Buffer data, int size) {
                        if (requestProbeProvider != null) {
                            requestProbeProvider.dataReceivedEvent(size, _id);
                        }
                    }

                    @Override
                    public void onWriteEvent(Connection connection, Buffer data, long size) {
                        if (requestProbeProvider != null) {
                            requestProbeProvider.dataSentEvent(size, _id);
                        }
                    }
                });
            } else {
                // check the listener is enabled before spitting out the SEVERE log
                if (Boolean.parseBoolean(listener.getEnabled())) {
                    _logger.log(Level.SEVERE, LogFacade.PROXY_NULL, new Object[] { listener.getName() });
                }
            }
        } catch (Exception ex) {
            _logger.log(Level.SEVERE, LogFacade.ADD_HTTP_PROBES_ERROR, ex);
        }
    }
}
Also used : Buffer(org.glassfish.grizzly.Buffer) GrizzlyProxy(com.sun.enterprise.v3.services.impl.GrizzlyProxy) GenericGrizzlyListener(org.glassfish.grizzly.config.GenericGrizzlyListener) Connection(org.glassfish.grizzly.Connection) HttpCodecFilter(org.glassfish.grizzly.http.HttpCodecFilter) LifecycleException(org.apache.catalina.LifecycleException) ConfigException(org.glassfish.embeddable.web.ConfigException) IOException(java.io.IOException) GlassFishException(org.glassfish.embeddable.GlassFishException) ConnectionProbe(org.glassfish.grizzly.ConnectionProbe) RequestProbeProvider(org.glassfish.web.admin.monitor.RequestProbeProvider) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 4 with Connection

use of org.glassfish.grizzly.Connection in project Payara by payara.

the class XProtocolFilter method handleRead.

@Override
public NextAction handleRead(final FilterChainContext ctx) throws IOException {
    final Connection connection = ctx.getConnection();
    final MemoryManager memoryManager = connection.getTransport().getMemoryManager();
    ctx.write(Buffers.wrap(memoryManager, "X-Protocol-Response", CHARSET));
    ctx.flush(new EmptyCompletionHandler() {

        @Override
        public void completed(Object result) {
            connection.closeSilently();
        }
    });
    return ctx.getStopAction();
}
Also used : Connection(org.glassfish.grizzly.Connection) EmptyCompletionHandler(org.glassfish.grizzly.EmptyCompletionHandler) MemoryManager(org.glassfish.grizzly.memory.MemoryManager)

Example 5 with Connection

use of org.glassfish.grizzly.Connection in project Payara by payara.

the class WSTCPProtocolFilter method handleClose.

@Override
public NextAction handleClose(final FilterChainContext ctx) throws IOException {
    final Connection connection = ctx.getConnection();
    final SelectionKey selectionKey = ((NIOConnection) connection).getSelectionKey();
    try {
        if (connector != null) {
            connector.notifyConnectionClosed((SocketChannel) selectionKey.channel());
        } else {
            synchronized (sync) {
                if (connector != null) {
                    connector.notifyConnectionClosed((SocketChannel) selectionKey.channel());
                }
            }
        }
    } catch (Exception e) {
    }
    return ctx.getInvokeAction();
}
Also used : SelectionKey(java.nio.channels.SelectionKey) Connection(org.glassfish.grizzly.Connection) NIOConnection(org.glassfish.grizzly.nio.NIOConnection) IOException(java.io.IOException) NIOConnection(org.glassfish.grizzly.nio.NIOConnection)

Aggregations

Connection (org.glassfish.grizzly.Connection)6 IOException (java.io.IOException)2 Buffer (org.glassfish.grizzly.Buffer)2 GrizzlyProxy (com.sun.enterprise.v3.services.impl.GrizzlyProxy)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 SelectionKey (java.nio.channels.SelectionKey)1 SSLEngine (javax.net.ssl.SSLEngine)1 LifecycleException (org.apache.catalina.LifecycleException)1 GlassFishException (org.glassfish.embeddable.GlassFishException)1 ConfigException (org.glassfish.embeddable.web.ConfigException)1 ConnectionProbe (org.glassfish.grizzly.ConnectionProbe)1 EmptyCompletionHandler (org.glassfish.grizzly.EmptyCompletionHandler)1 GenericGrizzlyListener (org.glassfish.grizzly.config.GenericGrizzlyListener)1 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)1 ProtocolFilter (org.glassfish.grizzly.config.dom.ProtocolFilter)1 HttpRedirectFilter (org.glassfish.grizzly.config.portunif.HttpRedirectFilter)1 Filter (org.glassfish.grizzly.filterchain.Filter)1 TransportFilter (org.glassfish.grizzly.filterchain.TransportFilter)1 HttpCodecFilter (org.glassfish.grizzly.http.HttpCodecFilter)1