Search in sources :

Example 16 with JSONObject

use of com.alibaba.fastjson.JSONObject in project weex-example by KalicyZhou.

the class WXDomStatementTest method testStartAnimation.

@Test
public void testStartAnimation() throws Exception {
    createBody();
    JSONObject obj;
    obj = new JSONObject();
    obj.put("type", "div");
    obj.put("ref", "100");
    stmt.addDom(obj, WXDomObject.ROOT, 0);
    stmt.startAnimation("100", "", null);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) WXBridgeManagerTest(com.taobao.weex.bridge.WXBridgeManagerTest) Test(org.junit.Test) WXSDKInstanceTest(com.taobao.weex.WXSDKInstanceTest)

Example 17 with JSONObject

use of com.alibaba.fastjson.JSONObject in project weex-example by KalicyZhou.

the class WXDomStatementTest method testMoveDom.

@Test
public void testMoveDom() throws Exception {
    createBody();
    JSONObject obj;
    obj = new JSONObject();
    obj.put("type", "div");
    obj.put("ref", "100");
    stmt.addDom(obj, WXDomObject.ROOT, 0);
    obj = new JSONObject();
    obj.put("type", "div");
    obj.put("ref", "101");
    stmt.addDom(obj, WXDomObject.ROOT, 0);
    stmt.moveDom("100", WXDomObject.ROOT, 1);
    stmt.batch();
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) WXBridgeManagerTest(com.taobao.weex.bridge.WXBridgeManagerTest) Test(org.junit.Test) WXSDKInstanceTest(com.taobao.weex.WXSDKInstanceTest)

Example 18 with JSONObject

use of com.alibaba.fastjson.JSONObject in project weex-example by KalicyZhou.

the class WXStreamModule method fetch.

/**
   *
   * @param optionsStr request options include:
   *  method: GET 、POST、PUT、DELETE、HEAD、PATCH
   *  headers:object,请求header
   *  url:
   *  body: "Any body that you want to add to your request"
   *  type: json、text、jsonp(native实现时等价与json)
   * @param callback finished callback,response object:
   *  status:status code
   *  ok:boolean 是否成功,等价于status200~299
   *  statusText:状态消息,用于定位具体错误原因
   *  data: 响应数据,当请求option中type为json,时data为object,否则data为string类型
   *  headers: object 响应头
   *
   * @param progressCallback in progress callback,for download progress and request state,response object:
   *  readyState: number 请求状态,1 OPENED,开始连接;2 HEADERS_RECEIVED;3 LOADING
   *  status:status code
   *  length:当前获取的字节数,总长度从headers里「Content-Length」获取
   *  statusText:状态消息,用于定位具体错误原因
   *  headers: object 响应头
   */
@JSMethod(uiThread = false)
public void fetch(String optionsStr, final JSCallback callback, JSCallback progressCallback) {
    JSONObject optionsObj = null;
    try {
        optionsObj = JSON.parseObject(optionsStr);
    } catch (JSONException e) {
        WXLogUtils.e("", e);
    }
    boolean invaildOption = optionsObj == null || optionsObj.getString("url") == null;
    if (invaildOption) {
        if (callback != null) {
            Map<String, Object> resp = new HashMap<>();
            resp.put("ok", false);
            resp.put(STATUS_TEXT, Status.ERR_INVALID_REQUEST);
            callback.invoke(resp);
        }
        return;
    }
    String method = optionsObj.getString("method");
    String url = optionsObj.getString("url");
    JSONObject headers = optionsObj.getJSONObject("headers");
    String body = optionsObj.getString("body");
    String type = optionsObj.getString("type");
    int timeout = optionsObj.getIntValue("timeout");
    if (method != null)
        method = method.toUpperCase();
    Options.Builder builder = new Options.Builder().setMethod(!"GET".equals(method) && !"POST".equals(method) && !"PUT".equals(method) && !"DELETE".equals(method) && !"HEAD".equals(method) && !"PATCH".equals(method) ? "GET" : method).setUrl(url).setBody(body).setType(type).setTimeout(timeout);
    extractHeaders(headers, builder);
    final Options options = builder.createOptions();
    sendRequest(options, new ResponseCallback() {

        @Override
        public void onResponse(WXResponse response, Map<String, String> headers) {
            if (callback != null) {
                Map<String, Object> resp = new HashMap<>();
                if (response == null || "-1".equals(response.statusCode)) {
                    resp.put(STATUS, -1);
                    resp.put(STATUS_TEXT, Status.ERR_CONNECT_FAILED);
                } else {
                    int code = Integer.parseInt(response.statusCode);
                    resp.put(STATUS, code);
                    resp.put("ok", (code >= 200 && code <= 299));
                    if (response.originalData == null) {
                        resp.put("data", null);
                    } else {
                        String respData = readAsString(response.originalData, headers != null ? getHeader(headers, "Content-Type") : "");
                        try {
                            resp.put("data", parseData(respData, options.getType()));
                        } catch (JSONException exception) {
                            WXLogUtils.e("", exception);
                            resp.put("ok", false);
                            resp.put("data", "{'err':'Data parse failed!'}");
                        }
                    }
                    resp.put(STATUS_TEXT, Status.getStatusText(response.statusCode));
                }
                resp.put("headers", headers);
                callback.invoke(resp);
            }
        }
    }, progressCallback);
}
Also used : HashMap(java.util.HashMap) JSONException(com.alibaba.fastjson.JSONException) WXResponse(com.taobao.weex.common.WXResponse) JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 19 with JSONObject

use of com.alibaba.fastjson.JSONObject in project weex-example by KalicyZhou.

the class WXStreamModule method sendHttp.

/**
   * send HTTP request
   *
   * @param params   {method:POST/GET/PUT/DELETE/HEAD/PATCH,url:http://xxx,header:{key:value},
   *                 body:{key:value}}
   * @param callback formate:handler(err, response)
   */
@Deprecated
@JSMethod(uiThread = false)
public void sendHttp(String params, final String callback) {
    JSONObject paramsObj = JSON.parseObject(params);
    String method = paramsObj.getString("method");
    String url = paramsObj.getString("url");
    JSONObject headers = paramsObj.getJSONObject("header");
    String body = paramsObj.getString("body");
    int timeout = paramsObj.getIntValue("timeout");
    if (method != null)
        method = method.toUpperCase();
    Options.Builder builder = new Options.Builder().setMethod(!"GET".equals(method) && !"POST".equals(method) && !"PUT".equals(method) && !"DELETE".equals(method) && !"HEAD".equals(method) && !"PATCH".equals(method) ? "GET" : method).setUrl(url).setBody(body).setTimeout(timeout);
    extractHeaders(headers, builder);
    sendRequest(builder.createOptions(), new ResponseCallback() {

        @Override
        public void onResponse(WXResponse response, Map<String, String> headers) {
            if (callback != null && mWXSDKInstance != null)
                WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callback, (response == null || response.originalData == null) ? "{}" : readAsString(response.originalData, headers != null ? getHeader(headers, "Content-Type") : ""));
        }
    }, null);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) WXResponse(com.taobao.weex.common.WXResponse) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 20 with JSONObject

use of com.alibaba.fastjson.JSONObject in project weex-example by KalicyZhou.

the class WXDomObject method parseFromJson.

/**
   * Parse the jsonObject to {@link WXDomObject} recursively
   * @param map the original JSONObject
   */
public void parseFromJson(JSONObject map) {
    if (map == null || map.size() <= 0) {
        return;
    }
    String type = (String) map.get("type");
    this.mType = type;
    this.mRef = (String) map.get("ref");
    Object style = map.get("style");
    if (style != null && style instanceof JSONObject) {
        WXStyle styles = new WXStyle();
        styles.putAll((JSONObject) style, false);
        this.mStyles = styles;
    }
    Object attr = map.get("attr");
    if (attr != null && attr instanceof JSONObject) {
        WXAttr attrs = new WXAttr((JSONObject) attr);
        //WXJsonUtils.putAll(attrs, (JSONObject) attr);
        this.mAttributes = attrs;
    }
    Object event = map.get("event");
    if (event != null && event instanceof JSONArray) {
        WXEvent events = new WXEvent();
        JSONArray eventArray = (JSONArray) event;
        int count = eventArray.size();
        for (int i = 0; i < count; ++i) {
            events.add(eventArray.getString(i));
        }
        this.mEvents = events;
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)1750 HashMap (java.util.HashMap)302 JSONArray (com.alibaba.fastjson.JSONArray)279 Test (org.junit.Test)217 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)182 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)165 IOException (java.io.IOException)138 ArrayList (java.util.ArrayList)125 Map (java.util.Map)111 AuthPassport (com.ngtesting.platform.util.AuthPassport)96 UserVo (com.ngtesting.platform.vo.UserVo)76 Date (java.util.Date)76 List (java.util.List)72 File (java.io.File)70 UnitResponse (info.xiancloud.core.message.UnitResponse)61 JSONException (com.alibaba.fastjson.JSONException)46 StringEntity (org.apache.http.entity.StringEntity)46 HttpResponse (org.apache.http.HttpResponse)44 Header (org.apache.http.Header)36 DefaultJSONParser (com.alibaba.fastjson.parser.DefaultJSONParser)30