public static NutMap invoke(final Object obj, Reader r) {
        final NutMap resp = new NutMap();
        resp.setv("jsonrpc", Version);
        Object req;
        try {
            req = Json.fromJson(r);
        } catch (Exception e) {
            return resp.setv("error", error(ParseError, "Parse error", E(e)));
        }
        if (req == null) {
            return resp.setv("error", error(InvalidRequest, "Invalid Request", "json is null"));
        }

        if (req instanceof Iterable) {// rpc批量调用
            final List<NutMap> results = new ArrayList<NutMap>();
            Lang.each(req, new Each<Object>() {
                public void invoke(int index, Object ele, int length) {
                    if (ele instanceof Map) {
                        results.add(JsonRPC.invoke(obj, new NutMap((Map<String, Object>) ele)));
                    } else {
                        NutMap _resp = new NutMap();
                        _resp.setv("jsonrpc", Version).setv("error", error(InvalidRequest, "Invalid Request", "not map or list"));
                        results.add(_resp);
                    }
                }
            });
            return resp.setv("result", results);
        } else if (req instanceof Map) { // 单一调用
            return invoke(obj, new NutMap((Map<String, Object>) req));
        } else { // 传的是什么鸟,拒绝
            return resp.setv("error", error(InvalidRequest, "Invalid Request", "not map or list"));
        }
    }
public static NutMap invoke(final Object obj, Reader r) {
        final NutMap resp = new NutMap();
        resp.setv("jsonrpc", Version);
        Object req;
        try {
            req = Json.fromJson(r);
        } catch (Exception e) {
            return resp.setv("error", error(ParseError, "Parse error", E(e)));
        }
        if (req == null) {
            return resp.setv("error", error(InvalidRequest, "Invalid Request", "json is null"));
        }

        if (req instanceof Iterable) {
            final List<NutMap> results = new ArrayList<NutMap>();
            Lang.each(req, new Each<Object>() {
                public void invoke(int index, Object ele, int length) {
                    if (ele instanceof Map) {
                        results.add(JsonRPC.invoke(obj, new NutMap((Map<String, Object>) ele)));
                    } else {
                        NutMap _resp = new NutMap();
                        _resp.setv("jsonrpc", Version).setv("error", error(InvalidRequest, "Invalid Request", "not map or list"));
                        results.add(_resp);
                    }
                }
            });
            return resp.setv("result", results);
        } else if (req instanceof Map) { 
            return invoke(obj, new NutMap((Map<String, Object>) req));
        } else { 
            return resp.setv("error", error(InvalidRequest, "Invalid Request", "not map or list"));
        }
    }
public static NutMap invoke ( final Object obj , Reader r ) { final NutMap resp = new NutMap ( ) ; resp . setv ( "jsonrpc" , Version ) ; Object req ; try { req = Json . fromJson ( r ) ; } catch ( Exception e ) { return resp . setv ( "error" , error ( ParseError , "Parse error" , E ( e ) ) ) ; } if ( req == null ) { return resp . setv ( "error" , error ( InvalidRequest , "Invalid Request" , "json is null" ) ) ; } if ( req instanceof Iterable ) { // rpc批量调用 final List < NutMap > results = new ArrayList < NutMap > ( ) ; Lang . each ( req , new Each < Object > ( ) { public void invoke ( int index , Object ele , int length ) { if ( ele instanceof Map ) { results . add ( JsonRPC . invoke ( obj , new NutMap ( ( Map < String , Object > ) ele ) ) ) ; } else { NutMap _resp = new NutMap ( ) ; _resp . setv ( "jsonrpc" , Version ) . setv ( "error" , error ( InvalidRequest , "Invalid Request" , "not map or list" ) ) ; results . add ( _resp ) ; } } } ) ; return resp . setv ( "result" , results ) ; } else if ( req instanceof Map ) { // 单一调用 return invoke ( obj , new NutMap ( ( Map < String , Object > ) req ) ) ; } else { // 传的是什么鸟,拒绝 return resp . setv ( "error" , error ( InvalidRequest , "Invalid Request" , "not map or list" ) ) ; } }
服务端
服务端