Examples of HttpContent


Examples of com.volantis.shared.net.url.http.HttpContent

                "",
                "<p>hello</p>"});

        final URLContentManager manager = createDefaultURLContentManager();
        final URL url = serverMock.getURL("/blah.txt?foo");
        HttpContent content = (HttpContent) manager.getURLContent(url, null, null);
        assertEquals("Content was received", "<p>hello</p>\n",
            toString(content.getInputStream()));
        assertEquals(200, content.getStatusCode());
        Map expectedHeaders = new HashMap();
        expectedHeaders.put("date", currentDate);
        expectedHeaders.put("content-type", "text/plain");
        expectedHeaders.put("cache-control", "public");
        expectedHeaders.put("etag", "\"aa\"");
        expectedHeaders.put("foo", "bar");
        boolean ageFound = false;
        for (Iterator iter = content.getHeaders(); iter.hasNext(); ) {
            final Header header = (Header) iter.next();
            final String name = header.getName().toLowerCase();
            if ("age".equals(name) && !ageFound) {
                // age must be at least 0
                assertTrue(Integer.parseInt(header.getValue()) >= 0);
                ageFound = true;
            } else {
                final String value =
                    (String) expectedHeaders.remove(name);
                assertEquals(value, header.getValue());
            }
        }
        assertTrue(ageFound);
        assertTrue(expectedHeaders.isEmpty());

        // second request should contain an If-None-Match validation header
        // response will indicate that content is not modified
        currentDate = RFC1123.format(new Date());
        serverMock.addTransaction(new String[]{
                "GET /blah.txt?foo HTTP/1.1",
                "If-None-Match: \"aa\"",
                UA_STRING,
                "Host: " + serverMock.getServerAddress()},
            new String[]{
                "HTTP/1.0 304 Not Modified",
                "Date: " + currentDate,
                "Foo: baz",
                ""});

        content = (HttpContent) manager.getURLContent(url, null, null);
        assertEquals("Content was not modified, cached entry is returned",
            "<p>hello</p>\n", toString(content.getInputStream()));
        assertEquals(200, content.getStatusCode());
        // original headers are kept, Date and Foo headers are updated
        expectedHeaders = new HashMap();
        expectedHeaders.put("date", currentDate);
        expectedHeaders.put("content-type", "text/plain");
        expectedHeaders.put("cache-control", "public");
        expectedHeaders.put("etag", "\"aa\"");
        expectedHeaders.put("foo", "baz");
        ageFound = false;
        for (Iterator iter = content.getHeaders(); iter.hasNext(); ) {
            final Header header = (Header) iter.next();
            final String name = header.getName().toLowerCase();
            if ("age".equals(name) && !ageFound) {
                // age must be at least 0
                assertTrue(Integer.parseInt(header.getValue()) >= 0);
View Full Code Here

Examples of com.volantis.shared.net.url.http.HttpContent

                "",
                "<p>hello</p>"});

        final URLContentManager manager = createDefaultURLContentManager();
        final URL url = serverMock.getURL("/blah.txt?foo");
        HttpContent content = (HttpContent) manager.getURLContent(url, null, null);
        assertEquals("Content was received", "<p>hello</p>\n",
            toString(content.getInputStream()));
        assertEquals(200, content.getStatusCode());
        Iterator cookiesIter = content.getCookies();
        assertTrue(cookiesIter.hasNext());
        final Cookie fooCookie = (Cookie) cookiesIter.next();
        assertFalse(cookiesIter.hasNext());
        assertEquals("foo", fooCookie.getName());
        assertEquals("bar", fooCookie.getValue());

        // second request should contain an If-None-Match validation header
        // response will indicate that content is not modified
        currentDate = RFC1123.format(new Date());
        serverMock.addTransaction(new String[]{
                "GET /blah.txt?foo HTTP/1.1",
                "If-None-Match: \"aa\"",
                UA_STRING,
                "Host: " + serverMock.getServerAddress()},
            new String[]{
                "HTTP/1.0 304 Not Modified",
                "Date: " + currentDate,
                "Set-Cookie: hello=world",
                ""});

        content = (HttpContent) manager.getURLContent(url, null, null);
        assertEquals("Content was not modified, cached entry is returned",
            "<p>hello</p>\n", toString(content.getInputStream()));
        assertEquals(200, content.getStatusCode());
        cookiesIter = content.getCookies();
        assertTrue(cookiesIter.hasNext());
        Cookie helloCookie = (Cookie) cookiesIter.next();
        assertFalse(cookiesIter.hasNext());
        assertEquals("hello", helloCookie.getName());
        assertEquals("world", helloCookie.getValue());


        // third request should contain an If-None-Match validation header
        // response will indicate that content is not modified
        currentDate = RFC1123.format(new Date());
        serverMock.addTransaction(new String[]{
                "GET /blah.txt?foo HTTP/1.1",
                "If-None-Match: \"aa\"",
                UA_STRING,
                "Host: " + serverMock.getServerAddress()},
            new String[]{
                "HTTP/1.0 304 Not Modified",
                "Date: " + currentDate,
                ""});

        content = (HttpContent) manager.getURLContent(url, null, null);
        assertEquals("Content was not modified, cached entry is returned",
            "<p>hello</p>\n", toString(content.getInputStream()));
        assertEquals(200, content.getStatusCode());
        cookiesIter = content.getCookies();
        assertTrue(cookiesIter.hasNext());
        helloCookie = (Cookie) cookiesIter.next();
        assertFalse(cookiesIter.hasNext());
        assertEquals("hello", helloCookie.getName());
        assertEquals("world", helloCookie.getValue());
View Full Code Here

Examples of com.volantis.shared.net.url.http.HttpContent

                "",
                "<p>hello</p>"});

        final URLContentManager manager = createDefaultURLContentManager();
        final URL url = serverMock.getURL("/blah.txt?foo");
        final HttpContent content =
            (HttpContent) manager.getURLContent(url, null, null);
        assertEquals("Content was received", "<p>hello</p>\n",
            toString(content.getInputStream()));
        assertEquals("HTTP/1.1", content.getHttpVersion());
        assertEquals(200, content.getStatusCode());
        final Map cookies = new HashMap();
        for (Iterator iter = content.getCookies(); iter.hasNext(); ) {
            final Cookie cookie = (Cookie) iter.next();
            cookies.put(cookie.getName(), cookie);
        }

        // we should have 3 cookies
View Full Code Here

Examples of http.content.HttpContent

     * Convert and parse input into the requested output, then write it.
     */
    String[] lines = req.split(CRLF);
    for (int i = 0; i < lines.length; i++) {
      if (lines[i].startsWith("GET"))
        new HttpContent(socket, lines[i]).write(out);
    }
    /**
     * Flush and close output stream.
     */
    in.close();
 
View Full Code Here

Examples of io.netty.handler.codec.http.HttpContent

            Attribute<HttpServerChannelHandler> attr = ctx.attr(SERVER_HANDLER_KEY);
            // store handler as attachment
            attr.set(handler);
            if (msg instanceof HttpContent) {
                // need to hold the reference of content
                HttpContent httpContent = (HttpContent) msg;
                httpContent.content().retain();
            }  
            handler.channelRead(ctx, request);
        } else {
            // this resource is not found, so send empty response back
            HttpResponse response = new DefaultHttpResponse(HTTP_1_1, NOT_FOUND);
View Full Code Here

Examples of io.netty.handler.codec.http.HttpContent

            Attribute<HttpServerChannelHandler> attr = ctx.attr(SERVER_HANDLER_KEY);
            // store handler as attachment
            attr.set(handler);
            if (msg instanceof HttpContent) {
                // need to hold the reference of content
                HttpContent httpContent = (HttpContent) msg;
                httpContent.content().retain();
            }  
            handler.channelRead(ctx, request);
        } else {
            // this resource is not found, so send empty response back
            HttpResponse response = new DefaultHttpResponse(HTTP_1_1, NOT_FOUND);
View Full Code Here

Examples of io.netty.handler.codec.http.HttpContent

        final HttpResponse response = ch.readOutbound();
        assertThat(response.getStatus(), equalTo(OK));
        assertThat(response.headers().get(CONTENT_TYPE), equalTo(Transports.CONTENT_TYPE_HTML));
        verifyNoCacheHeaders(response);

        final HttpContent headerChunk = ch.readOutbound();
        assertThat(headerChunk.content().readableBytes(), is(greaterThan(1024)));
        final String header = headerChunk.content().toString(UTF_8);
        assertThat(header, containsString("var c = parent.callback"));
        final HttpContent chunk = ch.readOutbound();
        assertThat(chunk.content().toString(UTF_8), equalTo("<script>\np(\"o\");\n</script>\r\n"));

        ch.write(new MessageFrame("x"));
        final HttpContent messageContent = ch.readOutbound();
        assertThat(messageContent.content().toString(UTF_8), equalTo("<script>\np(\"a[\\\"x\\\"]\");\n</script>\r\n"));
    }
View Full Code Here

Examples of io.netty.handler.codec.http.HttpContent

            super.write(ctx, rxResponse.getNettyResponse(), promise);
        } else if (ByteBuf.class.isAssignableFrom(recievedMsgClass)) {
            eventsSubject.onEvent(HttpServerMetricsEvent.RESPONSE_CONTENT_WRITE_START);
            addWriteCompleteEvents(promise, startTimeMillis, HttpServerMetricsEvent.RESPONSE_CONTENT_WRITE_SUCCESS,
                                   HttpServerMetricsEvent.RESPONSE_CONTENT_WRITE_FAILED);
            HttpContent content = new DefaultHttpContent((ByteBuf) msg);
            super.write(ctx, content, promise);
        } else {
            super.write(ctx, msg, promise); // pass through, since we do not understand this message.
        }
    }
View Full Code Here

Examples of io.netty.handler.codec.http.HttpContent

            }
            HttpHeaders.setTransferEncodingChunked(request);
            request.data().clear();
        } else {
            // get the only one body and set it to the request
            HttpContent chunk = nextChunk();
            request.data().clear().writeBytes(chunk.data());
        }
        return request;
    }
View Full Code Here

Examples of io.netty.handler.codec.http.HttpContent

        }
        // size > 0
        if (currentData != null) {
            // continue to read data
            if (isMultipart) {
                HttpContent chunk = encodeNextChunkMultipart(size);
                if (chunk != null) {
                    return chunk;
                }
            } else {
                HttpContent chunk = encodeNextChunkUrlEncoded(size);
                if (chunk != null) {
                    // NextChunk Url from currentData
                    return chunk;
                }
            }
            size = HttpPostBodyUtil.chunkSize - currentBuffer.readableBytes();
        }
        if (!iterator.hasNext()) {
            isLastChunk = true;
            // NextChunk as last non empty from buffer
            buffer = currentBuffer;
            currentBuffer = null;
            return new DefaultHttpContent(buffer);
        }
        while (size > 0 && iterator.hasNext()) {
            currentData = iterator.next();
            HttpContent chunk;
            if (isMultipart) {
                chunk = encodeNextChunkMultipart(size);
            } else {
                chunk = encodeNextChunkUrlEncoded(size);
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.