Search in sources :

Example 36 with Resource

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

the class HttpOutputTest method testAsyncWriteSmall.

@Test
public void testAsyncWriteSmall() throws Exception {
    final Resource big = Resource.newClassPathResource("simple/big.txt");
    _handler._writeLengthIfKnown = false;
    _handler._content = BufferUtil.toBuffer(big, false);
    _handler._arrayBuffer = new byte[8];
    _handler._async = true;
    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 37 with Resource

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

the class HttpOutputTest method testWriteMed.

@Test
public void testWriteMed() throws Exception {
    final Resource big = Resource.newClassPathResource("simple/big.txt");
    _handler._writeLengthIfKnown = false;
    _handler._content = BufferUtil.toBuffer(big, false);
    _handler._arrayBuffer = new byte[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 38 with Resource

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

the class HttpOutputTest method testSendChannelBigChunked.

@Test
public void testSendChannelBigChunked() throws Exception {
    Resource big = Resource.newClassPathResource("simple/big.txt");
    final ReadableByteChannel channel = big.getReadableByteChannel();
    _handler._contentChannel = new ReadableByteChannel() {

        @Override
        public boolean isOpen() {
            return channel.isOpen();
        }

        @Override
        public void close() throws IOException {
            channel.close();
        }

        @Override
        public int read(ByteBuffer dst) throws IOException {
            int filled = 0;
            if (dst.position() == 0 && dst.limit() > 2000) {
                int limit = dst.limit();
                dst.limit(2000);
                filled = channel.read(dst);
                dst.limit(limit);
            } else
                filled = channel.read(dst);
            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 : ReadableByteChannel(java.nio.channels.ReadableByteChannel) Resource(org.eclipse.jetty.util.resource.Resource) IOException(java.io.IOException) Matchers.containsString(org.hamcrest.Matchers.containsString) ByteBuffer(java.nio.ByteBuffer) LocalEndPoint(org.eclipse.jetty.server.LocalConnector.LocalEndPoint) Test(org.junit.Test)

Example 39 with Resource

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

the class HttpOutputTest method testAsyncWriteBufferLargeDirect.

@Test
public void testAsyncWriteBufferLargeDirect() throws Exception {
    final Resource big = Resource.newClassPathResource("simple/big.txt");
    _handler._writeLengthIfKnown = false;
    _handler._content = BufferUtil.toBuffer(big, true);
    _handler._byteBuffer = BufferUtil.allocateDirect(8192);
    _handler._async = true;
    String response = _connector.getResponses("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 40 with Resource

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

the class HttpOutputTest method testAsyncWriteBufferSmall.

@Test
public void testAsyncWriteBufferSmall() throws Exception {
    final Resource big = Resource.newClassPathResource("simple/big.txt");
    _handler._writeLengthIfKnown = false;
    _handler._content = BufferUtil.toBuffer(big, false);
    _handler._byteBuffer = BufferUtil.allocate(8);
    _handler._async = true;
    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