Permalink
Browse files

Fix refresh in undertow launcher

  • Loading branch information...
adrienlauer committed Nov 30, 2017
1 parent 759be30 commit 715429a8f4cca63cb2e7a6c7c78ae522de20407a
View
@@ -1,3 +1,7 @@
# Version 3.4.1 (2017-11-29)
* [fix] Undertow-based applications would not refresh after a startup failure.
# Version 3.4.0 (2017-11-28)
* [new] Validation exceptions on REST resources are automatically mapped to a detailed response.
View
@@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.1-SNAPSHOT</version>
</parent>
<artifactId>seed-cli</artifactId>
View
@@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.1-SNAPSHOT</version>
</parent>
<artifactId>seed-core</artifactId>
View
@@ -19,7 +19,7 @@
<groupId>org.seedstack.seed</groupId>
<artifactId>seed</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
View
@@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-rest</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.1-SNAPSHOT</version>
</parent>
<artifactId>seed-rest-core</artifactId>
View
@@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-rest</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.1-SNAPSHOT</version>
</parent>
<artifactId>seed-rest-jersey2</artifactId>
View
@@ -13,7 +13,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.1-SNAPSHOT</version>
</parent>
<artifactId>seed-rest</artifactId>
View
@@ -13,7 +13,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-rest</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.1-SNAPSHOT</version>
</parent>
<artifactId>seed-rest-specs</artifactId>
View
@@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-security</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.1-SNAPSHOT</version>
</parent>
<artifactId>seed-security-core</artifactId>
View
@@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.1-SNAPSHOT</version>
</parent>
<artifactId>seed-security</artifactId>
View
@@ -13,7 +13,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-security</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.1-SNAPSHOT</version>
</parent>
<artifactId>seed-security-specs</artifactId>
View
@@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.1-SNAPSHOT</version>
</parent>
<artifactId>seed-specs</artifactId>
@@ -28,7 +28,7 @@
*/
void shutdown() throws Exception;
default void refresh() {
default void refresh() throws Exception {
throw new UnsupportedOperationException("Refresh is not supported by this launcher");
}
}
View
@@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.1-SNAPSHOT</version>
</parent>
<artifactId>seed-testing</artifactId>
View
@@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-web</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.1-SNAPSHOT</version>
</parent>
<artifactId>seed-web-core</artifactId>
View
@@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.1-SNAPSHOT</version>
</parent>
<artifactId>seed-web</artifactId>
View
@@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-web</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.1-SNAPSHOT</version>
</parent>
<artifactId>seed-web-security</artifactId>
View
@@ -13,7 +13,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-web</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.1-SNAPSHOT</version>
</parent>
<artifactId>seed-web-specs</artifactId>
View
@@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-web</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.1-SNAPSHOT</version>
</parent>
<artifactId>seed-web-undertow</artifactId>
@@ -12,13 +12,13 @@
import io.nuun.kernel.api.Plugin;
import io.undertow.Undertow;
import io.undertow.servlet.api.DeploymentManager;
import javax.servlet.ServletException;
import org.seedstack.seed.SeedException;
import org.seedstack.seed.core.Seed;
import org.seedstack.seed.spi.SeedLauncher;
import org.seedstack.seed.undertow.UndertowConfig;
import org.seedstack.seed.web.WebConfig;
import org.seedstack.seed.web.internal.ServletContextUtils;
import org.seedstack.shed.exception.BaseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,7 +37,6 @@ public void launch(String[] args) throws Exception {
// Start the HTTP server
start(serverConfig, undertowConfig);
}
@Override
@@ -47,60 +46,68 @@ public void shutdown() throws Exception {
}
@Override
public void refresh() {
public void refresh() throws Exception {
LOGGER.info("Refreshing Web application");
if (undertow != null && deploymentManager != null) {
stop();
undeploy();
stop();
undeploy();
Seed.refresh();
Seed.refresh();
WebConfig.ServerConfig serverConfig = Seed.baseConfiguration().get(WebConfig.ServerConfig.class);
UndertowConfig undertowConfig = Seed.baseConfiguration().get(UndertowConfig.class);
WebConfig.ServerConfig serverConfig = Seed.baseConfiguration().get(WebConfig.ServerConfig.class);
UndertowConfig undertowConfig = Seed.baseConfiguration().get(UndertowConfig.class);
deploy(serverConfig);
start(serverConfig, undertowConfig);
}
deploy(serverConfig);
start(serverConfig, undertowConfig);
}
private void deploy(WebConfig.ServerConfig serverConfig) {
DeploymentManagerFactory factory = new DeploymentManagerFactory(serverConfig);
deploymentManager = factory.createDeploymentManager();
deploymentManager.deploy();
private void deploy(WebConfig.ServerConfig serverConfig) throws Exception {
try {
DeploymentManagerFactory factory = new DeploymentManagerFactory(serverConfig);
deploymentManager = factory.createDeploymentManager();
deploymentManager.deploy();
deploymentManager.start();
} catch (ServletException e) {
LOGGER.error("An error occurred when trying to start the servlet context", e);
} catch (Exception e) {
handleUndertowException(e);
}
}
private void undeploy() {
private void undeploy() throws Exception {
if (deploymentManager != null) {
try {
deploymentManager.stop();
} catch (ServletException e) {
LOGGER.error("An error occurred when trying to stop the servlet context", e);
deploymentManager.undeploy();
} catch (Exception e) {
handleUndertowException(e);
} finally {
deploymentManager = null;
}
deploymentManager.undeploy();
deploymentManager = null;
}
}
private void start(WebConfig.ServerConfig serverConfig, UndertowConfig undertowConfig) {
UndertowPlugin undertowPlugin = getUndertowPlugin(deploymentManager);
undertow = new ServerFactory(serverConfig, undertowConfig).createServer(
deploymentManager,
undertowPlugin.getSslProvider()
);
undertow.start();
LOGGER.info("Undertow Web server listening on {}:{}", serverConfig.getHost(), serverConfig.getPort());
private void start(WebConfig.ServerConfig serverConfig, UndertowConfig undertowConfig) throws Exception {
try {
UndertowPlugin undertowPlugin = getUndertowPlugin(deploymentManager);
undertow = new ServerFactory(serverConfig, undertowConfig).createServer(
deploymentManager,
undertowPlugin.getSslProvider()
);
undertow.start();
LOGGER.info("Undertow Web server listening on {}:{}", serverConfig.getHost(), serverConfig.getPort());
} catch (Exception e) {
handleUndertowException(e);
}
}
private void stop() {
private void stop() throws Exception {
if (undertow != null) {
undertow.stop();
LOGGER.info("Undertow Web server stopped");
undertow = null;
try {
undertow.stop();
LOGGER.info("Undertow Web server stopped");
} catch (Exception e) {
handleUndertowException(e);
} finally {
undertow = null;
}
}
}
@@ -114,4 +121,13 @@ private UndertowPlugin getUndertowPlugin(DeploymentManager deploymentManager) {
}
throw SeedException.createNew(UndertowErrorCode.MISSING_UNDERTOW_PLUGIN);
}
private void handleUndertowException(Exception e) throws Exception {
// Undertow always wraps exception in a RuntimeException
if (e instanceof RuntimeException && e.getCause() instanceof BaseException) {
throw (BaseException) e.getCause();
} else {
throw e;
}
}
}

0 comments on commit 715429a

Please sign in to comment.