gwt/3.3/src/pubnub/api/Pubnub.java
/**
     * Request URL
     *
     * @param List
     *            <String> request of url directories.
     * @return JSONArray from JSON response.
     */
Request URL
@param List
 request of url directories.
@return JSONArray from JSON response.
Request URL @param List request of url directories . @return JSONArray from JSON response .
private JSONArray _request(List<String> url_components) {
        String json = "";
        StringBuilder url = new StringBuilder();
        Iterator<String> url_iterator = url_components.iterator();
        String request_for = url_components.get(0);
        String request_type = url_components.get(1);
        url.append(this.ORIGIN);
        while (url_iterator.hasNext()) {
            try {
                String url_bit = (String) url_iterator.next();
                url.append("/").append(_encodeURIcomponent(url_bit));
            } catch (Exception e) {
                JSONArray jsono = new JSONArray();
                try {
                    jsono.put("Failed UTF-8 Encoding URL.");
                } catch (Exception jsone) {
                }
                return jsono;
            }
        }
        if (request_for.equals("subscribe") || request_for.equals("presence"))
            url.append("?uuid=").append(this.sessionUUID);
        if (request_for.equals("v2") && request_type.equals("history"))
            url.append(parameters);
        AsyncHttpClient ahc = null;
        try {
            Builder cb = new AsyncHttpClientConfig.Builder();
            cb.setRequestTimeoutInMs(310000);
            AsyncHttpClientConfig config = cb.build();
            ahc = new AsyncHttpClient(config);
            RequestBuilder rb = new RequestBuilder("GET");
            rb.setUrl(url.toString());
            rb.addHeader("V", "3.1");
            rb.addHeader("User-Agent", "Java");
            rb.addHeader("Accept-Encoding", "gzip");
            Request request = rb.build();
            Future<String> f = ahc.executeRequest(request,
            new AsyncCompletionHandler<String>() {
                @Override
                public String onCompleted(Response r) throws Exception {
                    String ce = r.getHeader("Content-Encoding");
                    InputStream resulting_is = null;
                    InputStream is = r.getResponseBodyAsStream();
                    if (ce != null && ce.equalsIgnoreCase("gzip")) {
                        try {
                            resulting_is = new GZIPInputStream(is);
                        } catch (IOException e) {
                            resulting_is = is;
                        } catch (Exception e) {
                            resulting_is = is;
                        }
                    } else {
                        resulting_is = is;
                    }
                    String line = "", json = "";
                    BufferedReader reader = new BufferedReader(
                        new InputStreamReader(resulting_is, "UTF8"));
                    while ((line = reader.readLine()) != null) {
                        json += line;
                    }
                    reader.close();
                    return json;
                }
            });
            json = f.get();
            ahc.close();
        } catch (Exception e) {
            JSONArray jsono = new JSONArray();
            try {
                if (request_for != null) {
                    if (request_for.equals("time")) {
                        jsono.put("0");
                    } else if (request_for.equals("history")) {
                        jsono.put("Error: Failed JSONP HTTP Request.");
                    } else if (request_for.equals("publish")) {
                        jsono.put("0");
                        jsono.put("Error: Failed JSONP HTTP Request.");
                    } else if (request_for.equals("subscribe")) {
                        jsono.put("0");
                        jsono.put("0");
                    }
                }
            } catch (Exception jsone) {
            }
            if (ahc != null) {
                ahc.close();
            }
            return jsono;
        }
        try {
            if (json.contains("uuids")) {
                JSONArray resp = new JSONArray();
                resp.put(json);
                return resp;
            }
            return new JSONArray(json);
        } catch (Exception e) {
            JSONArray jsono = new JSONArray();
            try {
                jsono.put("Error: Failed JSON Parsing.");
            } catch (Exception jsone) {
            }
            return jsono;
        }
    }
private JSONArray _request ( List < String > url_components ) { String json = "" ; StringBuilder url = new StringBuilder ( ) ; Iterator < String > url_iterator = url_components . iterator ( ) ; String request_for = url_components . get ( 0 ) ; String request_type = url_components . get ( 1 ) ; url . append ( this . ORIGIN ) ; while ( url_iterator . hasNext ( ) ) { try { String url_bit = ( String ) url_iterator . next ( ) ; url . append ( "/" ) . append ( _encodeURIcomponent ( url_bit ) ) ; } catch ( Exception e ) { JSONArray jsono = new JSONArray ( ) ; try { jsono . put ( "Failed UTF-8 Encoding URL." ) ; } catch ( Exception jsone ) { } return jsono ; } } if ( request_for . equals ( "subscribe" ) || request_for . equals ( "presence" ) ) url . append ( "?uuid=" ) . append ( this . sessionUUID ) ; if ( request_for . equals ( "v2" ) && request_type . equals ( "history" ) ) url . append ( parameters ) ; AsyncHttpClient ahc = null ; try { Builder cb = new AsyncHttpClientConfig . Builder ( ) ; cb . setRequestTimeoutInMs ( 310000 ) ; AsyncHttpClientConfig config = cb . build ( ) ; ahc = new AsyncHttpClient ( config ) ; RequestBuilder rb = new RequestBuilder ( "GET" ) ; rb . setUrl ( url . toString ( ) ) ; rb . addHeader ( "V" , "3.1" ) ; rb . addHeader ( "User-Agent" , "Java" ) ; rb . addHeader ( "Accept-Encoding" , "gzip" ) ; Request request = rb . build ( ) ; Future < String > f = ahc . executeRequest ( request , new AsyncCompletionHandler < String > ( ) { @ Override public String onCompleted ( Response r ) throws Exception { String ce = r . getHeader ( "Content-Encoding" ) ; InputStream resulting_is = null ; InputStream is = r . getResponseBodyAsStream ( ) ; if ( ce != null && ce . equalsIgnoreCase ( "gzip" ) ) { try { resulting_is = new GZIPInputStream ( is ) ; } catch ( IOException e ) { resulting_is = is ; } catch ( Exception e ) { resulting_is = is ; } } else { resulting_is = is ; } String line = "" , json = "" ; BufferedReader reader = new BufferedReader ( new InputStreamReader ( resulting_is , "UTF8" ) ) ; while ( ( line = reader . readLine ( ) ) != null ) { json += line ; } reader . close ( ) ; return json ; } } ) ; json = f . get ( ) ; ahc . close ( ) ; } catch ( Exception e ) { JSONArray jsono = new JSONArray ( ) ; try { if ( request_for != null ) { if ( request_for . equals ( "time" ) ) { jsono . put ( "0" ) ; } else if ( request_for . equals ( "history" ) ) { jsono . put ( "Error: Failed JSONP HTTP Request." ) ; } else if ( request_for . equals ( "publish" ) ) { jsono . put ( "0" ) ; jsono . put ( "Error: Failed JSONP HTTP Request." ) ; } else if ( request_for . equals ( "subscribe" ) ) { jsono . put ( "0" ) ; jsono . put ( "0" ) ; } } } catch ( Exception jsone ) { } if ( ahc != null ) { ahc . close ( ) ; } return jsono ; } try { if ( json . contains ( "uuids" ) ) { JSONArray resp = new JSONArray ( ) ; resp . put ( json ) ; return resp ; } return new JSONArray ( json ) ; } catch ( Exception e ) { JSONArray jsono = new JSONArray ( ) ; try { jsono . put ( "Error: Failed JSON Parsing." ) ; } catch ( Exception jsone ) { } return jsono ; } }
Request URL
 @param List
            <String> request of url directories.
Request URL @param List <String > request of url directories .
// Generate URL with UTF-8 Encoding // e.printStackTrace(); // Prepare Asynchronous HTTP Request // Execute Request // Decoding using 'gzip' // Default (encoding is null OR 'identity') // Read JSON Message // Response If Failed JSONP HTTP Request. // Parse JSON String // Return Failure to Parse