Search in sources :

Example 31 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class HttpOutputTest method testWriteBufferMed.

@Test
public void testWriteBufferMed() throws Exception {
    final Resource big = Resource.newClassPathResource("simple/big.txt");
    _handler._writeLengthIfKnown = false;
    _handler._content = BufferUtil.toBuffer(big, false);
    _handler._byteBuffer = BufferUtil.allocate(4000);
    String response = _connector.getResponse("GET / HTTP/1.0\nHost: localhost:80\n\n");
    assertThat(response, containsString("HTTP/1.1 200 OK"));
    assertThat(response, Matchers.not(containsString("Content-Length")));
    assertThat(response, endsWith(toUTF8String(big)));
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 32 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class HttpOutputTest method testSendInputStreamBig.

@Test
public void testSendInputStreamBig() throws Exception {
    Resource big = Resource.newClassPathResource("simple/big.txt");
    _handler._contentInputStream = big.getInputStream();
    String response = _connector.getResponse("GET / HTTP/1.0\nHost: localhost:80\n\n");
    assertThat(response, containsString("HTTP/1.1 200 OK"));
    assertThat(response, Matchers.not(containsString("Content-Length")));
    assertThat(response, endsWith(toUTF8String(big)));
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 33 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class HttpOutputTest method testSendInputStreamBigChunked.

@Test
public void testSendInputStreamBigChunked() throws Exception {
    Resource big = Resource.newClassPathResource("simple/big.txt");
    _handler._contentInputStream = new FilterInputStream(big.getInputStream()) {

        @Override
        public int read(byte[] b, int off, int len) throws IOException {
            int filled = super.read(b, off, len > 2000 ? 2000 : len);
            return filled;
        }
    };
    LocalEndPoint endp = _connector.executeRequest("GET / HTTP/1.1\nHost: localhost:80\n\n" + "GET / HTTP/1.1\nHost: localhost:80\nConnection: close\n\n");
    String response = endp.getResponse();
    assertThat(response, containsString("HTTP/1.1 200 OK"));
    assertThat(response, containsString("Transfer-Encoding: chunked"));
    assertThat(response, containsString("1\tThis is a big file"));
    assertThat(response, containsString("400\tThis is a big file"));
    assertThat(response, containsString("\r\n0\r\n"));
    response = endp.getResponse();
    assertThat(response, containsString("HTTP/1.1 200 OK"));
    assertThat(response, containsString("Connection: close"));
}
Also used : FilterInputStream(java.io.FilterInputStream) Resource(org.eclipse.jetty.util.resource.Resource) IOException(java.io.IOException) Matchers.containsString(org.hamcrest.Matchers.containsString) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) Test(org.junit.Test)

Example 34 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class HttpOutputTest method testWriteByte.

@Test
public void testWriteByte() throws Exception {
    final Resource big = Resource.newClassPathResource("simple/big.txt");
    _handler._writeLengthIfKnown = false;
    _handler._content = BufferUtil.toBuffer(big, false);
    _handler._arrayBuffer = new byte[1];
    String response = _connector.getResponse("GET / HTTP/1.0\nHost: localhost:80\n\n");
    assertThat(response, containsString("HTTP/1.1 200 OK"));
    assertThat(response, Matchers.not(containsString("Content-Length")));
    assertThat(response, endsWith(toUTF8String(big)));
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 35 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class HttpOutputTest method testSendChannelBig.

@Test
public void testSendChannelBig() throws Exception {
    Resource big = Resource.newClassPathResource("simple/big.txt");
    _handler._contentChannel = big.getReadableByteChannel();
    String response = _connector.getResponse("GET / HTTP/1.0\nHost: localhost:80\n\n");
    assertThat(response, containsString("HTTP/1.1 200 OK"));
    assertThat(response, Matchers.not(containsString("Content-Length")));
    assertThat(response, endsWith(toUTF8String(big)));
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

Resource (org.eclipse.jetty.util.resource.Resource)196 Test (org.junit.Test)79 File (java.io.File)46 URL (java.net.URL)39 ArrayList (java.util.ArrayList)38 Matchers.containsString (org.hamcrest.Matchers.containsString)31 IOException (java.io.IOException)28 ResourceCollection (org.eclipse.jetty.util.resource.ResourceCollection)18 JarResource (org.eclipse.jetty.util.resource.JarResource)16 XmlConfiguration (org.eclipse.jetty.xml.XmlConfiguration)16 Server (org.eclipse.jetty.server.Server)13 HashSet (java.util.HashSet)12 InputStream (java.io.InputStream)9 HashMap (java.util.HashMap)9 URI (java.net.URI)8 MalformedURLException (java.net.MalformedURLException)7 StringTokenizer (java.util.StringTokenizer)7 URISyntaxException (java.net.URISyntaxException)6 Properties (java.util.Properties)6 Set (java.util.Set)6