use of java.io.InputStream in project jetty.project by eclipse.
the class WeldInitializationTest method testRequestParamServletAbc.
@Test
public void testRequestParamServletAbc() throws Exception {
HttpURLConnection http = (HttpURLConnection) serverHttpURI.resolve("req-info?abc=123").toURL().openConnection();
assertThat("response code", http.getResponseCode(), is(200));
try (InputStream inputStream = http.getInputStream()) {
String resp = IO.toString(inputStream);
assertThat("Response", resp, containsString("request is PRESENT"));
assertThat("Response", resp, containsString("parameters.size = [1]"));
assertThat("Response", resp, containsString(" param[abc] = [123]"));
}
}
use of java.io.InputStream in project jetty.project by eclipse.
the class WeldInitializationTest method testRequestParamServletDefault.
@Test
public void testRequestParamServletDefault() throws Exception {
HttpURLConnection http = (HttpURLConnection) serverHttpURI.resolve("req-info").toURL().openConnection();
assertThat("response code", http.getResponseCode(), is(200));
try (InputStream inputStream = http.getInputStream()) {
String resp = IO.toString(inputStream);
assertThat("Response", resp, containsString("request is PRESENT"));
assertThat("Response", resp, containsString("parameters.size = [0]"));
}
}
use of java.io.InputStream in project jetty.project by eclipse.
the class Logging method config.
public static void config() {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL url = cl.getResource("logging.properties");
if (url != null) {
try (InputStream in = url.openStream()) {
LogManager.getLogManager().readConfiguration(in);
} catch (IOException e) {
e.printStackTrace(System.err);
}
}
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Jdk14Logger");
}
use of java.io.InputStream in project jetty.project by eclipse.
the class ALPNNegotiationTest method testClientAdvertisingMultipleProtocolsServerSpeaksHTTPWhenNegotiated.
@Test
public void testClientAdvertisingMultipleProtocolsServerSpeaksHTTPWhenNegotiated() throws Exception {
InetSocketAddress address = prepare();
SslContextFactory sslContextFactory = newSslContextFactory();
sslContextFactory.start();
SSLContext sslContext = sslContextFactory.getSslContext();
try (SSLSocket client = (SSLSocket) sslContext.getSocketFactory().createSocket(address.getAddress(), address.getPort())) {
client.setUseClientMode(true);
client.setSoTimeout(5000);
ALPN.put(client, new ALPN.ClientProvider() {
@Override
public void unsupported() {
}
@Override
public List<String> protocols() {
return Arrays.asList("unknown/1.0", "http/1.1");
}
@Override
public void selected(String protocol) {
Assert.assertEquals("http/1.1", protocol);
}
});
client.startHandshake();
// Verify that the server really speaks http/1.1
OutputStream output = client.getOutputStream();
output.write(("" + "GET / HTTP/1.1\r\n" + "Host: localhost:" + address.getPort() + "\r\n" + "\r\n" + "").getBytes(StandardCharsets.UTF_8));
output.flush();
InputStream input = client.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertTrue(line.contains(" 404 "));
}
}
use of java.io.InputStream in project jetty.project by eclipse.
the class ALPNNegotiationTest method testClientAdvertisingHTTPServerSpeaksHTTP.
@Test
public void testClientAdvertisingHTTPServerSpeaksHTTP() throws Exception {
InetSocketAddress address = prepare();
SslContextFactory sslContextFactory = newSslContextFactory();
sslContextFactory.start();
SSLContext sslContext = sslContextFactory.getSslContext();
try (SSLSocket client = (SSLSocket) sslContext.getSocketFactory().createSocket(address.getAddress(), address.getPort())) {
client.setUseClientMode(true);
client.setSoTimeout(5000);
ALPN.put(client, new ALPN.ClientProvider() {
@Override
public void unsupported() {
}
@Override
public List<String> protocols() {
return Arrays.asList("http/1.1");
}
@Override
public void selected(String protocol) {
Assert.assertEquals("http/1.1", protocol);
}
});
client.startHandshake();
// Verify that the server really speaks http/1.1
OutputStream output = client.getOutputStream();
output.write(("" + "GET / HTTP/1.1\r\n" + "Host: localhost:" + address.getPort() + "\r\n" + "\r\n" + "").getBytes(StandardCharsets.UTF_8));
output.flush();
InputStream input = client.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertTrue(line.contains(" 404 "));
}
}
Aggregations