Package org.mortbay.io

Examples of org.mortbay.io.ByteArrayBuffer


    public void testBigPostWithContentExchange() throws Exception
    {  
        int size =32;
        ContentExchange httpExchange=new ContentExchange();

        Buffer babuf = new ByteArrayBuffer(size*36*1024);
        Buffer niobuf = new DirectNIOBuffer(size*36*1024);

        byte[] bytes="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".getBytes();

        for (int i=0;i<size*1024;i++)
        {
            babuf.put(bytes);
            niobuf.put(bytes);
        }
       
        httpExchange.setURL(_scheme+"localhost:"+_port+"/");
        httpExchange.setMethod(HttpMethods.POST);
        httpExchange.setRequestContentType("application/data");
        httpExchange.setRequestContent(babuf);
       
        _httpClient.send(httpExchange);
        int status = httpExchange.waitForDone();
        String result=httpExchange.getResponseContent();
        assertEquals(babuf.length(),result.length());
        assertEquals(HttpExchange.STATUS_COMPLETED, status);

        httpExchange.reset();
        httpExchange.setURL(_scheme+"localhost:"+_port+"/");
        httpExchange.setMethod(HttpMethods.POST);
View Full Code Here


        String srvUrl = "http://127.0.0.1:" + _server.getConnectors()[0].getLocalPort() + "/test";

        ContentExchange ex = new ContentExchange();
        ex.setMethod(HttpMethods.POST);
        ex.setURL(srvUrl);
        ex.setRequestContent(new ByteArrayBuffer(__message,"UTF-8"));

        _received=null;
        client.send(ex);
        ex.waitForDone();
View Full Code Here

        _address=address;
        _ssl=ssl;
        _maxConnections=maxConnections;
        String addressString = address.getHost();
        if (address.getPort() != (_ssl ? 443 : 80)) addressString += ":" + address.getPort();
        _hostHeader = new ByteArrayBuffer(addressString);
    }
View Full Code Here

                buf=new IndirectNIOBuffer(size);
            return buf;
        }
        else
        {
            return new ByteArrayBuffer(size);
        }
    }
View Full Code Here

    private Buffer _authorization;
   
    public ProxyAuthorization(String username,String password) throws IOException
    {
        String authenticationString = "Basic " + B64Code.encode( username + ":" + password, StringUtil.__ISO_8859_1);
        _authorization= new ByteArrayBuffer(authenticationString);
    }
View Full Code Here

    {

        CustomContentExchange httpExchange = new CustomContentExchange();
        httpExchange.setURL(_scheme + "localhost:" + _port);
        httpExchange.setMethod(HttpMethods.POST);
        httpExchange.setRequestContent(new ByteArrayBuffer("<h1>??</h1>"));

        // let's use the default timeout - the one set on the HttpClient
        // (500 ms)
        _httpClient.send(httpExchange);

        httpExchange.getDoneLatch().await(900,TimeUnit.MILLISECONDS);
        // we should get a timeout - the server sleeps for 700 ms
        Assert.assertTrue(httpExchange.isTimeoutOccurred());
        Assert.assertFalse(httpExchange.isResponseReceived());

        // let's do it again - with a custom timeout
        httpExchange = new CustomContentExchange();
        httpExchange.setURL(_scheme + "localhost:" + _port);
        httpExchange.setMethod(HttpMethods.POST);
        httpExchange.setRequestContent(new ByteArrayBuffer("<h1>??</h1>"));
        httpExchange.setTimeout(500);

        // let's use a custom timeout - 500 ms (the default one) + 500 ms
        // delay = 1000 ms
        _httpClient.send(httpExchange);
View Full Code Here

            "Content-Type: application/x-www-form-urlencoded; charset=utf-16\r\n"+
            "Content-Length: "+content_utf_16.length+"\r\n"+
            "Connection: close\r\n"+
            "\r\n";
       
        ByteArrayBuffer out = new ByteArrayBuffer(4096);
        out.put(request_iso_8859_1.getBytes("iso8859-1"));
        out.put(content_iso_8859_1);
        out.put(request_utf_8.getBytes("iso8859-1"));
        out.put(content_utf_8);
        out.put(request_utf_16.getBytes("iso8859-1"));
        out.put(content_utf_16);

        ByteArrayBuffer responses = tester.getResponses(out);
       
        String expected=
            "HTTP/1.1 200 OK\r\n"+
            "Content-Type: text/html; charset=iso-8859-1\r\n"+
            "Content-Length: 21\r\n"+
            "\r\n"+
            "<h1>Test Servlet</h1>"+
            "HTTP/1.1 200 OK\r\n"+
            "Content-Type: text/html; charset=iso-8859-1\r\n"+
            "Content-Length: 21\r\n"+
            "\r\n"+
            "<h1>Test Servlet</h1>"+
            "HTTP/1.1 200 OK\r\n"+
            "Content-Type: text/html; charset=iso-8859-1\r\n"+
            "Connection: close\r\n"+
            "\r\n"+
            "<h1>Test Servlet</h1>";
       
        assertEquals(expected,responses.toString());
    }
View Full Code Here

            _buffer.put((byte) 0x4);
            addInt(_status);
            if (_reason == null)
                _reason = getReasonBuffer(_status);
            if (_reason == null)
                _reason = new ByteArrayBuffer(TypeUtil.toString(_status));
            addBuffer(_reason);

            if (_status == 100 || _status == 204 || _status == 304)
            {
                _noContent = true;
View Full Code Here

    private Buffer _authorization;
   
    public BasicAuthorization(Realm realm) throws IOException
    {
        String authenticationString = "Basic " + B64Code.encode( realm.getPrincipal() + ":" + realm.getCredentials(), StringUtil.__ISO_8859_1);
        _authorization= new ByteArrayBuffer(authenticationString);
    }
View Full Code Here

                            if (_cached!=null || _tok0.length() > 0 || _tok1.length() > 0 || _multiLineValue != null)
                            {
                               
                                Buffer header=_cached!=null?_cached:HttpHeaders.CACHE.lookup(_tok0);
                                _cached=null;
                                Buffer value=_multiLineValue == null ? (Buffer) _tok1 : (Buffer) new ByteArrayBuffer(_multiLineValue);
                               
                                int ho=HttpHeaders.CACHE.getOrdinal(header);
                                if (ho >= 0)
                                {
                                    int vo=-1;
View Full Code Here

TOP

Related Classes of org.mortbay.io.ByteArrayBuffer

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.