public synchronized void init() { if ( !initialized ) { // Instantiate all supported protocols register(WebSocketWireProtocol.HIXIE_75, new WsProtocolHixie75HandshakeValidator()); register(WebSocketWireProtocol.HIXIE_76, new WsProtocolHixie76HandshakeValidator()); register(WebSocketWireProtocol.HYBI_8, new WsProtocol8HandshakeValidator()); register(WebSocketWireProtocol.HYBI_13, new WsProtocol13HandshakeValidator()); register(WebSocketWireProtocol.RFC_6455, new WsProtocol13HandshakeValidator()); initialized = true; } } }
@Override public void removeBridgeFilters(IoFilterChain filterChain) { for (HttpAcceptFilter filter : allAcceptFilters) { removeFilter(filterChain, filter.filterName()); } }
PersistentConnectionPool(Logger logger) { this.connections = new VicariousThreadLocal<ServerConnections>() { @Override protected ServerConnections initialValue() { return new ServerConnections(); } }; this.logger = logger; this.idleFilter = new HttpConnectIdleFilter(logger); this.closeListener = new CloseListener(this); }
private static void checkBlockPadding(HttpAcceptSession session) { // TODO: Verify if counting bytes is really necessary // check to see if we need to add a padding message to the end of sent messages long writtenBytes = session.getWrittenBytes(); Long bytesWrittenOnLastFlush = ((Long)session.getAttribute(SseAcceptor.BYTES_WRITTEN_ON_LAST_FLUSH_KEY)); if (bytesWrittenOnLastFlush == null || writtenBytes != bytesWrittenOnLastFlush) { // Block Padding is required session.write(SseEncoder.BLOCK_PADDING_MESSAGE); session.setAttribute(SseAcceptor.BYTES_WRITTEN_ON_LAST_FLUSH_KEY, writtenBytes + 4096); } }
@Override protected void doExceptionCaught(HttpAcceptSession session, Throwable cause) throws Exception { // trigger sessionClosed to update connection capabilities accordingly session.close(true); }
@Override public void initializeSession(IoSession session, ConnectFuture future) { HttpConnectSession connectSession = (HttpConnectSession) session; connectSession.setVersion(acceptSession.getVersion()); connectSession.setMethod(acceptSession.getMethod()); URI connectURI = computeConnectPath(connectSession.getRequestURI()); connectSession.setRequestURI(connectURI); processRequestHeaders(acceptSession, connectSession); }
public static boolean hasBeenModified(HttpSession session, String etag, File requestFile) { String ifNoneMatch = session.getReadHeader("If-None-Match"); String ifModifiedSince = session.getReadHeader("If-Modified-Since"); return hasBeenModified(requestFile, etag, ifNoneMatch, ifModifiedSince); }
@Override public <T extends Message> IoBufferEx encode(MessageEncoder<T> encoder, T message, IoBufferAllocatorEx<?> allocator, int flags) { String cacheKey = isGzipped() ? GZIPPED_CACHE_KEY : DEFAULT_CACHE_KEY; if (isChunked()) { cacheKey = cacheKey + "/chunked"; } return encode(cacheKey, encoder, message, allocator, flags); }
@Override protected HttpBinding bindAdditionalAddressesIfNecessary(HttpBinding newHttpBinding) { HttpBinding httpBinding = addBinding0(newHttpBinding); // detect first bind (without race) if (httpBinding == null) { // bind the resources handler by default (no security) ResourceAddress resourcesAddress = getResourcesAddress(newHttpBinding); HttpAcceptor.this.bind(resourcesAddress, httpResourcesHandler, null); } return httpBinding; }
private <T extends ConnectFuture> void connectInternal0(ConnectFuture connectFuture, final ResourceAddress address, HttpConnectSessionFactory httpSessionFactory) { IoSession transportSession = persistentConnectionsStore.take((HttpResourceAddress) address); if (transportSession != null) { connectUsingExistingTransport(connectFuture, transportSession, httpSessionFactory); } else { connectUsingNewTransport(connectFuture, address, httpSessionFactory); } }
@Override protected void doSessionClosed(HttpAcceptSession session) throws Exception { // clean up the attribute. session.removeAttribute(WSN_HTTP_BRIDGE_HANDLER); }
@Override protected void finishSessionInitialization0(IoSession session, IoFuture future) { DefaultHttpSession httpSession = (DefaultHttpSession) session; HttpConnectProcessor processor = (HttpConnectProcessor) httpSession.getProcessor(); processor.finishConnect(httpSession); }
@Override protected boolean doValidate(HttpRequestMessage request, final boolean isPostMethodAllowed) { return super.doValidate(request, isPostMethodAllowed) && requireHeader(request, SEC_WEB_SOCKET_KEY1) && requireHeader(request, SEC_WEB_SOCKET_KEY2); // all other handshake elements are optional and not verifiable. }
HttpTransport() { acceptor = new HttpAcceptor(); connector = new HttpConnector(); }
@Override public void run() { newReader.setIoAlignment(ioThread, ioExecutor); attachReader0(newReader); // now allow messageReceived to fire if data is available newReader.resumeRead(); } });
@Override public void removeBridgeFilters(IoFilterChain filterChain) { for (HttpConnectFilter filter : allConnectFilters) { switch (filter) { case CODEC: // Note: we MUST NOT remove the codec filter until // after the first IoBuffer is received post-upgrade break; default: removeFilter(filterChain, filter.filterName()); break; } } }
@Override protected ServerConnections initialValue() { return new ServerConnections(); } };
@Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof HttpBinding)) { return false; } HttpBinding that = (HttpBinding)o; return equals(that); }
@Override public void operationComplete(CloseFuture future) { // Note: this reference to HTTP session is pinned by listener // and must be removed to avoid a memory leak (see below) session.close(false); } };
@Override protected void doExceptionCaught(HttpAcceptSession session, Throwable cause) throws Exception { // trigger sessionClosed to update connection capabilities accordingly session.close(true); }