modules/tests/test-integration/src/test/java/org/ballerinalang/test/util/HttpClientRequest.java
/**
     * Sends an HTTP GET request to a url.
     *
     * @param requestUrl - The URL of the service. (Example: "http://www.yahoo.com/search?params=value")
     * @param headers - http request header map
     * @return - HttpResponse from the end point
     * @throws java.io.IOException If an error occurs while sending the GET request
     */
Sends an HTTP GET request to a url.
@param requestUrl - The URL of the service.
Sends an HTTP GET request to a url . @param requestUrl - The URL of the service .
public static HttpResponse doGet(String requestUrl, Map<String, String> headers)
            throws IOException {
        HttpURLConnection conn = null;
        HttpResponse httpResponse;
        try {
            conn = getURLConnection(requestUrl);
            for (Map.Entry<String, String> e : headers.entrySet()) {
                conn.setRequestProperty(e.getKey(), e.getValue());
            }
            conn.setRequestMethod("GET");
            conn.connect();
            StringBuilder sb = new StringBuilder();
            BufferedReader rd = null;
            try {
                rd = new BufferedReader(new InputStreamReader(conn.getInputStream()
                        , Charset.defaultCharset()));
                String line;
                while ((line = rd.readLine()) != null) {
                    sb.append(line);
                }
                httpResponse = new HttpResponse(sb.toString(), conn.getResponseCode());
            } catch (IOException ex) {
                rd = new BufferedReader(new InputStreamReader(conn.getErrorStream()
                        , Charset.defaultCharset()));
                String line;
                while ((line = rd.readLine()) != null) {
                    sb.append(line);
                }
                httpResponse = new HttpResponse(sb.toString(), conn.getResponseCode());
            } finally {
                if (rd != null) {
                    rd.close();
                }
            }
            httpResponse.setHeaders(readHeaders(conn));
            httpResponse.setResponseMessage(conn.getResponseMessage());
            return httpResponse;
        } finally {
            if (conn != null) {
                conn.disconnect();
            }
        }
    }
public static HttpResponse doGet ( String requestUrl , Map < String , String > headers ) throws IOException { HttpURLConnection conn = null ; HttpResponse httpResponse ; try { conn = getURLConnection ( requestUrl ) ; for ( Map . Entry < String , String > e : headers . entrySet ( ) ) { conn . setRequestProperty ( e . getKey ( ) , e . getValue ( ) ) ; } conn . setRequestMethod ( "GET" ) ; conn . connect ( ) ; StringBuilder sb = new StringBuilder ( ) ; BufferedReader rd = null ; try { rd = new BufferedReader ( new InputStreamReader ( conn . getInputStream ( ) , Charset . defaultCharset ( ) ) ) ; String line ; while ( ( line = rd . readLine ( ) ) != null ) { sb . append ( line ) ; } httpResponse = new HttpResponse ( sb . toString ( ) , conn . getResponseCode ( ) ) ; } catch ( IOException ex ) { rd = new BufferedReader ( new InputStreamReader ( conn . getErrorStream ( ) , Charset . defaultCharset ( ) ) ) ; String line ; while ( ( line = rd . readLine ( ) ) != null ) { sb . append ( line ) ; } httpResponse = new HttpResponse ( sb . toString ( ) , conn . getResponseCode ( ) ) ; } finally { if ( rd != null ) { rd . close ( ) ; } } httpResponse . setHeaders ( readHeaders ( conn ) ) ; httpResponse . setResponseMessage ( conn . getResponseMessage ( ) ) ; return httpResponse ; } finally { if ( conn != null ) { conn . disconnect ( ) ; } } }
Sends an HTTP GET request to a url.
Sends an HTTP GET request to a url .
//setting request headers