Examples of ByteArrayEndPoint


Examples of org.eclipse.jetty.io.ByteArrayEndPoint

        public void run()
        {
            try
            {
                ByteArrayEndPoint endPoint = new ByteArrayEndPoint(_requestsBuffer.asArray(), 1024)
                {
                    @Override
                    public void setConnection(Connection connection)
                    {
                        if (getConnection()!=null && connection!=getConnection())
                            connectionUpgraded(getConnection(),connection);
                        super.setConnection(connection);
                    }
                };

                endPoint.setGrowOutput(true);
                AbstractHttpConnection connection = new BlockingHttpConnection(LocalConnector.this, endPoint, getServer());
                endPoint.setConnection(connection);
                connectionOpened(connection);

                boolean leaveOpen = _keepOpen;
                try
                {
                    while (endPoint.getIn().length() > 0 && endPoint.isOpen())
                    {
                        while (true)
                        {
                            final Connection con = endPoint.getConnection();
                            final Connection next = con.handle();
                            if (next!=con)
                            { 
                                endPoint.setConnection(next);
                                continue;
                            }
                            break;
                        }
                    }
                }
                catch (IOException x)
                {
                    LOG.debug(x);
                    leaveOpen = false;
                }
                catch (Exception x)
                {
                    LOG.warn(x);
                    leaveOpen = false;
                }
                finally
                {
                    if (!leaveOpen)
                        connectionClosed(connection);
                    _responsesBuffer = endPoint.getOut();
                }
            }
            finally
            {
                if (_latch != null)
View Full Code Here

Examples of org.mortbay.io.ByteArrayEndPoint

        throws Exception
    {
        Buffer bb=new ByteArrayBuffer(8096);
        Buffer sb=new ByteArrayBuffer(1500);
        HttpFields fields = new HttpFields();
        ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096);
        HttpGenerator hb = new HttpGenerator(new SimpleBuffers(new Buffer[]{sb,bb}),endp, sb.capacity(), bb.capacity());
        Handler handler = new Handler();
        HttpParser parser=null;
       
        // For HTTP version
        for (int v=9;v<=11;v++)
        {
            // For each test result
            for (int r=0;r<tr.length;r++)
            {
                // chunks = 1 to 3
                for (int chunks=1;chunks<=6;chunks++)
                {
                    // For none, keep-alive, close
                    for (int c=0;c<connect.length;c++)
                    {
                        String t="v="+v+",r="+r+",chunks="+chunks+",c="+c+",tr="+tr[r];
                        // System.err.println(t);
                       
                        hb.reset(true);
                        endp.reset();
                        fields.clear();

                        // System.out.println("TEST: "+t);
                       
                        try
                        {
                            tr[r].build(v,hb,connect[c],null,chunks, fields);
                        }
                        catch(IllegalStateException e)
                        {
                            if (v<10 || v==10 && chunks>2)
                                continue;
                            System.err.println(t);
                            throw e;
                        }
                        String request=endp.getOut().toString();
                        // System.out.println(request+(hb.isPersistent()?"...\n":"---\n"));
                       
                        assertTrue(t,hb.isPersistent());
                       
                        if (v==9)
View Full Code Here

Examples of org.mortbay.io.ByteArrayEndPoint

      throws Exception
    {
        Buffer bb=new ByteArrayBuffer(8096);
        Buffer sb=new ByteArrayBuffer(1500);
        HttpFields fields = new HttpFields();
        ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096);
        HttpGenerator hb = new HttpGenerator(new SimpleBuffers(new Buffer[]{sb,bb}),endp, sb.capacity(), bb.capacity());
        Handler handler = new Handler();
        HttpParser parser=null;
       
        // For HTTP version
        for (int v=9;v<=11;v++)
        {
            // For each test result
            for (int r=0;r<tr.length;r++)
            {
                // chunks = 1 to 3
                for (int chunks=1;chunks<=6;chunks++)
                {
                    // For none, keep-alive, close
                    for (int c=0;c<(v==11?connect.length:(connect.length-1));c++)
                    {
                       
                        String t="v="+v+",r="+r+",chunks="+chunks+",connect="+connect[c]+",tr="+tr[r];
                        // System.err.println(t);
                       
                        hb.reset(true);
                        endp.reset();
                        fields.clear();
                       
                        tr[r].build(v,hb,"OK\r\nTest",connect[c],null,chunks, fields);
                        String response=endp.getOut().toString();
                        // System.out.println("RESPONSE: "+t+"\n"+response+(hb.isPersistent()?"...\n":"---\n"));
                       
                        if (v==9)
                        {
                            assertFalse(t,hb.isPersistent());
View Full Code Here

Examples of org.mortbay.io.ByteArrayEndPoint

        throws Exception
    {
        Buffer sb=new ByteArrayBuffer(1500);
        Buffer bb=new ByteArrayBuffer(8096);
        HttpFields fields = new HttpFields();
        ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096);
        HttpGenerator hb = new HttpGenerator(new SimpleBuffers(new Buffer[]{sb,bb}),endp, sb.capacity(), bb.capacity());

        hb.setResponse(200,"OK");
       
        Output output = new Output(hb,10000);
        OutputWriter writer = new OutputWriter(output);
        writer.setCharacterEncoding(StringUtil.__UTF8);
       
        char[] chars = new char[1024];
        for (int i=0;i<chars.length;i++)
            chars[i]=(char)('0'+(i%10));
        chars[0]='\u0553';
        writer.write(chars);
       
        hb.completeHeader(fields,true);
        hb.flush();
        String response = new String(endp.getOut().asArray(),StringUtil.__UTF8);
        assertTrue(response.startsWith("HTTP/1.1 200 OK\r\nContent-Length: 1025\r\n\r\n\u05531234567890"));
               
    }   
View Full Code Here

Examples of org.mortbay.io.ByteArrayEndPoint

    /* ------------------------------------------------------------ */
    public void reopen()
    {
        _in.clear();
        _out.clear();
        _endp = new ByteArrayEndPoint();
        _endp.setIn(_in);
        _endp.setOut(_out);
        _endp.setGrowOutput(true);
        _accepting=false;
    }
View Full Code Here

Examples of org.mortbay.io.ByteArrayEndPoint

    public void doStart()
        throws Exception
    {  
        _in=new ByteArrayBuffer(8192);
        _out=new ByteArrayBuffer(8192);
        _endp = new ByteArrayEndPoint();
        _endp.setIn(_in);
        _endp.setOut(_out);
        _endp.setGrowOutput(true);
        _accepting=false;
       
View Full Code Here

Examples of org.mortbay.io.ByteArrayEndPoint

    public void testContentLength()
        throws Exception
    {
        Buffer bb=new ByteArrayBuffer(8096);
        Buffer sb=new ByteArrayBuffer(1500);
        ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096);
        HttpGenerator generator = new HttpGenerator(new SimpleBuffers(new Buffer[]{sb,bb}),endp, sb.capacity(), bb.capacity());
       
        generator.setRequest("GET","/usr");
       
        HttpFields fields = new HttpFields();
        fields.add("Header","Value");
        fields.add("Content-Type","text/plain");
       
        String content = "The quick brown fox jumped over the lazy dog";
        fields.addLongField("Content-Length",content.length());
       
        generator.completeHeader(fields,false);
       
        generator.addContent(new ByteArrayBuffer(content),true);
        generator.flush();
        generator.complete();
        generator.flush();
       
        String result=endp.getOut().toString();
        result=StringUtil.replace(result,"\r\n","|");
        result=StringUtil.replace(result,"\r","|");
        result=StringUtil.replace(result,"\n","|");
       
        assertEquals("GET /usr HTTP/1.1|Header: Value|Content-Type: text/plain|Content-Length: 44||"+content,result);
View Full Code Here

Examples of org.mortbay.io.ByteArrayEndPoint

    public void testAutoContentLength()
        throws Exception
    {
        Buffer bb=new ByteArrayBuffer(8096);
        Buffer sb=new ByteArrayBuffer(1500);
        ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096);
        HttpGenerator generator = new HttpGenerator(new SimpleBuffers(new Buffer[]{sb,bb}),endp, sb.capacity(), bb.capacity());
       
        generator.setRequest("GET","/usr");
       
        HttpFields fields = new HttpFields();
        fields.add("Header","Value");
        fields.add("Content-Type","text/plain");
       
        String content = "The quick brown fox jumped over the lazy dog";

        generator.addContent(new ByteArrayBuffer(content),true);
        generator.completeHeader(fields,true);
       
        generator.flush();
        generator.complete();
        generator.flush();
       
        String result=endp.getOut().toString();
        result=StringUtil.replace(result,"\r\n","|");
        result=StringUtil.replace(result,"\r","|");
        result=StringUtil.replace(result,"\n","|");
        assertEquals("GET /usr HTTP/1.1|Header: Value|Content-Type: text/plain|Content-Length: 44||"+content,result);
    }
View Full Code Here

Examples of org.mortbay.io.ByteArrayEndPoint

    public void testChunked()
        throws Exception
    {
        Buffer bb=new ByteArrayBuffer(8096);
        Buffer sb=new ByteArrayBuffer(1500);
        ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096);
        HttpGenerator generator = new HttpGenerator(new SimpleBuffers(new Buffer[]{sb,bb}),endp, sb.capacity(), bb.capacity());
       
        generator.setRequest("GET","/usr");
       
        HttpFields fields = new HttpFields();
        fields.add("Header","Value");
        fields.add("Content-Type","text/plain");
       
        String content = "The quick brown fox jumped over the lazy dog";

        generator.completeHeader(fields,false);
       
        generator.addContent(new ByteArrayBuffer(content),false);
        generator.flush();
        generator.complete();
        generator.flush();

        String result=endp.getOut().toString();
        result=StringUtil.replace(result,"\r\n","|");
        result=StringUtil.replace(result,"\r","|");
        result=StringUtil.replace(result,"\n","|");
        assertEquals("GET /usr HTTP/1.1|Header: Value|Content-Type: text/plain|Transfer-Encoding: chunked||2C|"+content+"|0||",result);
    }
View Full Code Here

Examples of org.mortbay.io.ByteArrayEndPoint

        throws Exception
    {
        Buffer bb=new ByteArrayBuffer(8096);
        Buffer sb=new ByteArrayBuffer(1500);
        HttpFields fields = new HttpFields();
        ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096);
        HttpGenerator hb = new HttpGenerator(new SimpleBuffers(new Buffer[]{sb,bb}),endp, sb.capacity(), bb.capacity());
        Handler handler = new Handler();
        HttpParser parser=null;
       
        // For HTTP version
        for (int v=9;v<=11;v++)
        {
            // For each test result
            for (int r=0;r<tr.length;r++)
            {
                // chunks = 1 to 3
                for (int chunks=1;chunks<=6;chunks++)
                {
                    // For none, keep-alive, close
                    for (int c=0;c<connect.length;c++)
                    {
                        String t="v="+v+",r="+r+",chunks="+chunks+",c="+c+",tr="+tr[r];
                        // System.err.println(t);
                       
                        hb.reset(true);
                        endp.reset();
                        fields.clear();

                        // System.out.println("TEST: "+t);
                       
                        try
                        {
                            tr[r].build(v,hb,connect[c],null,chunks, fields);
                        }
                        catch(IllegalStateException e)
                        {
                            if (v<10 || v==10 && chunks>2)
                                continue;
                            System.err.println(t);
                            throw e;
                        }
                        String request=endp.getOut().toString();
                        // System.out.println(request+(hb.isPersistent()?"...\n":"---\n"));
                       
                        assertTrue(t,hb.isPersistent());
                       
                        if (v==9)
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.