use of org.apache.activemq.artemis.dto.AppDTO in project activemq-artemis by apache.
the class ReplicatedFailoverTest method testReplicatedFailbackBackupFromLiveBackToBackup.
@Test
public void testReplicatedFailbackBackupFromLiveBackToBackup() throws Exception {
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 8787);
HttpServer httpServer = HttpServer.create(address, 100);
httpServer.start();
try {
httpServer.createContext("/", new HttpHandler() {
@Override
public void handle(HttpExchange t) throws IOException {
String response = "<html><body><b>This is a unit test</b></body></html>";
t.sendResponseHeaders(200, response.length());
OutputStream os = t.getResponseBody();
os.write(response.getBytes());
os.close();
}
});
WebServerDTO wdto = new WebServerDTO();
AppDTO appDTO = new AppDTO();
appDTO.war = "console.war";
appDTO.url = "console";
wdto.apps = new ArrayList<AppDTO>();
wdto.apps.add(appDTO);
wdto.bind = "http://localhost:0";
wdto.path = "console";
WebServerComponent webServerComponent = new WebServerComponent();
webServerComponent.configure(wdto, ".", ".");
webServerComponent.start();
backupServer.getServer().getNetworkHealthCheck().parseURIList("http://localhost:8787");
Assert.assertTrue(backupServer.getServer().getNetworkHealthCheck().isStarted());
backupServer.getServer().addExternalComponent(webServerComponent);
// this is called when backup servers go from live back to backup
backupServer.getServer().fail(true);
Assert.assertTrue(backupServer.getServer().getNetworkHealthCheck().isStarted());
Assert.assertTrue(backupServer.getServer().getExternalComponents().get(0).isStarted());
((ServiceComponent) (backupServer.getServer().getExternalComponents().get(0))).stop(true);
} finally {
httpServer.stop(0);
}
}
use of org.apache.activemq.artemis.dto.AppDTO in project activemq-artemis by apache.
the class WebServerComponent method configure.
@Override
public void configure(ComponentDTO config, String artemisInstance, String artemisHome) throws Exception {
webServerConfig = (WebServerDTO) config;
uri = new URI(webServerConfig.bind);
server = new Server();
String scheme = uri.getScheme();
if ("https".equals(scheme)) {
SslContextFactory sslFactory = new SslContextFactory();
sslFactory.setKeyStorePath(webServerConfig.keyStorePath == null ? artemisInstance + "/etc/keystore.jks" : webServerConfig.keyStorePath);
sslFactory.setKeyStorePassword(webServerConfig.getKeyStorePassword() == null ? "password" : webServerConfig.getKeyStorePassword());
if (webServerConfig.clientAuth != null) {
sslFactory.setNeedClientAuth(webServerConfig.clientAuth);
if (webServerConfig.clientAuth) {
sslFactory.setTrustStorePath(webServerConfig.trustStorePath);
sslFactory.setTrustStorePassword(webServerConfig.getTrustStorePassword());
}
}
SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(sslFactory, "HTTP/1.1");
HttpConfiguration https = new HttpConfiguration();
https.addCustomizer(new SecureRequestCustomizer());
HttpConnectionFactory httpFactory = new HttpConnectionFactory(https);
connector = new ServerConnector(server, sslConnectionFactory, httpFactory);
} else {
connector = new ServerConnector(server);
}
connector.setPort(uri.getPort());
connector.setHost(uri.getHost());
server.setConnectors(new Connector[] { connector });
handlers = new HandlerList();
Path homeWarDir = Paths.get(artemisHome != null ? artemisHome : ".").resolve(webServerConfig.path).toAbsolutePath();
Path instanceWarDir = Paths.get(artemisInstance != null ? artemisInstance : ".").resolve(webServerConfig.path).toAbsolutePath();
if (webServerConfig.apps != null && webServerConfig.apps.size() > 0) {
webContexts = new ArrayList<>();
for (AppDTO app : webServerConfig.apps) {
Path dirToUse = homeWarDir;
if (new File(instanceWarDir.toFile().toString() + File.separator + app.war).exists()) {
dirToUse = instanceWarDir;
}
WebAppContext webContext = deployWar(app.url, app.war, dirToUse);
webContexts.add(webContext);
if (app.war.startsWith("console")) {
consoleUrl = webServerConfig.bind + "/" + app.url;
}
}
}
ResourceHandler homeResourceHandler = new ResourceHandler();
homeResourceHandler.setResourceBase(homeWarDir.toString());
homeResourceHandler.setDirectoriesListed(false);
homeResourceHandler.setWelcomeFiles(new String[] { "index.html" });
ContextHandler homeContext = new ContextHandler();
homeContext.setContextPath("/");
homeContext.setResourceBase(homeWarDir.toString());
homeContext.setHandler(homeResourceHandler);
homeContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
ResourceHandler instanceResourceHandler = new ResourceHandler();
instanceResourceHandler.setResourceBase(instanceWarDir.toString());
instanceResourceHandler.setDirectoriesListed(false);
instanceResourceHandler.setWelcomeFiles(new String[] { "index.html" });
ContextHandler instanceContext = new ContextHandler();
instanceContext.setContextPath("/");
instanceContext.setResourceBase(instanceWarDir.toString());
instanceContext.setHandler(instanceResourceHandler);
homeContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
DefaultHandler defaultHandler = new DefaultHandler();
defaultHandler.setServeIcon(false);
handlers.addHandler(homeContext);
handlers.addHandler(instanceContext);
handlers.addHandler(defaultHandler);
server.setHandler(handlers);
}
Aggregations