使用JSOUP概念发布JSON时出错

时间:2016-07-15 19:33:02

标签: java json jsoup saiku

我想将嵌套的JSON输入发布到saiku服务器。我在POSTMAN中取得了成功,但是当我在java代码中尝试时,我有一个错误,例如

Errorjava.lang.IllegalArgumentException: Data value must not be null

下面是我将嵌套JSON发布到saiku服务器的代码。

             // nested JSON
            JSONObject object = new JSONObject();
            JSONObject querymodel = new JSONObject();
            JSONObject cube = new JSONObject();
            JSONObject parameters = new JSONObject();
            JSONObject plugin = new JSONObject();
            JSONObject properties = new JSONObject();
            JSONObject metadata = new JSONObject();
            JSONObject axes = new JSONObject();
            JSONObject details = new JSONObject();
            JSONObject columns = new JSONObject();
            JSONObject filter = new JSONObject();
            JSONObject rows = new JSONObject();
            JSONObject measures = new JSONObject();
            JSONObject o = new JSONObject();
            JSONObject hierarchies = new JSONObject();
            JSONObject o2 = new JSONObject();
            JSONObject levels = new JSONObject();
            JSONObject Year = new JSONObject();
            JSONObject cmembers = new JSONObject();

            cube.put("caption", null);
            cube.put("catalog", "Global Earthquakes");
            cube.put("connection", "earthquakes");
            cube.put("name", "Earthquakes");
            cube.put("schema", "Global Earthquakes");
            cube.put("uniqueName",
                    "[earthquakes].[Global Earthquakes].[Global Earthquakes].[Earthquakes]");
            cube.put("visible", Boolean.FALSE);

            properties.put("org.saiku.connection.scenario", Boolean.FALSE);
            properties.put("org.saiku.query.explain", Boolean.TRUE);
            properties.put("saiku.olap.query.automatic_execution", Boolean.TRUE);
            properties.put("saiku.olap.query.drillthrough", Boolean.TRUE);
            properties.put("saiku.olap.query.filter", Boolean.TRUE);
            properties.put("saiku.olap.query.nonempty", Boolean.TRUE);
            properties.put("saiku.olap.query.nonempty.columns", Boolean.TRUE);
            properties.put("saiku.olap.query.nonempty.rows", Boolean.TRUE);
            properties.put("saiku.olap.result.formatter", "flattened");
            properties.put("saiku.ui.render.mode", "table");


            List<String> a = new ArrayList<String>();
            List<String> ab = new ArrayList<String>();

            querymodel.put("axes", axes);
            querymodel.put("calculatedMeasures", a);
            querymodel.put("calculatedMembers", ab);
            querymodel.put("details", details);
            querymodel.put("lowestLevelsOnly", Boolean.FALSE);
            querymodel.put("visualTotals", Boolean.FALSE);
            querymodel.put("visualTotalsPattern", null);

            axes.put("COLUMNS", columns);
            axes.put("FILTER", filter);
            axes.put("ROWS", rows);

            List<Object> oa = new ArrayList<Object>();
            oa.add(o);
            o.put("name", "Average Magnitude");
            o.put("type", "EXACT");

            details.put("axis", "COLUMNS");
            details.put("location", "BOTTOM");
            details.put("measures", oa);

            List<String> b = new ArrayList<String>();
            List<String> bb = new ArrayList<String>();
            List<String> bc = new ArrayList<String>();

            columns.put("aggregators", b);
            columns.put("filters", bb);
            columns.put("hierarchies", bc);
            columns.put("hierarchizeMode", null);
            columns.put("location", "COLUMNS");
            columns.put("mdx", null);
            columns.put("nonEmpty", Boolean.TRUE);
            columns.put("sortEvaluationLiteral", null);
            columns.put("sortOrder", null);

            List<String> c = new ArrayList<String>();
            List<String> cb = new ArrayList<String>();
            List<String> cc = new ArrayList<String>();

            filter.put("aggregators", c);
            filter.put("filters", cb);
            filter.put("hierarchies", cc);
            filter.put("hierarchizeMode", null);
            filter.put("location", "FILTER");
            filter.put("mdx", null);
            filter.put("nonEmpty", Boolean.TRUE);
            filter.put("sortEvaluationLiteral", null);
            filter.put("sortOrder", null);

            List<String> d = new ArrayList<String>();
            List<String> db = new ArrayList<String>();
            List<Object> o2a = new ArrayList<Object>();
            o2a.add(o2);
            o2.put("cmembers", cmembers);
            o2.put("levels", levels);
            o2.put("name", "[Date].[Time]");

            rows.put("aggregators", d);
            rows.put("filters", db);
            rows.put("hierarchies", o2a);
            rows.put("hierarchizeMode", null);
            rows.put("location", "ROWS");
            rows.put("mdx", null);
            rows.put("nonEmpty", Boolean.TRUE);
            rows.put("sortEvaluationLiteral", null);
            rows.put("sortOrder", null);

            //hierarchies.put("0", o2a);

            levels.put("Year", Year);

            Year.put("name", "Year");

            object.put("cube", cube);
            object.put("mdx", null);
            object.put("metadata", metadata);
            object.put("name", "earth");
            object.put("parameters", parameters);
            object.put("plugins", plugin);
            object.put("properties", properties);
            object.put("queryModel", querymodel);
            object.put("queryType", "OLAP");
            object.put("type", "QUERYMODEL");

            System.out.println("++++++++++++++++++++++++++++"+object.toString());

            Response execute = Jsoup
                    .connect(
                            "http://localhost:8080/saiku/rest/saiku/api/query/execute/")
                    .header("Content-Type", "application/json")
                    .header("Accept", "application/json")
                    .requestBody(object.toJSONString())
                    .data(object)
                    .ignoreContentType(true)
                    .referrer("http://localhost:8080/")
                    .cookie("JSESSIONID", res.cookie("JSESSIONID"))
                    .userAgent(
                            "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36")
                    .method(Method.POST).timeout(10000).execute();
            System.out.println("post successfully....."
                    + object.toJSONString());

1 个答案:

答案 0 :(得分:0)

你发送的mdx参数为空