@Override protected void doSessionIdle(HttpAcceptSession session, IdleStatus status) throws Exception { if (status == IdleStatus.WRITER_IDLE) { session.write(WsCommandMessage.NOOP); } super.doSessionIdle(session, status); }
@Override protected void doSessionIdle(HttpAcceptSession httpSession, IdleStatus status) throws Exception { // keep-alive if (status == WRITER_IDLE) { SseMessage sseMessage = new SseMessage(); sseMessage.setComment(""); httpSession.write(sseMessage); } }
private void reportError(HttpAcceptSession session, HttpStatus status) throws IOException { session.setStatus(status); if (errorPagesDir != null && errorPagesDir.exists()) { String errorFileName = Integer.toString(status.code()) + ".html"; File errorContentFile = new File(errorPagesDir, errorFileName); if (errorContentFile.exists() && errorContentFile.canRead()) { IoBufferAllocatorEx<?> allocator = session.getBufferAllocator(); IoBufferEx buf = HttpUtils.getBufferForFile(allocator, errorContentFile); session.setWriteHeader(HttpHeaders.HEADER_CONTENT_LENGTH, Integer.toString(buf.remaining())); session.write(buf); } } }
@Override public void writeFile(HttpAcceptSession httpSession) { String sOriginId = httpSession.getParameter("soid"); String authority = httpSession.getParameter("authority"); String call = "(function() { var element = document.getElementById(\"" + sOriginId + "\");" + "if (element) { " +" element.Packages.org.kaazing.gateway.client.html5.impl.BridgeUtil.bridgeJsCall(\"" + authority +"\");}})();"; IoBuffer buf = IoBuffer.wrap(call.getBytes()); httpSession.write(buf); } }
@Override public void writeFile(HttpAcceptSession httpSession) { if (maxAge != null) { httpSession.setWriteHeader(HEADER_MAX_AGE, valueOf(maxAge)); } httpSession.setWriteHeader(HEADER_CONTENT_LENGTH, valueOf(result.remaining())); WriteFuture f = httpSession.write(result.duplicate()); try { f.await(10, TimeUnit.SECONDS); } catch (InterruptedException e) { if (LOGGER.isWarnEnabled()) { LOGGER.warn(String.format("Write future in %s never fired", HttpClientAccessPolicyXml.class)); } } httpSession.close(true); } }
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(WsebAcceptor.BYTES_WRITTEN_ON_LAST_FLUSH_KEY); if (bytesWrittenOnLastFlush == null || writtenBytes != bytesWrittenOnLastFlush) { // Block Padding is required session.write(WsebFrameEncoder.BLOCK_PADDING_MESSAGE); session.setAttribute(WsebAcceptor.BYTES_WRITTEN_ON_LAST_FLUSH_KEY, writtenBytes + 4096); } }
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); } }
httpSession.setWriteHeader("Expires", RFC822_FORMAT_PATTERN.format(System.currentTimeMillis())); httpSession.suspendWrite(); httpSession.write(out); httpSession.shutdownWrite(); httpSession.resumeWrite();
private static void checkInitialPadding(HttpAcceptSession session) { // check to see if we need to add a padding message to the end of // the sent messages Integer clientPadding = (Integer)session.getAttribute(WsebAcceptor.CLIENT_PADDING_KEY); if (clientPadding != null) { long writtenBytes = session.getWrittenBytes(); int padding = (int)(clientPadding - writtenBytes); if (padding > 0) { // each command uses 2 bytes on the wire so we need half as many commands as padding bytes int len = padding / 2; Command[] commands = new Command[len]; for (int i = 0; i < len; i++) { commands[i] = Command.noop(); } WsMessage msg = new WsCommandMessage(commands); session.write(msg); } else { session.removeAttribute(WsebAcceptor.CLIENT_PADDING_KEY); } } }
WriteFuture future = httpSession.write(buf); future.addListener(new IoFutureListener<IoFuture>() { @Override
private static void checkInitialPadding(HttpAcceptSession session) { // check to see if we need to add a padding message to the end of // the sent messages Integer clientPadding = (Integer)session.getAttribute(SseAcceptor.CLIENT_PADDING_KEY); if (clientPadding != null) { long writtenBytes = session.getWrittenBytes(); int padding = (int)(clientPadding - writtenBytes); if (padding > 0) { // a message is required SseMessage sseMessage = new SseMessage(); int commentSize = padding - 3; // check if we need more then just an empty message if (commentSize > 0) { sseMessage.setComment(Utils.fill(' ', commentSize)); } session.write(sseMessage); } else { session.removeAttribute(SseAcceptor.CLIENT_PADDING_KEY); } } }
session.write(out); session.close(false);
session.write(out); session.close(false);
session.write(buf);
writer.write(WsCommandMessage.CLOSE);
SseMessage sseMessage = new SseMessage(); sseMessage.setReconnect(true); parent.write(sseMessage); parent.close(false);