use of java.io.FileInputStream in project jetty.project by eclipse.
the class SslSelectChannelTimeoutTest method init.
@Before
public void init() throws Exception {
String keystorePath = System.getProperty("basedir", ".") + "/src/test/resources/keystore";
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(keystorePath);
sslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.setKeyManagerPassword("keypwd");
sslContextFactory.setTrustStorePath(keystorePath);
sslContextFactory.setTrustStorePassword("storepwd");
ServerConnector connector = new ServerConnector(_server, 1, 1, sslContextFactory);
//250 msec max idle
connector.setIdleTimeout(MAX_IDLE_TIME);
startServer(connector);
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
try (InputStream stream = new FileInputStream(keystorePath)) {
keystore.load(stream, "storepwd".toCharArray());
}
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keystore);
__sslContext = SSLContext.getInstance("SSL");
__sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
}
use of java.io.FileInputStream in project jetty.project by eclipse.
the class SslUploadTest method test.
@Test
@Ignore
public void test() throws Exception {
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
SslContextFactory ctx = connector.getConnectionFactory(SslConnectionFactory.class).getSslContextFactory();
try (InputStream stream = new FileInputStream(ctx.getKeyStorePath())) {
keystore.load(stream, "storepwd".toCharArray());
}
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keystore);
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
final SSLSocket socket = (SSLSocket) sslContext.getSocketFactory().createSocket("localhost", connector.getLocalPort());
// Simulate async close
/*
new Thread()
{
@Override
public void run()
{
try
{
sleep(100);
socket.close();
}
catch (IOException x)
{
x.printStackTrace();
}
catch (InterruptedException x)
{
Thread.currentThread().interrupt();
}
}
}.start();
*/
long start = System.nanoTime();
OutputStream out = socket.getOutputStream();
out.write("POST / HTTP/1.1\r\n".getBytes());
out.write("Host: localhost\r\n".getBytes());
out.write("Content-Length: 16777216\r\n".getBytes());
out.write("Content-Type: bytes\r\n".getBytes());
out.write("Connection: close\r\n".getBytes());
out.write("\r\n".getBytes());
out.flush();
byte[] requestContent = new byte[16777216];
Arrays.fill(requestContent, (byte) 120);
out.write(requestContent);
out.flush();
InputStream in = socket.getInputStream();
String response = IO.toString(in);
assertTrue(response.indexOf("200") > 0);
// System.err.println(response);
// long end = System.nanoTime();
// System.out.println("upload time: " + TimeUnit.NANOSECONDS.toMillis(end - start));
assertEquals(requestContent.length, total);
}
use of java.io.FileInputStream in project jetty.project by eclipse.
the class SSLSelectChannelConnectorLoadTest method startServer.
@BeforeClass
public static void startServer() throws Exception {
String keystorePath = System.getProperty("basedir", ".") + "/src/test/resources/keystore";
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(keystorePath);
sslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.setKeyManagerPassword("keypwd");
sslContextFactory.setTrustStorePath(keystorePath);
sslContextFactory.setTrustStorePassword("storepwd");
server = new Server();
connector = new ServerConnector(server, sslContextFactory);
server.addConnector(connector);
server.setHandler(new EmptyHandler());
server.start();
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
try (InputStream stream = new FileInputStream(keystorePath)) {
keystore.load(stream, "storepwd".toCharArray());
}
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keystore);
sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
}
use of java.io.FileInputStream in project jetty.project by eclipse.
the class DatabaseLoginServiceTestServer method runscript.
public static int runscript(File scriptFile) throws Exception {
//System.err.println("Running script:"+scriptFile.getAbsolutePath());
try (FileInputStream fileStream = new FileInputStream(scriptFile)) {
Loader.loadClass("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
Connection connection = DriverManager.getConnection(__dbURL, "", "");
ByteArrayOutputStream out = new ByteArrayOutputStream();
return ij.runScript(connection, fileStream, "UTF-8", out, "UTF-8");
}
}
use of java.io.FileInputStream in project buck by facebook.
the class DefaultAndroidDirectoryResolver method findNdkVersionFromDirectory.
/**
* The method returns the NDK version of a path.
* @param ndkDirectory Path to the folder that contains the NDK.
* @return A string containing the NDK version or absent.
*/
public static Optional<String> findNdkVersionFromDirectory(Path ndkDirectory) {
Path newNdk = ndkDirectory.resolve(NDK_POST_R11_VERSION_FILENAME);
Path oldNdk = ndkDirectory.resolve(NDK_PRE_R11_VERSION_FILENAME);
boolean newNdkPathFound = Files.exists(newNdk);
boolean oldNdkPathFound = Files.exists(oldNdk);
if (newNdkPathFound && oldNdkPathFound) {
throw new HumanReadableException("Android NDK directory " + ndkDirectory + " can not " + "contain both properties files. Remove source.properties or RELEASE.TXT.");
} else if (newNdkPathFound) {
Properties sourceProperties = new Properties();
try (FileInputStream fileStream = new FileInputStream(newNdk.toFile())) {
sourceProperties.load(fileStream);
return Optional.ofNullable(sourceProperties.getProperty("Pkg.Revision"));
} catch (IOException e) {
throw new HumanReadableException("Failed to read NDK version from " + newNdk + ".");
}
} else if (oldNdkPathFound) {
try (BufferedReader reader = Files.newBufferedReader(oldNdk, Charsets.UTF_8)) {
// around since we should consider them equivalent.
return Optional.ofNullable(reader.readLine().split("\\s+")[0].replace("r10e-rc4", "r10e"));
} catch (IOException e) {
throw new HumanReadableException("Failed to read NDK version from " + oldNdk + ".");
}
} else {
throw new HumanReadableException(ndkDirectory + " does not contain a valid properties " + "file for Android NDK.");
}
}
Aggregations