Java Code Examples for org.springframework.boot.web.context.WebServerInitializedEvent

The following examples show how to use org.springframework.boot.web.context.WebServerInitializedEvent. These examples are extracted from open source projects. 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
@Override
public void onApplicationEvent(ApplicationEvent applicationEvent) {
	if (applicationEvent instanceof WebServerInitializedEvent) {
		WebServerInitializedEvent event = (WebServerInitializedEvent) applicationEvent;

		ApplicationContext context = event.getApplicationContext();
		if (context instanceof ConfigurableWebServerApplicationContext) {
			if ("management"
					.equals(((ConfigurableWebServerApplicationContext) context)
							.getServerNamespace())) {
				return;
			}
		}
		this.autoServiceRegistration.setPortIfNeeded(event.getWebServer().getPort());
		this.autoServiceRegistration.start();
	}
}
 
Example 2
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
    Service service = ((TomcatWebServer) event.getWebServer()).getTomcat().getService();
    for (Connector connector : service.findConnectors()) {
        if (connector.getSecure()) {
            this.httpsPort = connector.getLocalPort();
        } else {
            this.httpPort = connector.getLocalPort();
        }
    }
}
 
Example 3
Source Project: soul   Source File: ApplicationStartListener.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(final WebServerInitializedEvent event) {
    int port = event.getWebServer().getPort();
    final String host = getHost();
    final String domain = System.getProperty("soul.httpPath");
    if (StringUtils.isBlank(domain)) {
        SoulDomain.getInstance()
                .setHttpPath("http://" + String.join(":", host, String.valueOf(port)));
    } else {
        SoulDomain.getInstance()
                .setHttpPath(domain);
    }
}
 
Example 4
Source Project: inception   Source File: GenericEventAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean accepts(Object aEvent)
{
    return aEvent instanceof ApplicationEvent && !(
            aEvent instanceof ApplicationContextEvent || 
            aEvent instanceof ServletRequestHandledEvent ||
            aEvent instanceof SessionCreationEvent ||
            aEvent instanceof SessionDestroyedEvent ||
            aEvent instanceof AbstractAuthorizationEvent ||
            aEvent instanceof AbstractAuthenticationEvent ||
            aEvent instanceof WebServerInitializedEvent);
}
 
Example 5
@Async
@Order
@EventListener(WebServerInitializedEvent.class)
public void afterStart(WebServerInitializedEvent event) {
	Environment environment = event.getApplicationContext().getEnvironment();
	String appName = environment.getProperty("spring.application.name").toUpperCase();
	int localPort = event.getWebServer().getPort();
	String profile = StringUtils.arrayToCommaDelimitedString(environment.getActiveProfiles());
	log.info("---[{}]---启动完成,当前使用的端口:[{}],环境变量:[{}]---", appName, localPort, profile);
}
 
Example 6
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {

    if (!discoveryProperties.isAutoRegister()) {
        return;
    }

    Register register = discoveryProperties.getRegister();

    if (StringUtils.isEmpty(register.getIp())) {
        register.setIp(NetUtils.localIP());
    }

    if (register.getPort() == 0) {
        register.setPort(event.getWebServer().getPort());
    }

    register.getMetadata().put("preserved.register.source", "SPRING_BOOT");

    register.setInstanceId("");

    String serviceName = register.getServiceName();

    if (StringUtils.isEmpty(serviceName)){
        if (StringUtils.isEmpty(applicationName)){
            throw new AutoRegisterException("serviceName notNull");
        }
        serviceName = applicationName;
    }

    try {
        namingService.registerInstance(serviceName, register.getGroupName(),
                register);
        logger.info("Finished auto register service : {}, ip : {}, port : {}",
                serviceName, register.getIp(), register.getPort());
    } catch (NacosException e) {
        throw new AutoRegisterException(e);
    }
}
 
Example 7
@Override
public void onApplicationEvent(final WebServerInitializedEvent event) {
    int port = event.getWebServer().getPort();
    final String host = getHost();
    Address.getInstance()
            .setHost(host)
            .setPort(port)
            .setDomain(String.join(":", host, String.valueOf(port)));
}
 
Example 8
Source Project: saluki   Source File: WebAppAutoConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
    int httpPort = event.getWebServer().getPort();
    if (grpcProperties.getRegistryHttpPort() == 0) {
        if (httpPort != 0) {
            grpcProperties.setRegistryHttpPort(httpPort);
        }
    }
}
 
Example 9
@Deprecated
public void bind(WebServerInitializedEvent event) {
	ApplicationContext context = event.getApplicationContext();
	if (context instanceof ConfigurableWebServerApplicationContext) {
		if ("management".equals(((ConfigurableWebServerApplicationContext) context)
				.getServerNamespace())) {
			return;
		}
	}
	this.port.compareAndSet(0, event.getWebServer().getPort());
	this.start();
}
 
Example 10
@Override
public void onApplicationEvent(WebServerInitializedEvent webServerInitializedEvent) {
	this.port = webServerInitializedEvent.getWebServer().getPort();
	if (this.port > 0) {
		simple.getLocal()
				.setUri(URI.create("http://"
						+ this.inet.findFirstNonLoopbackHostInfo().getHostname() + ":"
						+ this.port));
	}
}
 
Example 11
@Override
public void onApplicationEvent(WebServerInitializedEvent webServerInitializedEvent) {
	port = webServerInitializedEvent.getWebServer().getPort();
	if (port > 0) {
		simple.getLocal().setUri(URI.create("http://"
				+ inet.findFirstNonLoopbackHostInfo().getHostname() + ":" + port));
	}
}
 
Example 12
@Override
public void onApplicationEvent(ApplicationEvent event) {
	if (event instanceof WebServerInitializedEvent) {
		onApplicationEvent((WebServerInitializedEvent) event);
	}
	else if (event instanceof ContextClosedEvent) {
		onApplicationEvent((ContextClosedEvent) event);
	}
}
 
Example 13
public void onApplicationEvent(WebServerInitializedEvent event) {
	// TODO: take SSL into account
	String contextName = event.getApplicationContext().getServerNamespace();
	if (contextName == null || !contextName.equals("management")) {
		int localPort = event.getWebServer().getPort();
		if (this.port.get() == 0) {
			log.info("Updating port to " + localPort);
			this.port.compareAndSet(0, localPort);
			start();
		}
	}
}
 
Example 14
@EventListener
public void onWebServerInitialized(WebServerInitializedEvent event) {
	String name = event.getApplicationContext().getServerNamespace();
	if ("server".equals(name) || !StringUtils.hasText(name)) {
		localServerPort = event.getWebServer().getPort();
	}
	else if ("management".equals(name)) {
		localManagementPort = event.getWebServer().getPort();
	}
}
 
Example 15
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
    // TODO Auto-generated method stub
    this.event = event;
}
 
Example 16
Source Project: Moss   Source File: ServerConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
    serverPort = event.getWebServer().getPort();
}
 
Example 17
@EventListener(WebServerInitializedEvent.class)
public void onWebServerReady(WebServerInitializedEvent event) {
    System.out.println("当前 WebServer 实现类为:" + event.getWebServer().getClass().getName());
}
 
Example 18
Source Project: MicroCommunity   Source File: ServiceInfoListener.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
    this.serverPort = event.getWebServer().getPort();
}
 
Example 19
Source Project: karate   Source File: ServerStartedInitializingBean.java    License: MIT License 4 votes vote down vote up
@Override
public void onApplicationEvent(WebServerInitializedEvent e) {
	localPort = e.getWebServer().getPort();
	logger.info("after runtime init, local server port: {}", localPort);
}
 
Example 20
Source Project: webanno   Source File: TelemetryServiceImpl.java    License: Apache License 2.0 4 votes vote down vote up
@EventListener
public void onApplicationEvent(WebServerInitializedEvent aEvt)
{
    port = aEvt.getWebServer().getPort();
}
 
Example 21
Source Project: webanno   Source File: StandaloneShutdownDialog.java    License: Apache License 2.0 4 votes vote down vote up
@EventListener
public void onApplicationEvent(WebServerInitializedEvent aEvt) {
    port = aEvt.getWebServer().getPort();
}
 
Example 22
Source Project: testcontainers-java   Source File: SeleniumContainerTest.java    License: MIT License 4 votes vote down vote up
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    applicationContext.addApplicationListener((ApplicationListener<WebServerInitializedEvent>) event -> {
        Testcontainers.exposeHostPorts(event.getWebServer().getPort());
    });
}
 
Example 23
Source Project: spring-cloud-zookeeper   Source File: DependencyConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
	this.port = event.getWebServer().getPort();
}
 
Example 24
@Override
@SuppressWarnings("deprecation")
public void onApplicationEvent(WebServerInitializedEvent event) {
	bind(event);
}
 
Example 25
@Override
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
	return WebServerInitializedEvent.class.isAssignableFrom(eventType)
			|| ContextClosedEvent.class.isAssignableFrom(eventType);
}
 
Example 26
@Override
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
	return WebServerInitializedEvent.class.isAssignableFrom(eventType);
}
 
Example 27
@Override
public void bind(WebServerInitializedEvent event) {
	// do nothing so we can listen for this event in a different class
	// this ensures start() can be retried if spring-retry is available
}