use of io.vertx.core.VertxException in project vert.x by eclipse.
the class FileResolver method unpackFromFileURL.
private synchronized File unpackFromFileURL(URL url, String fileName, ClassLoader cl) {
File resource;
try {
resource = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new VertxException(e);
}
boolean isDirectory = resource.isDirectory();
File cacheFile = new File(cacheDir, fileName);
if (!isDirectory) {
cacheFile.getParentFile().mkdirs();
try {
if (ENABLE_CACHING) {
Files.copy(resource.toPath(), cacheFile.toPath());
} else {
Files.copy(resource.toPath(), cacheFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
} catch (FileAlreadyExistsException ignore) {
} catch (IOException e) {
throw new VertxException(e);
}
} else {
cacheFile.mkdirs();
String[] listing = resource.list();
for (String file : listing) {
String subResource = fileName + "/" + file;
URL url2 = cl.getResource(subResource);
unpackFromFileURL(url2, subResource, cl);
}
}
return cacheFile;
}
use of io.vertx.core.VertxException in project vert.x by eclipse.
the class FileResolver method unpackFromJarURL.
private synchronized File unpackFromJarURL(URL url, String fileName, ClassLoader cl) {
ZipFile zip = null;
try {
String path = url.getPath();
int idx1 = path.lastIndexOf(".jar!");
if (idx1 == -1) {
idx1 = path.lastIndexOf(".zip!");
}
int idx2 = path.lastIndexOf(".jar!", idx1 - 1);
if (idx2 == -1) {
idx2 = path.lastIndexOf(".zip!", idx1 - 1);
}
if (idx2 == -1) {
File file = new File(URLDecoder.decode(path.substring(5, idx1 + 4), "UTF-8"));
zip = new ZipFile(file);
} else {
String s = path.substring(idx2 + 6, idx1 + 4);
File file = resolveFile(s);
zip = new ZipFile(file);
}
String inJarPath = path.substring(idx1 + 6);
String[] parts = JAR_URL_SEP_PATTERN.split(inJarPath);
StringBuilder prefixBuilder = new StringBuilder();
for (int i = 0; i < parts.length - 1; i++) {
prefixBuilder.append(parts[i]).append("/");
}
String prefix = prefixBuilder.toString();
Enumeration<? extends ZipEntry> entries = zip.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
String name = entry.getName();
if (name.startsWith(prefix.isEmpty() ? fileName : prefix + fileName)) {
File file = new File(cacheDir, prefix.isEmpty() ? name : name.substring(prefix.length()));
if (name.endsWith("/")) {
// Directory
file.mkdirs();
} else {
file.getParentFile().mkdirs();
try (InputStream is = zip.getInputStream(entry)) {
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);
} finally {
closeQuietly(zip);
}
return new File(cacheDir, fileName);
}
use of io.vertx.core.VertxException in project vert.x by eclipse.
the class HttpServerImpl method createHandshaker.
WebSocketServerHandshaker createHandshaker(Channel ch, HttpRequest request) {
// As a fun part, Firefox 6.0.2 supports Websockets protocol '7'. But,
// it doesn't send a normal 'Connection: Upgrade' header. Instead it
// sends: 'Connection: keep-alive, Upgrade'. Brilliant.
String connectionHeader = request.headers().get(io.vertx.core.http.HttpHeaders.CONNECTION);
if (connectionHeader == null || !connectionHeader.toLowerCase().contains("upgrade")) {
sendError("\"Connection\" must be \"Upgrade\".", BAD_REQUEST, ch);
return null;
}
if (request.getMethod() != HttpMethod.GET) {
sendError(null, METHOD_NOT_ALLOWED, ch);
return null;
}
try {
WebSocketServerHandshakerFactory factory = new WebSocketServerHandshakerFactory(getWebSocketLocation(ch.pipeline(), request), subProtocols, false, options.getMaxWebsocketFrameSize(), options.isAcceptUnmaskedFrames());
WebSocketServerHandshaker shake = factory.newHandshaker(request);
if (shake == null) {
log.error("Unrecognised websockets handshake");
WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ch);
}
return shake;
} catch (Exception e) {
throw new VertxException(e);
}
}
use of io.vertx.core.VertxException in project vert.x by eclipse.
the class Http2ConnectionBase method setWindowSize.
@Override
public HttpConnection setWindowSize(int windowSize) {
try {
Http2Stream stream = handler.encoder().connection().connectionStream();
int delta = windowSize - this.windowSize;
handler.decoder().flowController().incrementWindowSize(stream, delta);
this.windowSize = windowSize;
return this;
} catch (Http2Exception e) {
throw new VertxException(e);
}
}
use of io.vertx.core.VertxException in project vert.x by eclipse.
the class HostnameResolutionTest method testInvalidHostsConfig.
@Test
public void testInvalidHostsConfig() {
try {
AddressResolverOptions options = new AddressResolverOptions().setHostsPath("whatever.txt");
vertx(new VertxOptions().setAddressResolverOptions(options));
fail();
} catch (VertxException ignore) {
}
}
Aggregations