Search in sources :

Example 31 with AjaxCallback

use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.

the class AQueryAsyncTest method testAjaxPostMultiWithProxyHandle.

public void testAjaxPostMultiWithProxyHandle() {
    BasicProxyHandle handle = new BasicProxyHandle("192.168.0.102", 3128, null, null);
    AjaxCallback.setProxyHandle(handle);
    String url = "http://www.androidquery.com/p/multipart";
    Map<String, Object> params = new HashMap<String, Object>();
    byte[] data = new byte[1234];
    byte[] data2 = new byte[2345];
    params.put("data", data);
    params.put("data2", data2);
    AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>() {

        @Override
        public void callback(String url, JSONObject jo, AjaxStatus status) {
            AQUtility.debug(status.getCode(), status.getError());
            AQueryAsyncTest.this.result = jo;
        }
    };
    aq.ajax(url, params, JSONObject.class, cb);
    waitAsync();
    JSONObject jo = (JSONObject) result;
    AQUtility.debug(jo);
    assertNotNull(jo);
    assertEquals(1234, jo.optInt("data"));
    assertEquals(2345, jo.optInt("data2"));
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 32 with AjaxCallback

use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.

the class AQueryAsyncTest method testFile404.

public void testFile404() {
    String url = "http://androidquery.appspot.com/test/fake";
    File old = aq.getCachedFile(url);
    if (old != null) {
        old.delete();
    }
    old = aq.getCachedFile(url);
    assertNull(old);
    AjaxCallback<File> cb = new AjaxCallback<File>();
    cb.url(url).type(File.class);
    //aq.ajax(url, JSONObject.class, cb);
    aq.sync(cb);
    File file = cb.getResult();
    AjaxStatus status = cb.getStatus();
    assertNull(file);
    assertEquals(404, status.getCode());
    old = aq.getCachedFile(url);
    assertNull(old);
}
Also used : File(java.io.File) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 33 with AjaxCallback

use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.

the class AQueryAsyncTest method testAjaxProxy.

//http://www.proxynova.com/proxy-server-list/
public void testAjaxProxy() throws ClientProtocolException, IOException {
    String url = "http://www.google.com";
    aq.ajax(url, String.class, new AjaxCallback<String>() {

        @Override
        public void callback(String url, String json, AjaxStatus status) {
            done(url, json, status);
        }
    }.proxy("192.168.0.105", 3128));
    waitAsync();
    assertNotNull(result);
    List<Header> headers = status.getHeaders();
    assertTrue(headers.size() > 0);
    Header c = headers.get(0);
    AQUtility.debug(c.getName(), c.getValue());
}
Also used : Header(org.apache.http.Header) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 34 with AjaxCallback

use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.

the class AQueryAsyncTest method testAjaxPostWithEmptyParams.

public void testAjaxPostWithEmptyParams() {
    String url = "http://www.androidquery.com/p/doNothing";
    AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>() {

        @Override
        public void callback(String url, JSONObject jo, AjaxStatus status) {
            done(url, jo, status);
        }
    };
    cb.url(url).type(JSONObject.class).method(AQuery.METHOD_POST);
    aq.ajax(cb);
    waitAsync();
    JSONObject jo = (JSONObject) result;
    AQUtility.debug(jo);
    assertNotNull(jo);
    assertEquals("POST", jo.optString("method"));
}
Also used : JSONObject(org.json.JSONObject) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 35 with AjaxCallback

use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.

the class AQueryAsyncTest method testIOError.

public void testIOError() {
    AQUtility.cleanCache(AQUtility.getCacheDir(getActivity()), 0, 0);
    String LAND_URL = "http://farm6.static.flickr.com/5035/5802797131_a729dac808_b.jpg";
    File file = aq.getCachedFile(LAND_URL);
    assertNull(file);
    AQUtility.TEST_IO_EXCEPTION = true;
    AjaxCallback<File> cb = new AjaxCallback<File>() {

        @Override
        public void callback(String url, File file, AjaxStatus status) {
            done(url, file, status);
        }
    };
    cb.fileCache(true);
    aq.ajax(LAND_URL, File.class, 0, cb);
    waitAsync();
    file = (File) result;
    assertNull(result);
    File file2 = aq.getCachedFile(LAND_URL);
    if (file2 != null) {
        AQUtility.debug("file length", file2.length());
    }
    assertNull(file2);
}
Also used : File(java.io.File) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Aggregations

AjaxCallback (com.androidquery.callback.AjaxCallback)37 BitmapAjaxCallback (com.androidquery.callback.BitmapAjaxCallback)33 AbstractAjaxCallback (com.androidquery.callback.AbstractAjaxCallback)31 AjaxStatus (com.androidquery.callback.AjaxStatus)28 JSONObject (org.json.JSONObject)23 File (java.io.File)12 HashMap (java.util.HashMap)5 Bitmap (android.graphics.Bitmap)3 StringEntity (org.apache.http.entity.StringEntity)3 XmlDom (com.androidquery.util.XmlDom)2 JsonObject (com.google.gson.JsonObject)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 HttpEntity (org.apache.http.HttpEntity)2 Activity (android.app.Activity)1 AQuery (com.androidquery.AQuery)1 GoogleHandle (com.androidquery.auth.GoogleHandle)1 Gson (com.google.gson.Gson)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1