use of io.vertx.core.VertxException in project vert.x by eclipse.
the class HAManager method processFailover.
// Process the failover of a deployment
private void processFailover(JsonObject failedVerticle) {
if (failDuringFailover) {
throw new VertxException("Oops!");
}
// This method must block until the failover is complete - i.e. the verticle is successfully redeployed
final String verticleName = failedVerticle.getString("verticle_name");
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Throwable> err = new AtomicReference<>();
// Now deploy this verticle on this node
ContextImpl ctx = vertx.getContext();
if (ctx != null) {
// We could be on main thread in which case we don't want to overwrite tccl
ContextImpl.setContext(null);
}
JsonObject options = failedVerticle.getJsonObject("options");
try {
doDeployVerticle(verticleName, new DeploymentOptions(options), result -> {
if (result.succeeded()) {
log.info("Successfully redeployed verticle " + verticleName + " after failover");
} else {
log.error("Failed to redeploy verticle after failover", result.cause());
err.set(result.cause());
}
latch.countDown();
Throwable t = err.get();
if (t != null) {
throw new VertxException(t);
}
});
} finally {
if (ctx != null) {
ContextImpl.setContext(ctx);
}
}
try {
if (!latch.await(120, TimeUnit.SECONDS)) {
throw new VertxException("Timed out waiting for redeploy on failover");
}
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
}
use of io.vertx.core.VertxException in project vert.x by eclipse.
the class FileResolver method unpackFromBundleURL.
/**
* bundle:// urls are used by OSGi implementations to refer to a file contained in a bundle, or in a fragment. There
* is not much we can do to get the file from it, except reading it from the url. This method copies the files by
* reading it from the url.
*
* @param url the url
* @return the extracted file
*/
private synchronized File unpackFromBundleURL(URL url) {
try {
File file = new File(cacheDir, url.getHost() + File.separator + url.getFile());
file.getParentFile().mkdirs();
if (url.toExternalForm().endsWith("/")) {
// Directory
file.mkdirs();
} else {
file.getParentFile().mkdirs();
try (InputStream is = url.openStream()) {
if (ENABLE_CACHING) {
Files.copy(is, file.toPath());
} else {
Files.copy(is, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
} catch (FileAlreadyExistsException ignore) {
}
}
} catch (IOException e) {
throw new VertxException(e);
}
return new File(cacheDir, url.getHost() + File.separator + url.getFile());
}
use of io.vertx.core.VertxException in project vert.x by eclipse.
the class ClientConnection method handleClosed.
protected synchronized void handleClosed() {
super.handleClosed();
if (ws != null) {
ws.handleClosed();
}
Exception e = new VertxException("Connection was closed");
// Signal requests failed
if (metrics.isEnabled()) {
for (HttpClientRequestImpl req : requests) {
metrics.requestReset(req.metric());
}
if (currentResponse != null) {
metrics.requestReset(currentResponse.request().metric());
}
}
// Connection was closed - call exception handlers for any requests in the pipeline or one being currently written
for (HttpClientRequestImpl req : requests) {
req.handleException(e);
}
if (currentRequest != null) {
currentRequest.handleException(e);
} else if (currentResponse != null) {
currentResponse.handleException(e);
}
// The connection has been closed - tell the pool about it, this allows the pool to create more
// connections. Note the pool doesn't actually remove the connection, when the next person to get a connection
// gets the closed on, they will check if it's closed and if so get another one.
pool.connectionClosed(this);
}
use of io.vertx.core.VertxException in project vert.x by eclipse.
the class SSLHelper method createContext.
/*
If you don't specify a trust store, and you haven't set system properties, the system will try to use either a file
called jsssecacerts or cacerts in the JDK/JRE security directory.
You can override this by specifying the javax.echo.ssl.trustStore system property
If you don't specify a key store, and don't specify a system property no key store will be used
You can override this by specifying the javax.echo.ssl.keyStore system property
*/
private SslContext createContext(VertxInternal vertx) {
try {
KeyManagerFactory keyMgrFactory = getKeyMgrFactory(vertx);
TrustManagerFactory trustMgrFactory = getTrustMgrFactory(vertx);
SslContextBuilder builder;
if (client) {
builder = SslContextBuilder.forClient();
if (keyMgrFactory != null) {
builder.keyManager(keyMgrFactory);
}
} else {
if (keyMgrFactory == null) {
throw new VertxException("Key/certificate is mandatory for SSL");
}
builder = SslContextBuilder.forServer(keyMgrFactory);
}
Collection<String> cipherSuites = enabledCipherSuites;
if (openSsl) {
builder.sslProvider(SslProvider.OPENSSL);
if (cipherSuites == null || cipherSuites.isEmpty()) {
cipherSuites = OpenSsl.availableOpenSslCipherSuites();
}
} else {
builder.sslProvider(SslProvider.JDK);
if (cipherSuites == null || cipherSuites.isEmpty()) {
cipherSuites = DEFAULT_JDK_CIPHER_SUITE;
}
}
if (trustMgrFactory != null) {
builder.trustManager(trustMgrFactory);
}
if (cipherSuites != null && cipherSuites.size() > 0) {
builder.ciphers(cipherSuites);
}
if (useAlpn && applicationProtocols != null && applicationProtocols.size() > 0) {
builder.applicationProtocolConfig(new ApplicationProtocolConfig(ApplicationProtocolConfig.Protocol.ALPN, ApplicationProtocolConfig.SelectorFailureBehavior.NO_ADVERTISE, ApplicationProtocolConfig.SelectedListenerFailureBehavior.ACCEPT, applicationProtocols.stream().map(PROTOCOL_NAME_MAPPING::get).collect(Collectors.toList())));
}
return builder.build();
} catch (Exception e) {
throw new VertxException(e);
}
}
use of io.vertx.core.VertxException in project vert.x by eclipse.
the class SSLEngineTest method doTest.
private void doTest(SSLEngineOptions engine, boolean useAlpn, HttpVersion version, String error, String expectedSslContext, boolean expectCause) {
server.close();
HttpServerOptions options = new HttpServerOptions().setSslEngineOptions(engine).setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST).setKeyCertOptions(Cert.SERVER_PEM.get()).setSsl(true).setUseAlpn(useAlpn);
try {
server = vertx.createHttpServer(options);
} catch (VertxException e) {
e.printStackTrace();
if (error == null) {
fail(e);
} else {
assertEquals(error, e.getMessage());
if (expectCause) {
assertNotSame(e, e.getCause());
}
}
return;
}
server.requestHandler(req -> {
assertEquals(req.version(), version);
assertTrue(req.isSSL());
req.response().end();
});
server.listen(onSuccess(s -> {
HttpServerImpl impl = (HttpServerImpl) s;
SSLHelper sslHelper = impl.getSslHelper();
SslContext ctx = sslHelper.getContext((VertxInternal) vertx);
switch(expectedSslContext) {
case "jdk":
assertTrue(ctx instanceof JdkSslContext);
break;
case "openssl":
assertTrue(ctx instanceof OpenSslContext);
break;
}
client = vertx.createHttpClient(new HttpClientOptions().setSslEngineOptions(engine).setSsl(true).setUseAlpn(useAlpn).setTrustAll(true).setProtocolVersion(version));
client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> {
assertEquals(200, resp.statusCode());
testComplete();
});
}));
await();
}
Aggregations