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;
}
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;
}
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);
}
}
}
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();
}
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();
}
Aggregations