List of usage examples for io.netty.channel ChannelHandlerContext fireChannelRead
@Override ChannelHandlerContext fireChannelRead(Object msg);
From source file:org.wso2.carbon.apimgt.gateway.handlers.WebsocketInboundHandler.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from w w w . j a va2 s . c om public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { //check if the request is a handshake if (msg instanceof FullHttpRequest) { FullHttpRequest req = (FullHttpRequest) msg; uri = req.getUri(); URI uriTemp = new URI(uri); apiContextUri = new URI(uriTemp.getScheme(), uriTemp.getAuthority(), uriTemp.getPath(), null, uriTemp.getFragment()).toString(); if (req.getUri().contains("/t/")) { tenantDomain = MultitenantUtils.getTenantDomainFromUrl(req.getUri()); } else { tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; } String useragent = req.headers().get(HttpHeaders.USER_AGENT); String authorization = req.headers().get(HttpHeaders.AUTHORIZATION); // '-' is used for empty values to avoid possible errors in DAS side. // Required headers are stored one by one as validateOAuthHeader() // removes some of the headers from the request useragent = useragent != null ? useragent : "-"; headers.add(HttpHeaders.AUTHORIZATION, authorization); headers.add(HttpHeaders.USER_AGENT, useragent); if (validateOAuthHeader(req)) { if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) { // carbon-mediation only support websocket invocation from super tenant APIs. // This is a workaround to mimic the the invocation came from super tenant. req.setUri(req.getUri().replaceFirst("/", "-")); String modifiedUri = uri.replaceFirst("/t/", "-t/"); req.setUri(modifiedUri); msg = req; } else { req.setUri(uri); // Setting endpoint appended uri } if (StringUtils.isNotEmpty(token)) { ((FullHttpRequest) msg).headers().set(APIMgtGatewayConstants.WS_JWT_TOKEN_HEADER, token); } ctx.fireChannelRead(msg); // publish google analytics data GoogleAnalyticsData.DataBuilder gaData = new GoogleAnalyticsData.DataBuilder(null, null, null, null) .setDocumentPath(uri).setDocumentHostName(DataPublisherUtil.getHostAddress()) .setSessionControl("end").setCacheBuster(APIMgtGoogleAnalyticsUtils.getCacheBusterId()) .setIPOverride(ctx.channel().remoteAddress().toString()); APIMgtGoogleAnalyticsUtils gaUtils = new APIMgtGoogleAnalyticsUtils(); gaUtils.init(tenantDomain); gaUtils.publishGATrackingData(gaData, req.headers().get(HttpHeaders.USER_AGENT), authorization); } else { ctx.writeAndFlush( new TextWebSocketFrame(APISecurityConstants.API_AUTH_INVALID_CREDENTIALS_MESSAGE)); throw new APISecurityException(APISecurityConstants.API_AUTH_INVALID_CREDENTIALS, APISecurityConstants.API_AUTH_INVALID_CREDENTIALS_MESSAGE); } } else if (msg instanceof WebSocketFrame) { boolean isThrottledOut = doThrottle(ctx, (WebSocketFrame) msg); String clientIp = getRemoteIP(ctx); if (isThrottledOut) { ctx.fireChannelRead(msg); } else { ctx.writeAndFlush(new TextWebSocketFrame("Websocket frame throttled out")); } // publish analytics events if analytics is enabled if (APIUtil.isAnalyticsEnabled()) { publishRequestEvent(infoDTO, clientIp, isThrottledOut); } } }
From source file:org.wso2.carbon.http2.transport.util.Http2FrameListenAdapter.java
License:Open Source License
@Override public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream) throws Http2Exception { if (log.isDebugEnabled()) { log.debug("Http2FrameListenAdapter.onDataRead()"); }//from ww w . ja va2 s.c o m DefaultHttp2DataFrame frame = new DefaultHttp2DataFrame(data, endOfStream, padding); frame.setStreamId(streamId); ctx.fireChannelRead(frame); return super.onDataRead(ctx, streamId, data, padding, endOfStream); }
From source file:org.wso2.carbon.http2.transport.util.Http2FrameListenAdapter.java
License:Open Source License
@Override public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception { if (log.isDebugEnabled()) log.debug("Http2FrameListenAdapter.onHeadersRead()"); DefaultHttp2HeadersFrame frame = new DefaultHttp2HeadersFrame(headers, endStream, padding); frame.setStreamId(streamId);//from ww w. jav a2 s .c o m ctx.fireChannelRead(frame); super.onHeadersRead(ctx, streamId, headers, streamDependency, weight, exclusive, padding, endStream); }
From source file:org.wso2.carbon.http2.transport.util.Http2FrameListenAdapter.java
License:Open Source License
@Override public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endStream) throws Http2Exception { if (log.isDebugEnabled()) log.debug("Http2FrameListenAdapter.onHeadersRead()"); DefaultHttp2HeadersFrame frame = new DefaultHttp2HeadersFrame(headers, endStream, padding); frame.setStreamId(streamId);//from w w w .j a v a 2s .c om ctx.fireChannelRead(frame); super.onHeadersRead(ctx, streamId, headers, padding, endStream); }
From source file:org.wso2.carbon.http2.transport.util.Http2FrameListenAdapter.java
License:Open Source License
@Override public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) throws Http2Exception { if (log.isDebugEnabled()) log.debug("Http2FrameListenAdapter.onSettingRead()"); ctx.fireChannelRead(settings); super.onSettingsRead(ctx, settings); }
From source file:org.wso2.carbon.http2.transport.util.Http2FrameListenAdapter.java
License:Open Source License
@Override public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception { if (log.isDebugEnabled()) log.debug("Http2FrameListenAdapter.onPushPromiseRead()"); Http2PushPromiseFrame frame = new Http2PushPromiseFrame(); frame.setStreamId(streamId);//from w ww .ja v a 2 s . co m frame.setPushPromiseId(promisedStreamId); frame.setHeaders(headers); ctx.fireChannelRead(frame); super.onPushPromiseRead(ctx, streamId, promisedStreamId, headers, padding); }
From source file:org.wso2.carbon.inbound.endpoint.protocol.http2.Http2FrameListenAdapter.java
License:Open Source License
@Override public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) throws Http2Exception { if (log.isDebugEnabled()) log.debug("Http2FrameListenAdapter.onSettingRead()"); ctx.fireChannelRead(settings); }
From source file:org.wso2.carbon.inbound.endpoint.protocol.http2.Http2FrameListenAdapter.java
License:Open Source License
@Override public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) throws Http2Exception { ctx.fireChannelRead(new DefaultHttp2ResetFrame(errorCode).setStreamId(streamId)); }
From source file:org.wso2.carbon.inbound.endpoint.protocol.http2.Http2FrameListenAdapter.java
License:Open Source License
@Override public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData) throws Http2Exception { ctx.fireChannelRead( new DefaultHttp2GoAwayFrame(errorCode).replace(debugData).setExtraStreamIds(lastStreamId)); }
From source file:org.wso2.carbon.mss.internal.router.RequestRouter.java
License:Open Source License
@Override protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception { Channel channel = ctx.channel(); if (msg instanceof HttpRequest) { HttpRequest request = (HttpRequest) msg; if (handleRequest(request, channel, ctx)) { if (httpMethodInfoBuilder.getHttpResourceModel().isStreamingReqSupported() && channel.pipeline().get("aggregator") != null) { channel.pipeline().remove("aggregator"); } else if (!httpMethodInfoBuilder.getHttpResourceModel().isStreamingReqSupported() && channel.pipeline().get("aggregator") == null) { channel.pipeline().addAfter("router", "aggregator", new HttpObjectAggregator(Integer.MAX_VALUE)); }// w ww .j a v a2s. c o m } ReferenceCountUtil.retain(msg); ctx.fireChannelRead(msg); } else if (msg instanceof HttpContent) { ReferenceCountUtil.retain(msg); ctx.fireChannelRead(msg); } }