Search in sources :

Example 1 with InputStream

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]"));
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStream(java.io.InputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 2 with InputStream

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]"));
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStream(java.io.InputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 3 with InputStream

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");
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) URL(java.net.URL)

Example 4 with InputStream

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 "));
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InetSocketAddress(java.net.InetSocketAddress) InputStream(java.io.InputStream) SSLSocket(javax.net.ssl.SSLSocket) OutputStream(java.io.OutputStream) SSLContext(javax.net.ssl.SSLContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) ALPN(org.eclipse.jetty.alpn.ALPN) BufferedReader(java.io.BufferedReader) List(java.util.List) Test(org.junit.Test)

Example 5 with InputStream

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 "));
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InetSocketAddress(java.net.InetSocketAddress) InputStream(java.io.InputStream) SSLSocket(javax.net.ssl.SSLSocket) OutputStream(java.io.OutputStream) SSLContext(javax.net.ssl.SSLContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) ALPN(org.eclipse.jetty.alpn.ALPN) BufferedReader(java.io.BufferedReader) List(java.util.List) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)33681 IOException (java.io.IOException)12617 ByteArrayInputStream (java.io.ByteArrayInputStream)7643 Test (org.junit.Test)7105 FileInputStream (java.io.FileInputStream)6956 File (java.io.File)5058 InputStreamReader (java.io.InputStreamReader)3045 URL (java.net.URL)3010 OutputStream (java.io.OutputStream)2893 BufferedInputStream (java.io.BufferedInputStream)2558 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2228 ArrayList (java.util.ArrayList)2193 FileOutputStream (java.io.FileOutputStream)2191 BufferedReader (java.io.BufferedReader)2039 Properties (java.util.Properties)1679 FileNotFoundException (java.io.FileNotFoundException)1503 HashMap (java.util.HashMap)1264 HttpURLConnection (java.net.HttpURLConnection)1144 Map (java.util.Map)866 Document (org.w3c.dom.Document)847