Package com.volantis.mcs.utilities

Examples of com.volantis.mcs.utilities.HttpClient


            requestHeaders.add(hostHeader);
            if( characterEncoding != null ) {
                requestHeaders.add( "Accept-Charset: " + characterEncoding );
            }

            HttpClient client = new HttpClient( messageURL, requestHeaders );

            HttpResponseHeader responseHeaders = client.getResponseHeaders();

            if( responseHeaders.getErrorCode() == 200 ) {

                // read in message from URL
                InputStreamReader isr =
                        (InputStreamReader)client.getInputStreamReader();
                String encoding = isr.getEncoding();

                StringBuffer bodyContent = new StringBuffer();

                char[] line = new char[1024];
View Full Code Here


    }

    /** Test creation of an HttpClient and call it by setting parameters */
    public void testSetByMethod() {
        try {
            HttpClient client = new HttpClient();
            client.setHost( "localhost" );
            client.setPort( server.getPort() );
            client.setUri( "/volantis/wibble/file.html" );
            client.setRequestHeaders( headers );
            client.connect();

            StringBuffer response = new StringBuffer();
            BufferedReader resp = client.getBufferedReader();
            String line;
            while( ( line = resp.readLine() ) != null ) {
                response.append( line );
            }
            assertEquals( expectedHTML.toString(), response.toString() );
View Full Code Here

        }
    }
   
    public void testSetByParameters() {
        try {
            HttpClient client = new HttpClient( "localhost", server.getPort(),
                                "/volantis/wibble/file.html", headers );

            StringBuffer response = new StringBuffer();
            BufferedReader resp = client.getBufferedReader();
            String line;
            while( ( line = resp.readLine() ) != null ) {
                response.append( line );
            }
            assertEquals( expectedHTML.toString(), response.toString() );       
View Full Code Here

        }
    }
   
    public void testSetByURL() {
        try {
            HttpClient client = new HttpClient(
                    "http://localhost:" + server.getPort() +
                    "/volantis/wibble/file.html", headers );

            StringBuffer response = new StringBuffer();
            BufferedReader resp = client.getBufferedReader();
            String line;
            while( ( line = resp.readLine() ) != null ) {
                response.append( line );
            }
            assertEquals( expectedHTML.toString(), response.toString() );       
View Full Code Here

    public void testTimeout() {
        try {

            final int MY_TIMEOUT = 100;

            HttpClient client = new HttpClient();
            client.setHost("localhost");
            client.setPort(server.getPort());
            client.setUri("/volantis/wibble/file.html");
            client.setRequestHeaders(headers);

            // Keep the server connection busy whilst connecting. This number
            // is should be greater than 2 seconds. Note that this delay is not
            // enforced because the server will shutdown within 1 second.
            server.setDelay(5000);
            client.connect(MY_TIMEOUT);

            // Shutdown the server and wait for 1/4 sec to guarentee it has
            // shut down properly.
            server.shutdown();
            Thread.currentThread().sleep(250);

            long now = System.currentTimeMillis();

            // Now attempt to read from the server. The request should timeout
            // with the specified timeout value.
            try {
                StringBuffer response = new StringBuffer();
                BufferedReader resp = client.getBufferedReader();
                String line;
                while ((line = resp.readLine()) != null) {
                    response.append(line);
                }
                assertEquals(expectedHTML.toString(), response.toString());
View Full Code Here

TOP

Related Classes of com.volantis.mcs.utilities.HttpClient

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.