使用 Jsoup 为 saiku 创建新的数据源

Create New DataSources For saiku using Jsoup

我必须在 saiku 服务器中创建一个新的数据源。我已经成功地在我的本地 运行 angular saiku 应用程序中创建了数据源,该应用程序是 运行 在 tomcat 中。 但我尝试使用 JAVA 代码创建数据源。我在粘贴代码时遇到了以下问题。 代码是,

p s v m(){
      String connectionname="saran";
      String connectiontype="MONDRIAN";
      String jdbcurl="jdbc:mysql://localhost:3306/drink";
      String schema="/datasources/drink.xml";
      String driver="com.mysql.jdbc.Driver";
      String username="root";
      String password="211218";

    Response connection = Jsoup
         .connect(
           "http://localhost:8080/saiku/rest/saiku/admin/datasources/")
         .header("Content-Type", "application/json)
    .data(connectionname,connectiontype,jdbcurl,schema,driver,username,password)
.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();
    }

输出 Errororg.jsoup.HttpStatusException: HTTP error fetching URL. Status=415, URL=http://localhost:8080/saiku/rest/saiku/admin/datasources/

我面临的另一个问题是我没有看到任何 Java 源代码,什么是 saiku 数据源方法的输入参数和参数以及它们如何在 JAVA 代码中声明。 是否可以看到 JAVA Saiku 服务器端编码,我看到 git OSLB/Saiku 我克隆了它,但我没有得到他们在 saiku angular 应用程序中提到的网址 运行 在浏览器本地。

我使用 requestBody() 发布 JSON object.The requestBody() 方法仅在 JSOUP 1.9.1 jar 中可用,我发布了下面的代码供您参考。

         // JSON Object
        JSONObject testJson = new JSONObject();

        testJson.put("connectionname", "drinkss");
        testJson.put("jdbcurl", "jdbc:mysql://localhost/drink");
        testJson.put("schema", "datasources/dr.xml");
        testJson.put("driver", "com.mysql.jdbc.Driver");
        testJson.put("username", "root");
        testJson.put("password", "211218");
        testJson.put("connectiontype", "MONDRIAN");

        // For Posting datasource into server


        Response document1 = Jsoup
                    .connect(
                            "http://localhost:8080/saiku/rest/saiku/admin/datasources/")
                    .header("Content-Type", "application/json")
                    .requestBody(testJson.toString())
                    .data(testJson)
                    .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....."
                    + testJson.toJSONString());