com.android.volley.toolbox.HurlStack Java Examples

The following examples show how to use com.android.volley.toolbox.HurlStack. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CloudBackendFragment.java    From io2014-codelabs with Apache License 2.0 6 votes vote down vote up
private RequestQueue newRequestQueue(Context context) {
    // define cache folder
    File rootCache = context.getExternalCacheDir();
    if (rootCache == null) {
        rootCache = context.getCacheDir();
    }

    File cacheDir = new File(rootCache, DEFAULT_CACHE_DIR);
    cacheDir.mkdirs();

    HttpStack stack = new HurlStack();
    Network network = new BasicNetwork(stack);
    DiskBasedCache diskBasedCache = new DiskBasedCache(cacheDir, DEFAULT_DISK_USAGE_BYTES);
    RequestQueue queue = new RequestQueue(diskBasedCache, network);
    queue.start();

    return queue;
}
 
Example #2
Source File: VolleySingleton.java    From qBittorrent-Controller with MIT License 6 votes vote down vote up
private RequestQueue getRequestQueueHttps(String keystore_path, String keystore_password) {
//        if (requestQueue == null) {
//            Log.d("Debug", "[SSLSocketFactory] getRequestQueueHttps");
//
//            requestQueue = Volley.newRequestQueue(context.getApplicationContext(),  new HurlStack(null, getSocketFactory(keystore_path,keystore_password)));
//        }
//        else{
//            Log.d("Debug", "[SSLSocketFactory] requestQueue is NOT null");
//        }

//        Log.d("Debug", "[SSLSocketFactory] getRequestQueueHttps");
//        Log.d("Debug", "[SSLSocketFactory] keystore_path: " + keystore_path);
//        Log.d("Debug", "[SSLSocketFactory] keystore_password: " + keystore_password);

        requestQueue = Volley.newRequestQueue(context.getApplicationContext(), new HurlStack(null, getSocketFactory(keystore_path, keystore_password)));

        return requestQueue;
    }
 
Example #3
Source File: VolleyQueueSingleton.java    From base-module with Apache License 2.0 5 votes vote down vote up
private RequestQueue newAsyncRequestQueue(HurlStack stack) {
    BasicNetwork network = new BasicNetwork(stack);
    //修改Volley的请求队列,构键新的线程池
    RequestQueue queue1 = new RequestQueue(new NoCache(), network, DEFAULT_NETWORK_THREAD_POOL_SIZE,
            new ExecutorDelivery(executorService));
    queue1.start();
    return queue1;
}
 
Example #4
Source File: LimitingRequestQueue.java    From odyssey with GNU General Public License v3.0 5 votes vote down vote up
public synchronized static LimitingRequestQueue getInstance(Context context) {
    if (null == mInstance) {
        Network network = new BasicNetwork(new HurlStack());
        // 10MB disk cache
        Cache cache = new DiskBasedCache(context.getCacheDir(), 1024 * 1024 * 10);

        mInstance = new LimitingRequestQueue(cache, network);
        mInstance.start();
    }
    return mInstance;
}
 
Example #5
Source File: EasyVolley.java    From EasyVolley with Apache License 2.0 5 votes vote down vote up
public static void initialize(Context appContext, int lruCacheSize) {
    if (mGlobalRequestQueue == null) {
        mGlobalRequestQueue = new com.github.asifmujteba.easyvolley.ASFRequestQueue(Volley.newRequestQueue(appContext,
                new HurlStack(), maxDiskCacheBytes));
    }

    if (lruCacheSize > 0) {
        getMemoryCache().setMaxSize(lruCacheSize);
    }
}
 
Example #6
Source File: ImageLoader.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
private static RequestQueue newRequestQueue(Context context) {

        // On HC+ use HurlStack which is based on HttpURLConnection. Otherwise fall back on
        // AndroidHttpClient (based on Apache DefaultHttpClient) which should no longer be used
        // on newer platform versions where HttpURLConnection is simply better.
        Network network = new BasicNetwork(Utils.hasHoneycomb() ? new HurlStack() : new HttpClientStack(AndroidHttpClient.newInstance(Utils.getUserAgent(context))));

        Cache cache = new DiskBasedCache(getDiskCacheDir(context, CACHE_DIR), DEFAULT_DISK_USAGE_BYTES);
        RequestQueue queue = new RequestQueue(cache, network);
        queue.start();
        return queue;
    }
 
Example #7
Source File: VolleyTestMainActivity.java    From android_tv_metro with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.test_main);

	txtDisplay = (TextView) findViewById(R.id.txtDisplay);

	// Instantiate the cache
	Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024); // 1MB cap
	// Set up the network to use HttpURLConnection as the HTTP client.
	Network network = new BasicNetwork(new HurlStack());
	// Instantiate the RequestQueue with the cache and network.
	mRequestQueue = new RequestQueue(cache, network);
	// Start the queue
	mRequestQueue.start();
	
	String url = "http://172.27.9.104:9300/testdata/1/1/1/zh/CN?api=index";

	JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, url, null,
			new Response.Listener<JSONObject>() {

				@Override
				public void onResponse(JSONObject response) {
					// TODO Auto-generated method stub
					txtDisplay.setText("Response => " + response.toString());
					findViewById(R.id.progressBar1).setVisibility(View.GONE);
				}
			}, new Response.ErrorListener() {

				@Override
				public void onErrorResponse(VolleyError error) {
					txtDisplay.setText("VolleyError => " + error.toString());
					findViewById(R.id.progressBar1).setVisibility(View.GONE);
				}
			});

	mRequestQueue.add(jsObjRequest);

}
 
Example #8
Source File: HttpStackSelector.java    From CrossBow with Apache License 2.0 5 votes vote down vote up
public static HttpStack createStack() {
    if(hasOkHttp()) {
        OkHttpClient okHttpClient = new OkHttpClient();
        VolleyLog.d("OkHttp found, using okhttp for http stack");
        return new OkHttpStack(okHttpClient);
    }
    else if (useHttpClient()){
        VolleyLog.d("Android version is older than Gingerbread (API 9), using HttpClient");
        return new HttpClientStack(AndroidHttpClient.newInstance(USER_AGENT));
    }
    else {
        VolleyLog.d("Using Default HttpUrlConnection");
        return new HurlStack();
    }
}
 
Example #9
Source File: VolleyQueueSingleton.java    From base-module with Apache License 2.0 4 votes vote down vote up
private VolleyQueueSingleton() {
//        HttpsTrustManager.allowAllSSL();
        HurlStack stack = new SelfSignSslHurlStack();
        mRequestQueue = newAsyncRequestQueue(stack);
    }
 
Example #10
Source File: RemoteDataSource.java    From android-network-security-config with Apache License 2.0 4 votes vote down vote up
public RemoteDataSource(String url) {
    mUrl = url;
    mRequestQueue = new RequestQueue(new NoCache(), new BasicNetwork(new HurlStack()));
    mRequestQueue.start();
}
 
Example #11
Source File: VolleyHttpRequest.java    From privacy-friendly-weather with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @see IHttpRequest#make(String, HttpRequestType, IProcessHttpRequest)
 */
@Override
public void make(String URL, HttpRequestType method, final IProcessHttpRequest requestProcessor) {
    RequestQueue queue = Volley.newRequestQueue(context, new HurlStack(null, getSocketFactory()));

    // Set the request method
    int requestMethod;
    switch (method) {
        case POST:
            requestMethod = Request.Method.POST;
            break;
        case GET:
            requestMethod = Request.Method.GET;
            break;
        case PUT:
            requestMethod = Request.Method.PUT;
            break;
        case DELETE:
            requestMethod = Request.Method.DELETE;
            break;
        default:
            requestMethod = Request.Method.GET;
    }

    // Execute the request and handle the response
    StringRequest stringRequest = new StringRequest(requestMethod, URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    requestProcessor.processSuccessScenario(response);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    requestProcessor.processFailScenario(error);
                }
            }
    );

    queue.add(stringRequest);
}
 
Example #12
Source File: GetChromium.java    From getChromium with GNU General Public License v3.0 4 votes vote down vote up
private void downloadLatest() {

        // Instantiate the cache
        Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024); // 1MB cap

        // Set up the network to use HttpURLConnection as the HTTP client.
        com.android.volley.Network network = new BasicNetwork(new HurlStack());

        // Instantiate the RequestQueue with the cache and network.
        mRequestQueue = new RequestQueue(cache, network);
        mRequestQueue.start();

        // Request a string response from "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Android/LAST_CHANGE"
        // The response provides the current build number of Chromium's latest build
        String urlL = "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Android/LAST_CHANGE";
        final StringRequest stringRequest = new StringRequest(Request.Method.GET, urlL,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                        // Build new String for the current APK download URL
                        Uri.Builder builder = new Uri.Builder();
                        builder.scheme("https")
                                .authority("commondatastorage.googleapis.com")
                                .appendPath("chromium-browser-snapshots")
                                .appendPath("Android")
                                .appendPath(response) // Build revision number
                                .appendPath("chrome-android.zip"); // Name of the file that will contain the APKs.
                        String apkUrl = builder.build().toString();
                        new DownloadTask().execute(apkUrl);
                    }
                },

                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                    }
                });

        // Add the request to the RequestQueue.
        mRequestQueue.add(stringRequest);
    }
 
Example #13
Source File: EasyVolley.java    From EasyVolley with Apache License 2.0 4 votes vote down vote up
public static com.github.asifmujteba.easyvolley.ASFRequestContext withNewQueue(Context context) {
    return new com.github.asifmujteba.easyvolley.ASFRequestContext(new ASFRequestQueue(Volley.newRequestQueue(context,
            new HurlStack())));
}