org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory Java Examples

The following examples show how to use org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory. 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: JetLinksConfiguration.java    From jetlinks-community with Apache License 2.0 5 votes vote down vote up
@Bean
public WebServerFactoryCustomizer<NettyReactiveWebServerFactory> webServerFactoryWebServerFactoryCustomizer() {
    //解决请求参数最大长度问题
    return factory -> factory.addServerCustomizers(httpServer ->
        httpServer.httpRequestDecoder(spec -> {
            spec.maxInitialLineLength(10240);
            return spec;
        }));
}
 
Example #2
Source File: SoulNettyWebServerFactory.java    From soul with Apache License 2.0 5 votes vote down vote up
/**
 * Netty reactive web server factory netty reactive web server factory.
 *
 * @return the netty reactive web server factory
 */
@Bean
public NettyReactiveWebServerFactory nettyReactiveWebServerFactory() {
    NettyReactiveWebServerFactory webServerFactory = new NettyReactiveWebServerFactory();
    webServerFactory.addServerCustomizers(new EventLoopNettyCustomizer());
    return webServerFactory;
}
 
Example #3
Source File: RoutingConfig.java    From pitchfork with Apache License 2.0 5 votes vote down vote up
/**
 * Since we're impersonating a {@code Zipkin} server we need to support the same set of features.
 * One of the features is request compression, which we handle here by adding a {@link HttpContentDecompressor} to the {@code Netty} pipeline.
 */
@Bean
public ReactiveWebServerFactory reactiveWebServerFactory() {
    NettyReactiveWebServerFactory factory = new NettyReactiveWebServerFactory();

    factory.addServerCustomizers(builder -> builder
            .tcpConfiguration(tcpServer -> {
                return tcpServer.doOnConnection(connection -> connection.addHandler("decompressor", new HttpContentDecompressor()));
            }));

    return factory;
}
 
Example #4
Source File: GatewayAutoConfiguration.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnProperty(name = "spring.cloud.gateway.httpserver.wiretap")
public NettyWebServerFactoryCustomizer nettyServerWiretapCustomizer(
		Environment environment, ServerProperties serverProperties) {
	return new NettyWebServerFactoryCustomizer(environment, serverProperties) {
		@Override
		public void customize(NettyReactiveWebServerFactory factory) {
			factory.addServerCustomizers(httpServer -> httpServer.wiretap(true));
			super.customize(factory);
		}
	};
}
 
Example #5
Source File: SleuthBenchmarkingSpringWebFluxApp.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Bean
NettyReactiveWebServerFactory nettyReactiveWebServerFactory(
		@Value("${server.port:0}") int serverPort) {
	log.info("Starting container at port [" + serverPort + "]");
	return new NettyReactiveWebServerFactory(
			serverPort == 0 ? SocketUtils.findAvailableTcpPort() : serverPort);
}
 
Example #6
Source File: NettyWebServerFactorySslCustomizer.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public void customize(NettyReactiveWebServerFactory serverFactory) {
    Ssl ssl = new Ssl();
    ssl.setEnabled(true);
    ssl.setKeyStore("classpath:sample.jks");
    ssl.setKeyAlias("alias");
    ssl.setKeyPassword("password");
    ssl.setKeyStorePassword("secret");
    Http2 http2 = new Http2();
    http2.setEnabled(false);
    serverFactory.addServerCustomizers(new SslServerCustomizer(ssl, http2, null));
    serverFactory.setPort(8443);
}
 
Example #7
Source File: AllFeaturesTest.java    From feign-reactive with Apache License 2.0 4 votes vote down vote up
@Bean
public ReactiveWebServerFactory reactiveWebServerFactory(){
	return new NettyReactiveWebServerFactory();
}
 
Example #8
Source File: WebFluxServerDsl.java    From spring-fu with Apache License 2.0 4 votes vote down vote up
@Override
public ConfigurableReactiveWebServerFactory get() {
	return new NettyReactiveWebServerFactory();
}
 
Example #9
Source File: Application.java    From liiklus with MIT License 4 votes vote down vote up
public static SpringApplication createSpringApplication(String[] args) {
    var environment = new StandardEnvironment();
    environment.setDefaultProfiles("exporter", "gateway");
    environment.getPropertySources().addFirst(new SimpleCommandLinePropertySource(args));

    var pluginsDir = environment.getProperty("plugins.dir", String.class, "./plugins");
    var pathMatcher = environment.getProperty("plugins.pathMatcher", String.class, "*.jar");

    var pluginsRoot = Paths.get(pluginsDir).toAbsolutePath().normalize();
    log.info("Loading plugins from '{}' with matcher: '{}'", pluginsRoot, pathMatcher);

    var pluginManager = new LiiklusPluginManager(pluginsRoot, pathMatcher);

    pluginManager.loadPlugins();
    pluginManager.startPlugins();

    var binder = Binder.get(environment);
    var application = new SpringApplication(Application.class) {
        @Override
        protected void load(ApplicationContext context, Object[] sources) {
            // We don't want the annotation bean definition reader
        }
    };
    application.setWebApplicationType(WebApplicationType.REACTIVE);
    application.setApplicationContextClass(ReactiveWebServerApplicationContext.class);
    application.setEnvironment(environment);

    application.addInitializers(
            new StringCodecInitializer(false, true),
            new ResourceCodecInitializer(false),
            new ReactiveWebServerInitializer(
                    binder.bind("server", ServerProperties.class).orElseGet(ServerProperties::new),
                    binder.bind("spring.resources", ResourceProperties.class).orElseGet(ResourceProperties::new),
                    binder.bind("spring.webflux", WebFluxProperties.class).orElseGet(WebFluxProperties::new),
                    new NettyReactiveWebServerFactory()
            ),
            new GatewayConfiguration(),
            (GenericApplicationContext applicationContext) -> {
                applicationContext.registerBean("health", RouterFunction.class, () -> {
                    return RouterFunctions.route()
                            .GET("/health", __ -> ServerResponse.ok().bodyValue("OK"))
                            .build();
                });

                applicationContext.registerBean(PluginManager.class, () -> pluginManager);
            }
    );

    application.addInitializers(
            pluginManager.getExtensionClasses(ApplicationContextInitializer.class).stream()
                    .map(it -> {
                        try {
                            return it.getDeclaredConstructor().newInstance();
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    })
                    .toArray(ApplicationContextInitializer[]::new)
    );

    return application;
}
 
Example #10
Source File: NettyWebServerFactoryPortCustomizer.java    From tutorials with MIT License 4 votes vote down vote up
@Override
public void customize(NettyReactiveWebServerFactory serverFactory) {
    serverFactory.addServerCustomizers(new PortCustomizer(8443));
}
 
Example #11
Source File: CustomNettyWebServerFactory.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public NettyReactiveWebServerFactory nettyReactiveWebServerFactory() {
    NettyReactiveWebServerFactory webServerFactory = new NettyReactiveWebServerFactory();
    webServerFactory.addServerCustomizers(new EventLoopNettyCustomizer());
    return webServerFactory;
}