io.netty.channel.ChannelInboundHandler Java Examples

The following examples show how to use io.netty.channel.ChannelInboundHandler. 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: ProtocolNegotiators.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
/**
 * When this channel is registered, we will add all the ChannelHandlers passed into our
 * constructor to the pipeline.
 */
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
  /**
   * This check is necessary as a channel may be registered with different event loops during it
   * lifetime and we only want to configure it once.
   */
  if (handlers != null) {
    for (ChannelHandler handler : handlers) {
      ctx.pipeline().addBefore(ctx.name(), null, handler);
    }
    ChannelHandler handler0 = handlers[0];
    ChannelHandlerContext handler0Ctx = ctx.pipeline().context(handlers[0]);
    handlers = null;
    if (handler0Ctx != null) { // The handler may have removed itself immediately
      if (handler0 instanceof ChannelInboundHandler) {
        ((ChannelInboundHandler) handler0).channelRegistered(handler0Ctx);
      } else {
        handler0Ctx.fireChannelRegistered();
      }
    }
  } else {
    super.channelRegistered(ctx);
  }
}
 
Example #2
Source File: VideoPreviewServerModule.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {
   bind(BridgeServerConfig.class);
   bind(PreviewConfig.class);
   bind(BridgeServerTlsContext.class).to(BridgeServerTlsContextImpl.class);
   bind(BridgeServerTrustManagerFactory.class).to(NullTrustManagerFactoryImpl.class);
   bind(ChannelInboundHandler.class).toProvider(BaseWebSocketServerHandlerProvider.class);
   bind(new TypeLiteral<ChannelInitializer<SocketChannel>>(){}).to(HttpRequestInitializer.class);
   bind(Authenticator.class).to(ShiroAuthenticator.class);
   bind(SessionFactory.class).to(DefaultSessionFactoryImpl.class);
   bind(SessionRegistry.class).to(DefaultSessionRegistryImpl.class);
   bind(RequestMatcher.class).annotatedWith(Names.named("WebSocketUpgradeMatcher")).to(NeverMatcher.class);
   bind(RequestAuthorizer.class).annotatedWith(Names.named("SessionAuthorizer")).to(SessionAuth.class);
   bind(IrisNettyAuthorizationContextLoader.class).to(SubscriberAuthorizationContextLoader.class);

   // No Session Listeners
   Multibinder<SessionListener> slBindings = Multibinder.newSetBinder(binder(), SessionListener.class);

   // Bind Http Handlers
   Multibinder<RequestHandler> rhBindings = Multibinder.newSetBinder(binder(), RequestHandler.class);
   rhBindings.addBinding().to(RootRedirect.class);
   rhBindings.addBinding().to(IndexPage.class);
   rhBindings.addBinding().to(CheckPage.class);
   rhBindings.addBinding().to(PreviewHandler.class);
}
 
Example #3
Source File: HttpRequestInitializer.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Inject
public HttpRequestInitializer(
   BridgeServerTlsContext tlsContext,
   BridgeServerConfig serverConfig,
   Provider<ChannelInboundHandler> handlerProvider,
   BindClientContextHandler bindClient,
   IrisNettyCorsConfig corsConfig
) {
   this.serverTlsContext = tlsContext;
   this.serverConfig = serverConfig;

   this.inboundIpTracking = new IPTrackingInboundHandler();
   this.outboundIpTracking = new IPTrackingOutboundHandler();
   this.handlerProvider = handlerProvider;
   this.bindClient = bindClient;
   this.corsConfig = corsConfig;
}
 
Example #4
Source File: IvrFallbackServerModule.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {
   // No Session Listeners
   Multibinder<SessionListener> slBindings = Multibinder.newSetBinder(binder(), SessionListener.class);

   // Bind Http Handlers
   Multibinder<RequestHandler> rhBindings = Multibinder.newSetBinder(binder(), RequestHandler.class);
   rhBindings.addBinding().to(RootRedirect.class);
   rhBindings.addBinding().to(CheckPage.class);
   rhBindings.addBinding().to(IndexPage.class);
   rhBindings.addBinding().to(TwilioFallbackHandler.class);
   rhBindings.addBinding().to(TwilioRequestHandler.class);

   // TODO why isn't this part of the NoAuthModule...
   bind(RequestAuthorizer.class)
      .annotatedWith(Names.named("SessionAuthorizer"))
      .to(AlwaysAllow.class);

   // use the BaseHandler because it isn't abstract as the name implies, its just doesn't fully support websockets
   bind(ChannelInboundHandler.class).toProvider(BaseWebSocketServerHandlerProvider.class);

   // TODO bind this up into a WebSocket / NoWebSocket module...
   bind(RequestMatcher.class).annotatedWith(Names.named("WebSocketUpgradeMatcher")).to(NeverMatcher.class);
}
 
Example #5
Source File: BillingServerModule.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {
   // No Session Listeners
   Multibinder<SessionListener> slBindings = Multibinder.newSetBinder(binder(), SessionListener.class);

   // Bind Http Handlers
   Multibinder<RequestHandler> rhBindings = Multibinder.newSetBinder(binder(), RequestHandler.class);
   rhBindings.addBinding().to(RootRedirect.class);
   rhBindings.addBinding().to(IndexPage.class);
   rhBindings.addBinding().to(CheckPage.class);
   rhBindings.addBinding().to(RecurlyCallbackHttpHandler.class);

   bind(RequestAuthorizer.class)
      .annotatedWith(Names.named("SessionAuthorizer"))
      .to(AlwaysAllow.class);

   MapBinder<String,WebhookHandler<? extends Object>> actionBinder = MapBinder.newMapBinder(binder(),new TypeLiteral<String>(){},new TypeLiteral<WebhookHandler<? extends Object>>(){});
   actionBinder.addBinding(RecurlyCallbackHttpHandler.TRANS_TYPE_CLOSED_INVOICE_NOTIFICATION).to(ClosedInvoiceWebhookHandler.class);

   // use the BaseHandler because it isn't abstract as the name implies, its just doesn't fully support websockets
   bind(ChannelInboundHandler.class).toProvider(BaseWebSocketServerHandlerProvider.class);

   // TODO bind this up into a WebSocket / NoWebSocket module...
   bind(RequestMatcher.class).annotatedWith(Names.named("WebSocketUpgradeMatcher")).to(NeverMatcher.class);
}
 
Example #6
Source File: IvrServerModule.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {
   // No Session Listeners
   Multibinder<SessionListener> slBindings = Multibinder.newSetBinder(binder(), SessionListener.class);

   // Bind Http Handlers
   Multibinder<RequestHandler> rhBindings = Multibinder.newSetBinder(binder(), RequestHandler.class);
   rhBindings.addBinding().to(RootRedirect.class);
   rhBindings.addBinding().to(IndexPage.class);
   rhBindings.addBinding().to(CheckPage.class);
   rhBindings.addBinding().to(TwilioAckScriptHandler.class);
   rhBindings.addBinding().to(TwilioAckEventHandler.class);

   bind(NotificationAuditor.class).to(CassandraAuditor.class);

   // TODO why isn't this part of the NoAuthModule...
   bind(RequestAuthorizer.class)
      .annotatedWith(Names.named("SessionAuthorizer"))
      .to(AlwaysAllow.class);

   // use the BaseHandler because it isn't abstract as the name implies, its just doesn't fully support websockets
   bind(ChannelInboundHandler.class).toProvider(BaseWebSocketServerHandlerProvider.class);

   // TODO bind this up into a WebSocket / NoWebSocket module...
   bind(RequestMatcher.class).annotatedWith(Names.named("WebSocketUpgradeMatcher")).to(NeverMatcher.class);
}
 
Example #7
Source File: RemoterNNHA.java    From jumbune with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Write to channel.
 *
 * @param channel the channel
 * @param magicBytes the magic bytes
 * @param pathOrCommand the path or command
 * @param attachment the attachment
 * @throws ConnectException the connect exception
 */
private void writeToChannel(Channel channel, String[] magicBytes, Object pathOrCommand, Object attachment) throws ConnectException {
	long firstAttempt = System.currentTimeMillis();
	long timeOut = RemotingConstants.TEN * RemotingConstants.THOUSAND;
	while (!channel.isOpen() || !channel.isActive()) {
		if (System.currentTimeMillis() - firstAttempt >= timeOut) {
			try {
				throw new TimeoutException();
			} catch (TimeoutException e) {
				logger.error("Waited for 10 sec for connection reattempt to JumbuneAgent, but failed to connect", e);
			}
			break;
		}
	}
	if (!channel.isActive()) {
		logger.warn("Channel #" + channel.hashCode() + " still disconnected, about to write on disconnected Channel");
	}
	if (attachment != null && attachment instanceof CyclicBarrier) {
		channel.attr(RemotingConstants.barrierKey).set((CyclicBarrier)attachment);
	}else if (attachment != null) {
		channel.attr(RemotingConstants.handlerKey).set((ChannelInboundHandler)attachment);
	}
	channel.write(Unpooled.wrappedBuffer(magicBytes[0].getBytes(), magicBytes[1].getBytes(), magicBytes[2].getBytes()));
	channel.write(pathOrCommand);
	channel.flush();
}
 
Example #8
Source File: RemoterHA.java    From jumbune with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Write to channel.
 *
 * @param channel the channel
 * @param magicBytes the magic bytes
 * @param pathOrCommand the path or command
 * @param attachment the attachment
 */
private void writeToChannel(Channel channel, String[] magicBytes, Object pathOrCommand, Object attachment) throws ConnectException {
	long firstAttempt = System.currentTimeMillis();
	long timeOut = RemotingConstants.TEN * RemotingConstants.THOUSAND;
	while (!channel.isOpen() || !channel.isActive()) {
		if (System.currentTimeMillis() - firstAttempt >= timeOut) {
			try {
				throw new TimeoutException();
			} catch (TimeoutException e) {
				logger.error("Waited for 10 sec for connection reattempt to JumbuneAgent, but failed to connect", e);
			}
			break;
		}
	}
	if (!channel.isActive()) {
		logger.warn("channel #" + channel.hashCode() + " still disconnected, about to write on disconnected Channel");
	}
	if (attachment != null && attachment instanceof CyclicBarrier) {
		channel.attr(RemotingConstants.barrierKey).set((CyclicBarrier)attachment);
	}else if (attachment != null) {
		channel.attr(RemotingConstants.handlerKey).set((ChannelInboundHandler)attachment);
	}
	channel.write(Unpooled.wrappedBuffer(magicBytes[0].getBytes(), magicBytes[1].getBytes(), magicBytes[2].getBytes()));
	channel.write(pathOrCommand);
	channel.flush();
}
 
Example #9
Source File: HttpChannelInitializerTest.java    From riposte with Apache License 2.0 6 votes vote down vote up
@Test
public void initChannel_adds_HttpServerCodec_as_the_first_inbound_handler_after_sslCtx() {
    // given
    HttpChannelInitializer hci = basicHttpChannelInitializerNoUtilityHandlers();

    // when
    hci.initChannel(socketChannelMock);

    // then
    ArgumentCaptor<ChannelHandler> channelHandlerArgumentCaptor = ArgumentCaptor.forClass(ChannelHandler.class);
    verify(channelPipelineMock, atLeastOnce()).addLast(anyString(), channelHandlerArgumentCaptor.capture());
    List<ChannelHandler> handlers = channelHandlerArgumentCaptor.getAllValues();
    Pair<Integer, ChannelInboundHandler> firstInboundHandler = findChannelHandler(handlers, ChannelInboundHandler.class);
    Pair<Integer, HttpServerCodec> foundHandler = findChannelHandler(handlers, HttpServerCodec.class);

    assertThat(firstInboundHandler, notNullValue());
    assertThat(foundHandler, notNullValue());

    // No SSL Context was passed, so HttpRequestDecoder should be the first inbound handler.
    assertThat(foundHandler.getLeft(), is(firstInboundHandler.getLeft()));
    assertThat(foundHandler.getRight(), is(firstInboundHandler.getRight()));
}
 
Example #10
Source File: IrisNettyCORSChannelInitializer.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Inject
public IrisNettyCORSChannelInitializer(
   BridgeServerTlsContext tlsContext,
   BridgeServerConfig serverConfig,
   Provider<TrafficHandler> trafficHandlerProvider,
   Provider<ChannelInboundHandler> channelInboundProvider,
   SslForwardedBindClientHandler sslForwardedBindClientHandler,
   SslBindClientHandler sslBindClientHandler,
   BasicAuthClientContextHandler basicAuthHandler,
   BindClientContextHandler bindClientHandler,
   ClearClientContextHandler clearClientHandler,
   IrisNettyCorsConfig corsConfig
) {
   super(tlsContext, serverConfig, trafficHandlerProvider, channelInboundProvider, 
         sslForwardedBindClientHandler, sslBindClientHandler, basicAuthHandler, bindClientHandler,
         clearClientHandler);
   this.corsConfig = corsConfig;
}
 
Example #11
Source File: VoiceBridgeModule.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
   bind(BridgeServerConfig.class);
   bind(BridgeServerTlsContext.class).to(BridgeServerTlsContextImpl.class);
   bind(BridgeServerTrustManagerFactory.class).to(NullTrustManagerFactoryImpl.class);
   bind(ChannelInboundHandler.class).toProvider(BaseWebSocketServerHandlerProvider.class);
   bind(CHANNEL_INITIALIZER_TYPE_LITERAL).to(HttpRequestInitializer.class);
   bind(RequestMatcher.class).annotatedWith(Names.named("WebSocketUpgradeMatcher")).to(NeverMatcher.class);
   bind(IrisNettyAuthorizationContextLoader.class).to(IrisNettyNoopAuthorizationContextLoader.class);

   // No Session Listeners
   Multibinder<SessionListener> slBindings = Multibinder.newSetBinder(binder(), SessionListener.class);

   // Bind Http Handlers
   Multibinder<RequestHandler> rhBindings = Multibinder.newSetBinder(binder(), RequestHandler.class);
   rhBindings.addBinding().to(RootRedirect.class);
   rhBindings.addBinding().to(IndexPage.class);
   rhBindings.addBinding().to(CheckPage.class);

   rhBindings.addBinding().to(SessionLogin.class);
   rhBindings.addBinding().to(SessionLogout.class);
   rhBindings.addBinding().to(ListPlacesRESTHandler.class);
   rhBindings.addBinding().to(TokenHandler.class);
   rhBindings.addBinding().to(RevokeHandler.class);
   rhBindings.addBinding().to(AuthorizeHandler.class);

   // oauth
   bind(OAuthDAO.class).to(CassandraOAuthDAO.class);
   bind(RequestAuthorizer.class).annotatedWith(Names.named("SessionAuthorizer")).to(SessionAuth.class);
   bind(SessionFactory.class).to(DefaultSessionFactoryImpl.class);
   bind(SessionRegistry.class).to(DefaultSessionRegistryImpl.class);
   bind(Responder.class).annotatedWith(Names.named("SessionLogin")).to(SessionLoginResponder.class);
   bind(Responder.class).annotatedWith(Names.named("SessionLogout")).to(SessionLogoutResponder.class);
   bind(Authenticator.class).to(ShiroAuthenticator.class);
   bind(PlaceSelectionHandler.class).to(VoicePlaceSelectionHandler.class);
}
 
Example #12
Source File: OlapPipelineFactory.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
public OlapPipelineFactory(ChannelInboundHandler submitHandler, ChannelInboundHandler cancelHandler, ChannelInboundHandler statusHandler){
    this.submitHandler=submitHandler;
    this.cancelHandler=cancelHandler;
    this.statusHandler=statusHandler;

    this.decoder = new ProtobufDecoder(OlapMessage.Command.getDefaultInstance(),buildExtensionRegistry());
}
 
Example #13
Source File: HttpCacheClientTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
public ServerChannel start(ChannelInboundHandler handler) {
  return createServer(
      NioServerSocketChannel.class,
      NioEventLoopGroup::new,
      new InetSocketAddress("localhost", 0),
      handler);
}
 
Example #14
Source File: RemoterNonHA.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
	 * Write to channel.
	 *
	 * @param channel the channel
	 * @param magicBytes the magic bytes
	 * @param pathOrCommand the path or command
	 * @param attachment the attachment
	 */
	private void writeToChannel(Channel channel, String[] magicBytes, Object pathOrCommand, Object attachment) throws ConnectException {

		//update leader agent details
//		if (pathOrCommand instanceof CommandWritable
//				&& ((CommandWritable) pathOrCommand).isCommandForMaster()) {
//			CommandWritable commandWritable = (CommandWritable) pathOrCommand;
//			AgentNode agent = ZKUtils.getLeaderAgentfromZK();
//			commandWritable.setNameNodeHost(agent.getHost());
//			if(commandWritable.isHasSshAuthKeysFile()){
//				commandWritable.setSshAuthKeysFile(agent.getPrivateKey());
//			}
//		}

		long firstAttempt = System.currentTimeMillis();
		long timeOut = RemotingConstants.TEN * RemotingConstants.THOUSAND;
		while (!channel.isOpen() || !channel.isActive()) {
			if (System.currentTimeMillis() - firstAttempt >= timeOut) {
				try {
					throw new TimeoutException();
				} catch (TimeoutException e) {
					logger.error("Waited for 10 sec for connection reattempt to JumbuneAgent, but failed to connect", e);
				}
				break;
			}
		}
		if (!channel.isActive()) {
			logger.warn("channel #" + channel.hashCode() + " still disconnected, about to write on disconnected Channel");
		}
		if (attachment != null && attachment instanceof CyclicBarrier) {
			channel.attr(RemotingConstants.barrierKey).set((CyclicBarrier)attachment);
		}else if (attachment != null) {
			channel.attr(RemotingConstants.handlerKey).set((ChannelInboundHandler)attachment);
		}
		channel.write(Unpooled.wrappedBuffer(magicBytes[0].getBytes(), magicBytes[1].getBytes(), magicBytes[2].getBytes()));
		channel.write(pathOrCommand);
		channel.flush();
	}
 
Example #15
Source File: ProxyConnectConnectionFactoryFilterTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
private ChannelPipeline configurePipeline(@Nullable SslHandshakeCompletionEvent event) {
    ChannelPipeline pipeline = mock(ChannelPipeline.class);
    when(pipeline.addLast(any())).then((Answer<ChannelPipeline>) invocation -> {
        ChannelInboundHandler handshakeAwait = invocation.getArgument(0);
        if (event != null) {
            handshakeAwait.userEventTriggered(mock(ChannelHandlerContext.class), event);
        }
        return pipeline;
    });
    return pipeline;
}
 
Example #16
Source File: AbstractIpcdServerModule.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
protected final void configure() {
   bind(BridgeServerConfig.class);
   bind(TrustConfig.class);
   bind(BridgeServerTlsContext.class).to(BridgeServerTlsContextImpl.class);
   bind(BridgeServerTrustManagerFactory.class).to(SimpleTrustManagerFactoryImpl.class);
   bind(ProtocolBusService.class).to(ProtocolBusServiceImpl.class).asEagerSingleton();
   bindSetOf(ProtocolBusListener.class).addBinding().to(IpcdProtocolBusListener.class);
   bind(PlatformBusService.class).to(IpcdPlatformBusServiceImpl.class).asEagerSingleton();
   Multibinder<PlatformBusListener> platformListenerBinder = bindSetOf(PlatformBusListener.class);
   platformListenerBinder.addBinding().to(IpcdServiceEventListener.class);      
   bindMessageHandler();
   bind(Authenticator.class).to(NoopAuthenticator.class);
   bind(ClientFactory.class).to(IpcdClientFactory.class);
   bind(new TypeLiteral<ChannelInitializer<SocketChannel>>(){}).to(Bridge10ChannelInitializer.class);
   bind(ChannelInboundHandler.class).toProvider(Text10WebSocketServerHandlerProvider.class);
   bindSessionFactory();
   bind(SessionRegistry.class).to(DefaultSessionRegistryImpl.class);
   bindSessionSupplier();
   bind(SessionHeartBeater.class);

   bind(DefaultIpcdDeliveryStrategy.class);
   bindDeliveryStrategies();
   bind(RequestMatcher.class).annotatedWith(Names.named("WebSocketUpgradeMatcher")).to(WebSocketUpgradeMatcher.class);
   bind(RequestAuthorizer.class).annotatedWith(Names.named("SessionAuthorizer")).to(AlwaysAllow.class);

   Multibinder<SessionListener> slBindings = Multibinder.newSetBinder(binder(), SessionListener.class);
   bindSessionListener(slBindings);

   Multibinder<RequestHandler> rhBindings = Multibinder.newSetBinder(binder(), RequestHandler.class);
   rhBindings.addBinding().to(RootRedirect.class);
   bindHttpHandlers(rhBindings);
}
 
Example #17
Source File: HttpRequestInitializer.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Inject
public HttpRequestInitializer(
   Provider<ChannelInboundHandler> channelInboundProvider,
   BridgeServerTlsContext tlsContext, 
   BridgeServerConfig serverConfig, 
   VideoConfig videoConfig,
   IrisNettyCorsConfig corsConfig
) {
   this.serverTlsContext = tlsContext;
   this.serverConfig = serverConfig;
   this.videoConfig = videoConfig;
   this.channelInboundProvider = channelInboundProvider;
   this.corsConfig = corsConfig;
}
 
Example #18
Source File: VideoStreamingServerModule.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
   bind(BridgeServerConfig.class);
   bind(VideoStreamingServerConfig.class);

   bind(BridgeServerTlsContext.class).to(BridgeServerTlsContextImpl.class);
   bind(BridgeServerTrustManagerFactory.class).to(NullTrustManagerFactoryImpl.class);

   bind(SessionFactory.class).to(NullSessionFactoryImpl.class);
   bind(SessionRegistry.class).to(NullSessionRegistryImpl.class);
   bind(ClientFactory.class).to(VideoStreamingClientFactory.class);

   bind(ChannelInboundHandler.class).toProvider(BaseWebSocketServerHandlerProvider.class);
   bind(new TypeLiteral<ChannelInitializer<SocketChannel>>(){}).to(HttpRequestInitializer.class);

   bind(RequestMatcher.class).annotatedWith(Names.named("WebSocketUpgradeMatcher")).to(NeverMatcher.class);
   bind(RequestAuthorizer.class).annotatedWith(Names.named("SessionAuthorizer")).to(AlwaysAllow.class);

   // No Session Listeners
   Multibinder<SessionListener> slBindings = Multibinder.newSetBinder(binder(), SessionListener.class);

   // Bind Http Handlers
   Multibinder<RequestHandler> rhBindings = Multibinder.newSetBinder(binder(), RequestHandler.class);
   rhBindings.addBinding().to(CheckPage.class);
   rhBindings.addBinding().to(HlsHandler.class);
   rhBindings.addBinding().to(HlsPlaylistHandler.class);
   rhBindings.addBinding().to(HlsIFrameHandler.class);
   rhBindings.addBinding().to(HlsVideoHandler.class);
   rhBindings.addBinding().to(JPGHandler.class);

   if (dash) {         
      rhBindings.addBinding().to(DashVideoHandler.class);
   }
}
 
Example #19
Source File: HttpRequestInitializer.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Inject
public HttpRequestInitializer(
   BridgeServerTlsContext tlsContext,
   BridgeServerConfig serverConfig,
   VideoPreviewUploadServerConfig config,
   Provider<ChannelInboundHandler> handlerProvider) {
   this.serverTlsContext = tlsContext;
   this.serverConfig = serverConfig;
   this.config = config;

   this.inboundIpTracking = new IPTrackingInboundHandler();
   this.outboundIpTracking = new IPTrackingOutboundHandler();
   this.handlerProvider = handlerProvider;
}
 
Example #20
Source File: VideoPreviewUploadServerModule.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
   bind(BridgeServerConfig.class);
   bind(TrustConfig.class);
   bind(PreviewConfig.class);
   bind(HubSessionListener.class).to(NoopHubSessionListener.class);
   bind(SessionFactory.class).to(HubSessionFactory.class);
   bind(SessionRegistry.class).to(DefaultSessionRegistryImpl.class);
   bind(ClientFactory.class).to(VideoPreviewUploadClientFactory.class);

   bind(BridgeServerTlsContext.class).to(BridgeServerTlsContextImpl.class);
   bind(BridgeServerTrustManagerFactory.class).to(HubTrustManagerFactoryImpl.class);
   bind(new TypeLiteral<ChannelInitializer<SocketChannel>>(){}).to(HttpRequestInitializer.class);

   bind(ChannelInboundHandler.class).toProvider(BaseWebSocketServerHandlerProvider.class);
   bind(RequestMatcher.class).annotatedWith(Names.named("WebSocketUpgradeMatcher")).to(NeverMatcher.class);
   bind(RequestAuthorizer.class).annotatedWith(Names.named("SessionAuthorizer")).to(AlwaysAllow.class);

   bind(VideoPreviewUploadServerConfig.class);

   // No Session Listeners
   Multibinder<SessionListener> slBindings = Multibinder.newSetBinder(binder(), SessionListener.class);

   // Bind Http Handlers
   Multibinder<RequestHandler> rhBindings = Multibinder.newSetBinder(binder(), RequestHandler.class);
   rhBindings.addBinding().to(RootRedirect.class);
   rhBindings.addBinding().to(CheckPage.class);
   rhBindings.addBinding().to(IndexPage.class);
   rhBindings.addBinding().to(UploadHandler.class);
}
 
Example #21
Source File: HttpRequestInitializer.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Inject
public HttpRequestInitializer(
   BridgeServerTlsContext tlsContext,
   BridgeServerConfig serverConfig,
   Provider<ChannelInboundHandler> handlerProvider,
   OAuthBindClientContextHandler oauthBindClientContext
) {
   this.serverTlsContext = tlsContext;
   this.serverConfig = serverConfig;

   this.inboundIpTracking = new IPTrackingInboundHandler();
   this.outboundIpTracking = new IPTrackingOutboundHandler();
   this.handlerProvider = handlerProvider;
   this.oauthBindClientContext = oauthBindClientContext;
}
 
Example #22
Source File: BootstrapTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 10000)
public void testBindDeadLock() throws Exception {
    EventLoopGroup groupA = new LocalEventLoopGroup(1);
    EventLoopGroup groupB = new LocalEventLoopGroup(1);

    try {
        ChannelInboundHandler dummyHandler = new DummyHandler();

        final Bootstrap bootstrapA = new Bootstrap();
        bootstrapA.group(groupA);
        bootstrapA.channel(LocalChannel.class);
        bootstrapA.handler(dummyHandler);

        final Bootstrap bootstrapB = new Bootstrap();
        bootstrapB.group(groupB);
        bootstrapB.channel(LocalChannel.class);
        bootstrapB.handler(dummyHandler);

        List<Future<?>> bindFutures = new ArrayList<Future<?>>();

        // Try to bind from each other.
        for (int i = 0; i < 1024; i ++) {
            bindFutures.add(groupA.next().submit(new Runnable() {
                @Override
                public void run() {
                    bootstrapB.bind(LocalAddress.ANY);
                }
            }));

            bindFutures.add(groupB.next().submit(new Runnable() {
                @Override
                public void run() {
                    bootstrapA.bind(LocalAddress.ANY);
                }
            }));
        }

        for (Future<?> f: bindFutures) {
            f.sync();
        }
    } finally {
        groupA.shutdownGracefully();
        groupB.shutdownGracefully();
        groupA.terminationFuture().sync();
        groupB.terminationFuture().sync();
    }
}
 
Example #23
Source File: HubServerModule.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Override
protected void configure() {
    bind(TrustConfig.class);

    bind(HubMessageFilter.class).to(DefaultHubMessageFilterImpl.class);

    bind(BridgeServerTlsContext.class).to(BridgeServerTlsContextImpl.class);
    bind(BridgeServerTrustManagerFactory.class).to(HubTrustManagerFactoryImpl.class);
    bind(PlatformBusService.class).to(PlatformBusServiceImpl.class).asEagerSingleton();
    bind(ProtocolBusService.class).to(ProtocolBusServiceImpl.class).asEagerSingleton();
    bindSetOf(PlatformBusListener.class)
            .addBinding()
            .to(HubPlatformBusListener.class);

    bindSetOf(ProtocolBusListener.class)
            .addBinding()
            .to(HubProtocolBusListener.class);

    bind(new TypeLiteral<DeviceMessageHandler<ByteBuf>>() {
    }).to(HubMessageHandler.class);

    Multibinder<DirectMessageHandler> directHandlers = bindSetOf(DirectMessageHandler.class);
    directHandlers.addBinding().to(HubConnectedHandler.class);
    directHandlers.addBinding().to(HubRegisteredResponseHandler.class);
    directHandlers.addBinding().to(HubFirmwareUpgradeProcessEventHandler.class);
    directHandlers.addBinding().to(HubFirmwareUpdateResponseHandler.class);


    bind(new TypeLiteral<ChannelInitializer<SocketChannel>>() {
    }).to(Bridge10ChannelInitializer.class);
    bind(ChannelInboundHandler.class).toProvider(Binary10WebSocketServerHandlerProvider.class);

    bind(RequestMatcher.class).annotatedWith(Names.named("WebSocketUpgradeMatcher")).to(WebSocketUpgradeMatcher.class);
    bind(RequestAuthorizer.class).annotatedWith(Names.named("SessionAuthorizer")).to(AlwaysAllow.class);

    // No Session Listeners
    Multibinder<SessionListener> slBindings = Multibinder.newSetBinder(binder(), SessionListener.class);

    // Bind Http Handlers
    Multibinder<RequestHandler> rhBindings = Multibinder.newSetBinder(binder(), RequestHandler.class);
    if (clientAuthRequired) {
        rhBindings.addBinding().to(RootRedirect.class);
        rhBindings.addBinding().to(IndexPage.class);
    } else {
        rhBindings.addBinding().to(RootRemoteRedirect.class);
    }
    rhBindings.addBinding().to(CheckPage.class);

}
 
Example #24
Source File: HttpCacheClientTest.java    From bazel with Apache License 2.0 4 votes vote down vote up
public ServerChannel start(ChannelInboundHandler handler) {
  reset(this.serverChannel);
  this.handler = handler;
  return this.serverChannel;
}
 
Example #25
Source File: SpdyOrHttpHandler.java    From netty-cookbook with Apache License 2.0 4 votes vote down vote up
@Override
protected ChannelInboundHandler createHttpRequestHandlerForHttp() {
    return new SpdyServerHandler();
}
 
Example #26
Source File: ClientServerModule.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Override
protected void configure() {
   bind(BridgeServerConfig.class);
   bind(BridgeServerTlsContext.class).to(BridgeServerTlsContextImpl.class);
   bind(BridgeServerTrustManagerFactory.class).to(NullTrustManagerFactoryImpl.class);
   bind(PlatformBusService.class).to(IrisNettyPlatformBusServiceImpl.class).asEagerSingleton();
   bindSetOf(PlatformBusListener.class)
      .addBinding()
      .to(IrisNettyPlatformBusListener.class);      
   bind(new TypeLiteral<DeviceMessageHandler<String>>(){}).to(IrisNettyMessageHandler.class);
   bind(Authenticator.class).to(ShiroAuthenticator.class);
   bind(SessionFactory.class).to(DefaultSessionFactoryImpl.class);
   bind(SessionRegistry.class).to(DefaultSessionRegistryImpl.class);      
   bind(NotificationAuditor.class).to(CassandraAuditor.class);

   if(algorithm.equalsIgnoreCase(AUTHZ_LOADER_NONE)) {
      bind(IrisNettyAuthorizationContextLoader.class).to(IrisNettyNoopAuthorizationContextLoader.class);
   } else {
      bind(IrisNettyAuthorizationContextLoader.class).to(SubscriberAuthorizationContextLoader.class);
   }

   
   Multibinder<SessionListener> slBindings = Multibinder.newSetBinder(binder(), SessionListener.class);
   slBindings.addBinding().to(HandshakeSessionListener.class);
   slBindings.addBinding().to(StopCameraPreviewsUploadSessionListener.class);

   bind(ChannelInboundHandler.class).toProvider(WebSocketServerHandlerProvider.class);
   bind(new TypeLiteral<ChannelInitializer<SocketChannel>>(){})
      .to(IrisNettyCORSChannelInitializer.class);

   bind(RequestMatcher.class).annotatedWith(Names.named("WebSocketUpgradeMatcher")).to(WebSocketUpgradeMatcher.class);
   bind(RequestAuthorizer.class).annotatedWith(Names.named("SessionAuthorizer")).to(SessionAuth.class);

   //Bind Login and Logout
   bind(Responder.class).annotatedWith(Names.named("SessionLogin")).to(SessionLoginResponder.class);
   bind(Responder.class).annotatedWith(Names.named("SessionLogout")).to(SessionLogoutResponder.class);
   
   // Bind Http Handlers
   Multibinder<RequestHandler> rhBindings = Multibinder.newSetBinder(binder(), RequestHandler.class);
   rhBindings.addBinding().to(SessionLogin.class);
   rhBindings.addBinding().to(RootRedirect.class);
   rhBindings.addBinding().to(CheckPage.class);
   rhBindings.addBinding().to(IndexPage.class);
   rhBindings.addBinding().to(LoginPage.class);
   
   /* Bounce handlers */
   rhBindings.addBinding().to(AppleAppSiteAssociationHandler.class);
   rhBindings.addBinding().to(AppFallbackHandler.class);
   rhBindings.addBinding().to(AppLaunchHandler.class);
   rhBindings.addBinding().to(WebLaunchHandler.class);
   rhBindings.addBinding().to(WebRunHandler.class);
   
   /* ProductCatalog RestHandlers */
   rhBindings.addBinding().to(GetProductCatalogRESTHandler.class);
   rhBindings.addBinding().to(GetProductsRESTHandler.class);
   rhBindings.addBinding().to(FindProductsRESTHandler.class);
   rhBindings.addBinding().to(GetBrandsRESTHandler.class);
   rhBindings.addBinding().to(GetCategoriesRESTHandler.class);
   rhBindings.addBinding().to(GetProductRESTHandler.class);
   rhBindings.addBinding().to(GetProductsByBrandRESTHandler.class);
   rhBindings.addBinding().to(GetProductsByCategoryRESTHandler.class);

   // NWS SAME and EAS Code REST Handlers
   rhBindings.addBinding().to(GetSameCodeRESTHandler.class);
   rhBindings.addBinding().to(ListSameCountiesRESTHandler.class);
   rhBindings.addBinding().to(ListSameStatesRESTHandler.class);    
   rhBindings.addBinding().to(ListEasCodesRESTHandler.class);

   /* Other RestHandlers */
   rhBindings.addBinding().to(ChangePinRESTHandler.class);
   rhBindings.addBinding().to(ChangePinV2RESTHandler.class);
   rhBindings.addBinding().to(VerifyPinRESTHandler.class);
   rhBindings.addBinding().to(CreateAccountRESTHandler.class);
   rhBindings.addBinding().to(ChangePasswordRESTHandler.class);
   rhBindings.addBinding().to(LoadLocalizedStringsRESTHandler.class);
   rhBindings.addBinding().to(ResetPasswordRESTHandler.class);
   rhBindings.addBinding().to(SendPasswordResetRESTHandler.class);
   rhBindings.addBinding().to(SessionLogout.class);
   rhBindings.addBinding().to(SessionLogRESTHandler.class);
   rhBindings.addBinding().to(ListTimezonesRESTHandler.class);
   rhBindings.addBinding().to(AcceptInvitationCreateLoginRESTHandler.class);
   rhBindings.addBinding().to(GetInvitationRESTHandler.class);
   rhBindings.addBinding().to(GetInvoiceRESTHandler.class);
   rhBindings.addBinding().to(LockDeviceRESTHandler.class);
   rhBindings.addBinding().to(RequestEmailVerificatonRESTHandler.class);
   rhBindings.addBinding().to(VerifyEmailRESTHandler.class);

   /* Static resource handler */
   // should be bound last because its matcher is super-greedy 
   rhBindings.addBinding().to(WebAppStaticResources.class);
}
 
Example #27
Source File: TransactionTimeoutHandler.java    From WZWave with Eclipse Public License 1.0 4 votes vote down vote up
public TransactionTimeoutHandler(String id, ChannelHandlerContext context, ChannelInboundHandler handler) {
    this.id = id;
    this.context = context;
    this.handler = handler;
}
 
Example #28
Source File: RsfDuplexHandler.java    From hasor with Apache License 2.0 4 votes vote down vote up
public RsfDuplexHandler(ChannelInboundHandler inBoundArray, ChannelOutboundHandler outBoundArray) {
    super(inBoundArray, outBoundArray);
}
 
Example #29
Source File: BootstrapTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 10000)
public void testConnectDeadLock() throws Exception {
    EventLoopGroup groupA = new LocalEventLoopGroup(1);
    EventLoopGroup groupB = new LocalEventLoopGroup(1);

    try {
        ChannelInboundHandler dummyHandler = new DummyHandler();

        final Bootstrap bootstrapA = new Bootstrap();
        bootstrapA.group(groupA);
        bootstrapA.channel(LocalChannel.class);
        bootstrapA.handler(dummyHandler);

        final Bootstrap bootstrapB = new Bootstrap();
        bootstrapB.group(groupB);
        bootstrapB.channel(LocalChannel.class);
        bootstrapB.handler(dummyHandler);

        List<Future<?>> bindFutures = new ArrayList<Future<?>>();

        // Try to connect from each other.
        for (int i = 0; i < 1024; i ++) {
            bindFutures.add(groupA.next().submit(new Runnable() {
                @Override
                public void run() {
                    bootstrapB.connect(LocalAddress.ANY);
                }
            }));

            bindFutures.add(groupB.next().submit(new Runnable() {
                @Override
                public void run() {
                    bootstrapA.connect(LocalAddress.ANY);
                }
            }));
        }

        for (Future<?> f: bindFutures) {
            f.sync();
        }
    } finally {
        groupA.shutdownGracefully();
        groupB.shutdownGracefully();
        groupA.terminationFuture().sync();
        groupB.terminationFuture().sync();
    }
}
 
Example #30
Source File: HttpServerChannelInitializer.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
/**
 * @param handler the handler to set
 */
public void setHandler(ChannelInboundHandler handler) {
   this.handler = handler;
}