use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class SSLHelper method getTrustMgrFactory.
private TrustManagerFactory getTrustMgrFactory(VertxInternal vertx) throws Exception {
TrustManagerFactory fact;
if (trustAll) {
TrustManager[] mgrs = new TrustManager[] { createTrustAllTrustManager() };
fact = new VertxTrustManagerFactory(mgrs);
} else if (trustOptions != null) {
fact = trustOptions.getTrustManagerFactory(vertx);
} else {
return null;
}
if (crlPaths != null && crlValues != null && (crlPaths.size() > 0 || crlValues.size() > 0)) {
Stream<Buffer> tmp = crlPaths.stream().map(path -> vertx.resolveFile(path).getAbsolutePath()).map(vertx.fileSystem()::readFileBlocking);
tmp = Stream.concat(tmp, crlValues.stream());
CertificateFactory certificatefactory = CertificateFactory.getInstance("X.509");
ArrayList<CRL> crls = new ArrayList<>();
for (Buffer crlValue : tmp.collect(Collectors.toList())) {
crls.addAll(certificatefactory.generateCRLs(new ByteArrayInputStream(crlValue.getBytes())));
}
TrustManager[] mgrs = createUntrustRevokedCertTrustManager(fact.getTrustManagers(), crls);
fact = new VertxTrustManagerFactory(mgrs);
}
return fact;
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class RecordParserImpl method parseDelimited.
private void parseDelimited() {
int len = buff.length();
for (; pos < len && !reset; pos++) {
if (buff.getByte(pos) == delim[delimPos]) {
delimPos++;
if (delimPos == delim.length) {
Buffer ret = buff.getBuffer(start, pos - delim.length + 1);
start = pos + 1;
delimPos = 0;
output.handle(ret);
}
} else {
if (delimPos > 0) {
pos -= delimPos;
delimPos = 0;
}
}
}
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class RecordParserImpl method parseFixed.
private void parseFixed() {
int len = buff.length();
while (len - start >= recordSize && !reset) {
int end = start + recordSize;
Buffer ret = buff.getBuffer(start, end);
start = end;
pos = start - 1;
output.handle(ret);
}
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class Http1xTest method testCopyClientOptions.
@Test
public void testCopyClientOptions() {
HttpClientOptions options = new HttpClientOptions();
int sendBufferSize = TestUtils.randomPositiveInt();
int receiverBufferSize = TestUtils.randomPortInt();
Random rand = new Random();
boolean reuseAddress = rand.nextBoolean();
int trafficClass = TestUtils.randomByte() + 128;
boolean tcpNoDelay = rand.nextBoolean();
boolean tcpKeepAlive = rand.nextBoolean();
int soLinger = TestUtils.randomPositiveInt();
boolean usePooledBuffers = rand.nextBoolean();
int idleTimeout = TestUtils.randomPositiveInt();
boolean ssl = rand.nextBoolean();
KeyCertOptions keyCertOptions = randomKeyCertOptions();
TrustOptions trustOptions = randomTrustOptions();
String enabledCipher = TestUtils.randomAlphaString(100);
int connectTimeout = TestUtils.randomPositiveInt();
boolean trustAll = rand.nextBoolean();
String crlPath = TestUtils.randomUnicodeString(100);
Buffer crlValue = TestUtils.randomBuffer(100);
boolean verifyHost = rand.nextBoolean();
int maxPoolSize = TestUtils.randomPositiveInt();
boolean keepAlive = rand.nextBoolean();
boolean pipelining = rand.nextBoolean();
int pipeliningLimit = TestUtils.randomPositiveInt();
int http2MaxPoolSize = TestUtils.randomPositiveInt();
int http2MultiplexingLimit = TestUtils.randomPositiveInt();
int http2ConnectionWindowSize = TestUtils.randomPositiveInt();
boolean tryUseCompression = rand.nextBoolean();
HttpVersion protocolVersion = HttpVersion.HTTP_1_0;
int maxChunkSize = TestUtils.randomPositiveInt();
int maxInitialLineLength = TestUtils.randomPositiveInt();
int maxHeaderSize = TestUtils.randomPositiveInt();
int maxWaitQueueSize = TestUtils.randomPositiveInt();
Http2Settings initialSettings = randomHttp2Settings();
boolean useAlpn = TestUtils.randomBoolean();
SSLEngineOptions sslEngine = TestUtils.randomBoolean() ? new JdkSSLEngineOptions() : new OpenSSLEngineOptions();
List<HttpVersion> alpnVersions = Collections.singletonList(HttpVersion.values()[TestUtils.randomPositiveInt() % 3]);
boolean h2cUpgrade = TestUtils.randomBoolean();
boolean openSslSessionCacheEnabled = rand.nextBoolean();
boolean sendUnmaskedFrame = rand.nextBoolean();
String localAddress = TestUtils.randomAlphaString(10);
options.setSendBufferSize(sendBufferSize);
options.setReceiveBufferSize(receiverBufferSize);
options.setReuseAddress(reuseAddress);
options.setTrafficClass(trafficClass);
options.setSsl(ssl);
options.setTcpNoDelay(tcpNoDelay);
options.setTcpKeepAlive(tcpKeepAlive);
options.setSoLinger(soLinger);
options.setUsePooledBuffers(usePooledBuffers);
options.setIdleTimeout(idleTimeout);
options.setKeyCertOptions(keyCertOptions);
options.setTrustOptions(trustOptions);
options.addEnabledCipherSuite(enabledCipher);
options.setConnectTimeout(connectTimeout);
options.setTrustAll(trustAll);
options.addCrlPath(crlPath);
options.addCrlValue(crlValue);
options.setVerifyHost(verifyHost);
options.setMaxPoolSize(maxPoolSize);
options.setKeepAlive(keepAlive);
options.setPipelining(pipelining);
options.setPipeliningLimit(pipeliningLimit);
options.setHttp2MaxPoolSize(http2MaxPoolSize);
options.setHttp2MultiplexingLimit(http2MultiplexingLimit);
options.setHttp2ConnectionWindowSize(http2ConnectionWindowSize);
options.setTryUseCompression(tryUseCompression);
options.setProtocolVersion(protocolVersion);
options.setMaxChunkSize(maxChunkSize);
options.setMaxInitialLineLength(maxInitialLineLength);
options.setMaxHeaderSize(maxHeaderSize);
options.setMaxWaitQueueSize(maxWaitQueueSize);
options.setInitialSettings(initialSettings);
options.setUseAlpn(useAlpn);
options.setSslEngineOptions(sslEngine);
options.setAlpnVersions(alpnVersions);
options.setHttp2ClearTextUpgrade(h2cUpgrade);
options.setLocalAddress(localAddress);
options.setSendUnmaskedFrames(sendUnmaskedFrame);
HttpClientOptions copy = new HttpClientOptions(options);
checkCopyHttpClientOptions(options, copy);
HttpClientOptions copy2 = new HttpClientOptions(options.toJson());
checkCopyHttpClientOptions(options, copy2);
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class Http1xTest method testConnectionClose.
private void testConnectionClose(Handler<HttpClientRequest> clientRequest, Handler<NetSocket> connectHandler) throws Exception {
client.close();
server.close();
NetServerOptions serverOptions = new NetServerOptions();
CountDownLatch serverLatch = new CountDownLatch(1);
vertx.createNetServer(serverOptions).connectHandler(connectHandler).listen(8080, result -> {
if (result.succeeded()) {
serverLatch.countDown();
} else {
fail();
}
});
awaitLatch(serverLatch);
HttpClientOptions clientOptions = new HttpClientOptions().setDefaultHost("localhost").setDefaultPort(8080).setKeepAlive(true).setPipelining(false);
client = vertx.createHttpClient(clientOptions);
int requests = 11;
AtomicInteger count = new AtomicInteger(requests);
for (int i = 0; i < requests; i++) {
HttpClientRequest req = client.get("/", resp -> {
resp.bodyHandler(buffer -> {
});
resp.endHandler(v -> {
if (count.decrementAndGet() == 0) {
complete();
}
});
resp.exceptionHandler(th -> {
fail();
});
}).exceptionHandler(th -> {
fail();
});
clientRequest.handle(req);
}
await();
}
Aggregations