@SuppressWarnings("deprecation") @Override public <T> Attribute<T> attr(AttributeKey<T> key) { return context.attr(key); }
ClientConnection(ChannelHandlerContext c) { _netId = netidGenerator.incrementAndGet(); _ctx = c; _ctx.attr(ClientConnection.NETID).set(_netId); }
public static ClientConnection getClientConnection(ChannelHandlerContext ctx) { Long netId = ctx.attr(ClientConnection.NETID).get(); ClientConnection conn = allClientMap.get(netId); if(conn != null) return conn; else { logger.error("ClientConenction not found in allClientMap, netId: {}", netId); } return null; }
/** * Returns true if this is an HTTPS request. * * @return true if https, false if http */ public boolean isHttps() { Attribute<Boolean> isHttpsAttr = ctx.attr(AttributeKey.<Boolean>valueOf(IS_HTTPS_ATTRIBUTE_NAME)); Boolean isHttps = isHttpsAttr.get(); if (isHttps == null) { return false; } else { return isHttps; } }
/** * Returns the host and port of this HTTPS request, including any modifications by other filters. * * @return host and port of this HTTPS request * @throws IllegalStateException if this is not an HTTPS request */ private String getHttpsRequestHostAndPort() throws IllegalStateException { if (!isHttps()) { throw new IllegalStateException("Request is not HTTPS. Cannot get host and port on non-HTTPS request using this method."); } Attribute<String> hostnameAttr = ctx.attr(AttributeKey.<String>valueOf(HOST_ATTRIBUTE_NAME)); return hostnameAttr.get(); }
/** * Returns the original host and port of this HTTPS request, as sent by the client. Does not reflect any modifications * by other filters. * TODO: evaluate this (unused) method and its capture mechanism in HttpsOriginalHostCaptureFilter; remove if not useful. * * @return host and port of this HTTPS request * @throws IllegalStateException if this is not an HTTPS request */ private String getHttpsOriginalRequestHostAndPort() throws IllegalStateException { if (!isHttps()) { throw new IllegalStateException("Request is not HTTPS. Cannot get original host and port on non-HTTPS request using this method."); } Attribute<String> hostnameAttr = ctx.attr(AttributeKey.<String>valueOf(ORIGINAL_HOST_ATTRIBUTE_NAME)); return hostnameAttr.get(); } }
public HttpsOriginalHostCaptureFilter(HttpRequest originalRequest, ChannelHandlerContext ctx) { super(originalRequest, ctx); // if this is an HTTP CONNECT, set the isHttps attribute on the ChannelHandlerConect and capture the hostname from the original request. // capturing the original host (and the remapped/modified host in clientToProxyRequest() below) guarantees that we will // have the "true" host, rather than relying on the Host header in subsequent requests (which may be absent or spoofed by malicious clients). if (ProxyUtils.isCONNECT(originalRequest)) { Attribute<String> originalHostAttr = ctx.attr(AttributeKey.<String>valueOf(HttpsAwareFiltersAdapter.ORIGINAL_HOST_ATTRIBUTE_NAME)); String hostAndPort = originalRequest.getUri(); originalHostAttr.set(hostAndPort); Attribute<Boolean> isHttpsAttr = ctx.attr(AttributeKey.<Boolean>valueOf(HttpsAwareFiltersAdapter.IS_HTTPS_ATTRIBUTE_NAME)); isHttpsAttr.set(true); } } }
@Override public HttpResponse clientToProxyRequest(HttpObject httpObject) { if (httpObject instanceof HttpRequest) { HttpRequest httpRequest = (HttpRequest) httpObject; if (ProxyUtils.isCONNECT(httpRequest)) { Attribute<String> hostname = ctx.attr(AttributeKey.<String>valueOf(HttpsAwareFiltersAdapter.HOST_ATTRIBUTE_NAME)); String hostAndPort = httpRequest.getUri(); // CONNECT requests contain the port, even when using the default port. a sensible default is to remove the // default port, since in most cases it is not explicitly specified and its presence (in a HAR file, for example) // would be unexpected. String hostNoDefaultPort = BrowserMobHttpUtil.removeMatchingPort(hostAndPort, 443); hostname.set(hostNoDefaultPort); } } return null; } }
channelCtx.attr(ATTR_ZUUL_RESP).set(zuulResponse);
channelCtx.attr(ATTR_ZUUL_RESP).set(zuulResponse);
@Override @ApiOperation(value = "Realtime mailbox notification service", notes = "Websocket service for sending and receiving mail noti fication", response = WSMessage.class, request = String.class, responseContainer = "List", authorizations = {@Authorization(value = "write_key"), @Authorization(value = "read_key")} ) public void onMessage(ChannelHandlerContext ctx, String data) { Integer jsonStart = data.indexOf("\n"); Operation op = Operation.valueOf(data.substring(0, jsonStart)); String jsonStr = data.substring(jsonStart); switch (op) { case msg: try { UserMessage message = JsonHelper.readSafe(jsonStr, UserMessage.class); storage.send(ctx.attr(PROJECT_ID).get(), ctx.attr(USER_ID).get(), message.toUser, message.parent, message.content, Instant.now()); } catch (IOException e) { ctx.close(); } break; case typing: break; } }
@Override public <T> Attribute<T> attr(AttributeKey<T> attributeKey) { return base.attr(attributeKey); } }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (maxKeepAliveTimeoutInNanoTime > 0 && ((System.nanoTime() - ctx.attr(CREATION_TIME).get()) > maxKeepAliveTimeoutInNanoTime)) { closeConnection(msg, promise); } else if (maxKeepAliveRequests > 0 && (ctx.attr(REQUEST_COUNT).get() != null && ctx.attr(REQUEST_COUNT).get().get() >= maxKeepAliveRequests)) { closeConnection(msg, promise); } ctx.write(msg, promise); } }
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { ctx.attr(CREATION_TIME).set(System.nanoTime()); super.channelActive(ctx); }
@Override protected final void encode(ChannelHandlerContext ctx, ModernPacket msg, List<Object> out) throws Exception { FMLProxyPacket proxy = PacketHandler.toFMLPacket(msg, ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get()); FMLProxyPacket old = ctx.attr(PacketHandler.INBOUNDPACKETTRACKER).get().get(); if (old != null) { proxy.setDispatcher(old.getDispatcher()); } out.add(proxy); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { Operation op = ctx.attr(NettyChannelContext.OPERATION_KEY).get(); if (op != null) { this.host.log(Level.SEVERE, "Listener channel exception: %s, in progress op: %s", cause.getMessage(), op.toString()); } ctx.channel().attr(NettyChannelContext.OPERATION_KEY).remove(); ctx.close(); }
private Session attachSession(ChannelHandlerContext ctx){ Session sess = new TcpSession(ctx); Attribute<String> attr = ctx.attr(sessionKey); attr.set(sess.id()); sessionMap.put(sess.id(), sess); return sess; }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { logCaughtException(cause); MessageReplier messageReplier = new NettyMessageReplier(ctx); requestProcessor.handleError(ctx.attr(REQUEST_OP_CODE).get(), messageReplier, cause); }