Java Code Examples for io.netty.channel.ChannelHandlerContext#attr()
The following examples show how to use
io.netty.channel.ChannelHandlerContext#attr() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompatibleObjectEncoder.java From netty4.0.27Learn with Apache License 2.0 | 6 votes |
@Override protected void encode(ChannelHandlerContext ctx, Serializable msg, ByteBuf out) throws Exception { Attribute<ObjectOutputStream> oosAttr = ctx.attr(OOS); ObjectOutputStream oos = oosAttr.get(); if (oos == null) { oos = newObjectOutputStream(new ByteBufOutputStream(out)); ObjectOutputStream newOos = oosAttr.setIfAbsent(oos); if (newOos != null) { oos = newOos; } } synchronized (oos) { if (resetInterval != 0) { // Resetting will prevent OOM on the receiving side. writtenObjects ++; if (writtenObjects % resetInterval == 0) { oos.reset(); } } oos.writeObject(msg); oos.flush(); } }
Example 2
Source File: HttpKeyEvaluationContext.java From karyon with Apache License 2.0 | 6 votes |
public static QueryStringDecoder getOrCreateQueryStringDecoder(HttpServerRequest<?> request, ChannelHandlerContext channelHandlerContext) { if (null == request) { throw new NullPointerException("Request can not be null."); } String uri = request.getUri(); if (null == uri) { return null; } Attribute<QueryStringDecoder> queryDecoderAttr = channelHandlerContext.attr(queryDecoderKey); QueryStringDecoder _queryStringDecoder = queryDecoderAttr.get(); if (null == _queryStringDecoder) { _queryStringDecoder = new QueryStringDecoder(uri); queryDecoderAttr.setIfAbsent(_queryStringDecoder); } return _queryStringDecoder; }
Example 3
Source File: VideoSessionRegistry.java From arcusplatform with Apache License 2.0 | 5 votes |
public void put(UUID recId, ChannelHandlerContext ctx) { if(ctx == null) { return; } Attribute<UUID> recIdAttr = ctx.attr(REC_KEY); if(!recIdAttr.compareAndSet(null, recId)) { throw new IllegalStateException("attempt to set existing non-null ctx recId [" + recIdAttr.get() + "] to [" + recId + "]"); } sessions.put(recIdAttr.get(), ctx); }
Example 4
Source File: VideoSessionRegistry.java From arcusplatform with Apache License 2.0 | 5 votes |
public ChannelHandlerContext remove(ChannelHandlerContext ctx) { if(ctx == null) { return null; } Attribute<UUID> recIdAttr = ctx.attr(REC_KEY); if(recIdAttr != null && recIdAttr.get() != null) { return remove(recIdAttr.get()); } return null; }
Example 5
Source File: HttpsOriginalHostCaptureFilter.java From CapturePacket with MIT License | 5 votes |
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); } }
Example 6
Source File: HttpsOriginalHostCaptureFilter.java From Dream-Catcher with MIT License | 5 votes |
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); } }
Example 7
Source File: HttpsOriginalHostCaptureFilter.java From AndroidHttpCapture with MIT License | 5 votes |
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); } }
Example 8
Source File: ContextBoundUnmarshallerProvider.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
@Override public Unmarshaller getUnmarshaller(ChannelHandlerContext ctx) throws Exception { Attribute<Unmarshaller> attr = ctx.attr(UNMARSHALLER); Unmarshaller unmarshaller = attr.get(); if (unmarshaller == null) { unmarshaller = super.getUnmarshaller(ctx); attr.set(unmarshaller); } return unmarshaller; }
Example 9
Source File: PeerChannelHandler.java From p2p with Apache License 2.0 | 4 votes |
static Attribute<Connection> getSessionAttribute(ChannelHandlerContext ctx) { return ctx.attr(AttributeKey.<Connection>valueOf(SESSION_ATTRIBUTE_KEY)); }