javajsonjsoupsaiku

Create New DataSources For saiku using Jsoup


I have to create a new datasources in saiku server. I have successfully able to create the datasources in my local running angular saiku application which is running inside the tomcat . But I have tried to create datasources using JAVA code . I Faced problems below I pasted my code . Code Is ,

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();
    }

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

The another problem I am facing is I dont see any Java source code what is the input param's and arguments of saiku datasources method and how they declared in their JAVA code. Is it possible to see the JAVA Saiku server side coding , I saw git OSLB/Saiku I cloned it but I dont get the urls they mentioned in the angular app of saiku running locally inside the browser.


Solution

  • I use the requestBody() for posting the JSON object.The requestBody() method is only available in the JSOUP 1.9.1 jar and i posted the code below for your reference.

             // 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());