Package org.apache.tomcat.lite.io

Examples of org.apache.tomcat.lite.io.IOBuffer


            mOutBuffer = sc;
        }

        @Override
        public void handleReceived(IOChannel ch) throws IOException {
            IOBuffer inBuffer = ch.getIn();
            IOChannel outBuffer = mOutBuffer;
            if (outBuffer == null &&
                    ch instanceof HttpChannel) {
                outBuffer =
                    (IOChannel) ((HttpChannel)ch).getRequest().getAttribute("P");
            }
            // body.
            while (true) {
                if (outBuffer == null || outBuffer.getOut() == null) {
                    return;
                }
                if (outBuffer.getOut().isAppendClosed()) {
                    return;
                }

                ByteBuffer bb = outBuffer.getOut().getWriteBuffer();
                int rd = inBuffer.read(bb);
                outBuffer.getOut().releaseWriteBuffer(rd);

                if (rd == 0) {
                    outBuffer.startSending();
                    return;
View Full Code Here


      }


    public StaticContentService setData(CharSequence data) {
      try {
          IOBuffer tmp = new IOBuffer(null);
          tmp.append(data);
          mb = tmp.readAll(null);
      } catch (IOException e) {
      }
      return this;
    }
View Full Code Here

    public void testClose() throws IOException {
        net.getIn().append(POST);
        net.getIn().close();

        IOBuffer receiveBody = http.receiveBody;
        IOBuffer appData = receiveBody;
        BBuffer res = BBuffer.allocate(1000);
        appData.readAll(res);

        assertEquals(res.toString(), "1234");
        assertFalse(((Http11Connection)http.conn).keepAlive());

        http.sendBody.queue(res);
View Full Code Here

    public void service(HttpRequest req, HttpResponse res) throws IOException {
        HttpChannel sproc = req.getHttpChannel();
        res.setStatus(200);
        res.setContentType(contentType);

        IOBuffer tmp = new IOBuffer(null);
        Http11Connection.serialize(req, tmp);

        sproc.getOut().append("REQ HEAD:\n");
        sproc.getOut().append(tmp.readAll(null));
        IOBuffer reqBuf = sproc.getOut();

        reqBuf.append("\nCONTENT_LENGTH:")
            .append(Long.toString(req.getContentLength()))
            .append("\n");
//
//        sproc.release();
    }
View Full Code Here

        }


        @Override
        public void handleReceived(IOChannel net) throws IOException {
            IOBuffer ch = net.getIn();
            //SelectorChannel ch = (SelectorChannel) ioch;
                if (!headReceived) {
                    int rd = ch.read(headBuffer);
                    if (rd == 0) {
                        return;
                    }
                    if (rd == -1) {
                        ch.close();
                    }

                    rd = parseHead();
                    if (rd < 0) {
                        return; // need more
                    }
                    if (rd == 5) {
                        headResBuffer.clear();
                        headResBuffer.put((byte) 5);
                        headResBuffer.put((byte) 0);
                        headResBuffer.flip();
                        net.getOut().queue(headResBuffer);
                        net.startSending();
                        headReceived = true;
                        headBuffer.clear();
                        return;
                    } else {
                        headReceived = true;
                        head5Received = true;
                        startClientConnection();
                    }
                }

                if (!head5Received) {
                    int rd = ch.read(headBuffer);
                    if (rd == 0) {
                        return;
                    }
                    if (rd == -1) {
                        ch.close();
                    }

                    rd = parseHead5_2();
                    if (rd < 0) {
                        return; // need more
View Full Code Here

    // Initial frame generated by Chrome
    public void testParse() throws IOException {
            InputStream is =
            getClass().getClassLoader().getResourceAsStream("org/apache/tomcat/lite/http/spdyreq0.bin");

        IOBuffer iob = new IOBuffer();
        iob.append(is);

        SpdyConnection con = new SpdyConnection(memSpdyCon, new RemoteServer());

        // By default it has a dispatcher buit-in
        con.serverMode = true;
View Full Code Here

    // Initial frame generated by Chrome
    public void testParseCompressed() throws IOException {
        InputStream is =
            getClass().getClassLoader().getResourceAsStream("org/apache/tomcat/lite/http/spdyreqCompressed.bin");

        IOBuffer iob = new IOBuffer();
        iob.append(is);

        SpdyConnection con = new SpdyConnection(memSpdyCon, new RemoteServer());

        // By default it has a dispatcher buit-in
        con.serverMode = true;
View Full Code Here

    }

    // Does int parsing works ?
    public void testLargeInt() throws Exception {

        IOBuffer iob = new IOBuffer();
        iob.append(0x80);
        iob.append(0x01);
        iob.append(0xFF);
        iob.append(0xFF);

        iob.append(0xFF);
        iob.append(0xFF);
        iob.append(0xFF);
        iob.append(0xFF);

        SpdyConnection con = new SpdyConnection(memSpdyCon, new RemoteServer());
        con.dataReceived(iob);
        assertEquals(1, con.currentInFrame.version);
        assertEquals(0xFFFF, con.currentInFrame.type);
View Full Code Here

    }

    // Does int parsing works ?
    public void testBad() throws Exception {

            IOBuffer iob = new IOBuffer();
            iob.append(0xFF);
            iob.append(0xFF);
            iob.append(0xFF);
            iob.append(0xFF);

            iob.append(0xFF);
            iob.append(0xFF);
            iob.append(0xFF);
            iob.append(0xFF);

            SpdyConnection con = new SpdyConnection(memSpdyCon, new RemoteServer());
            con.dataReceived(iob);

            assertEquals(1, con.streamErrors.get());
View Full Code Here

                if (checkHttpChannel() == null) {
                    return;
                }
            }

            IOBuffer receiveBody = activeHttp.receiveBody;

            if (!headersReceived) {
                headRecvBuf.wrapTo(headW);
                parseMessage(activeHttp, headW);
                // Part of parseMessage we can switch the protocol
                if (switchedProtocol != null) {
                    return;
                }

                if (serverMode && activeHttp.httpReq.decodedUri.remaining() == 0) {
                    abort(activeHttp, "Invalid url");
                }

                headersReceived = true;
                // Send header callbacks - we process any incoming data
                // first, so callbacks have more info
                trace("Send headers received callback " + activeHttp.httpService);
                activeHttp.handleHeadersReceived(activeHttp.inMessage);
            }

            // any remaining data will be processed as part of the
            // body - or left in the channel until endSendReceive()

            if (!bodyReceived) {
                // Will close receiveBody when it consummed enough
                rawDataReceived(activeHttp, receiveBody, net.getIn());
                // Did we process anything ?
                if (receiveBody.getBufferCount() > 0) {
                    activeHttp.sendHandleReceivedCallback(); // callback
                }
            }
            // Receive has marked the body as closed
            if (receiveBody.isAppendClosed()) {
                bodyReceived = true;
                activeHttp.handleEndReceive();
            }

View Full Code Here

TOP

Related Classes of org.apache.tomcat.lite.io.IOBuffer

Copyright © 2018 www.massapicom. 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.