Ext.: http://www.cnblogs.com/dreamfactory/p/5588203.html
Recently in the development of big data, learning to study the Kylin system for a period of time, for the front-end development needs to use the RESTful API, but the official website does not provide detailed Java API. After a few days of looking at the document, finally wrote out the Java API, dare not to stash, special share with you.
1 Import Java.io.BufferedReader; 2 Import Java.io.InputStream; 3 Import Java.io.InputStreamReader; 4 Import Java.io.OutputStream; 5 Import java.net.HttpURLConnection; 6 Import Java.net.URL; 7 8 Import Org.apache.commons.codec.binary.Base64; 9/** * * @author Hennsun * www.shareideas.net * @Reference * http://kylin.apache.org/d Ocs15/howto/howto_use_restapi.html#authentication * */public class Kylinhttpbasic {+ Private STA Tic String encoding; The private static final String BaseURL = "Http://10.1.50.123:7070/kylin/api"; public static string login (String user,string passwd) {string method = "POST"; string para = "/user/authentication"; Byte[] key = (user+ ":" +passwd). GetBytes (); encoding = base64.encodebase64string (key); Return Excute (Para,method,null); The public static string Listqueryabletables (String projectName) {34 The String method = "GET"; Para String = "/tables_and_columns?project=" +projectname; Panax Notoginseng return Excute (para,method,null); /** * * @param offset required int offset used by pagination * @param limit required int Cubes per page. CubeName * @param Optional string Keyword for cube names. To find cubes whose name contains this keyword. ProjectName * @param Optional String Project name. * @return * * * public static String listcubes (int offset, int l Imit, CubeName string, projectName) {5 5 String method = "GET"; Para String = "/cubes?offset=" +offset + "&limit=" +limit 58 + "&cubename=" +cubename + "&projectname=" +PROjectname; Return Excute (Para,method,null); /** * @param cubename Cube name. Getcubedes * @return * * *-public static string (string CubeName) {"String method =" GET "; 70 String para = "/cube_desc/" +cubename; Excute return (para,method,null); /** * * @param cubename * @return * * Bayi p * Ublic static string Getcube (String cubename) {The String method = "GET"; the string para = "/cubes/" +cubenam E Excute return (para,method,null); */** * * @param modelname Data model name, by default It should is the same with cube name. * * @return 94 * * * Getdatamodel public static string (string modelname) {"String method =" GET "; Para String = "/model/" +modelname; 98 Return Excute (Para,meThod,null); }101 102/**103 * 104 * @param cubename cubename Cube name.105 * @return106 * * 107 public static string Enablecube (String cubename) {108 109 string method = "PUT"; Para = "/cubes/" +cubename+ "/enable"; 111 return Excute (Para,method,null); 113}114/**116 * 117 * @param cubename Cube name.118 * @return119 */120 public static string Disablecube (String cubename) {121 122 String method = "PUT"; 123 string Para = "/cubes/" +cubename+ "/disable"; 124 return Excute (Para,method,null); 126}127/**129 * @param cubename Cube name.131 * @return132 */133 public static string Purgecube (String cubename) {134 135 String method = "PUT"; 136 string para = "/cube s/"+cubename+"/purge "137 return Excute (Para,method,null); 138 139}140 141 142/**143 * 144 * @param jobId Job id145 * @return146 */147 public static String re Sumejob (String jobId) {148 149 string method = "PUT"; string para = "/jobs/" +jobid+ "/resume"; 151 Return Excute (Para,method,null); 153}154 155 156/**157 * starttime-required long Start timestamp of data to build, e.g . 1388563200000 for 2014-1-1158 * endtime-required long End timestamp of data to build159 * buildtype-required String supported build Type: ' Build ', ' MERGE ', ' REFRESH ' * @param cubename Cube name.161 * @return162 */163 public static string Buildcube (String cubename,string body) {164 String method = "PUT"; 165 string Para = "/cubes/" +cubename+ "/rebuild"; 166 167 return Excute (para,method,body); 168}169 171/**172 * 173 * @param jobId Job id.174 * @return175 */176 Public Static StringDiscardjob (String jobId) {177 178 string method = "PUT"; 179 string para = "/jobs/" +jobid+ "/cancel"; 180 Return Excute (Para,method,null); 181 182}183 184/**185 * 186 * @param jobId Job id.187 * @return188 */189 PU Blic static string Getjobstatus (String jobId) {191 string method = "GET"; 192 string para = "/jobs/" +job id;193 return Excute (para,method,null); 194 195}196 197/**198 * 199 * @param jobId Job id.200 * @param stepid Step ID; The step ID is composed by jobId with step sequence ID; 201 * For example, the jobId is "fb479e54-837f-49a2-b457-651fc50be110", it 3rd Step ID 202 * is "fb479e54-837f- 49a2-b457-651fc50be110-3 ", 203 * @return204 */205 public static string Getjobstepoutput (string jobid,string s Tepid) {206 string method = "GET"; 207 string para = "/" +jobid+ "/steps/" +stepid+ "/output"; 208 return Excute (PARa,method,null); 209}210 211/**212 * 213 * @param tableName table name to find.214 * @return215 */216 public static string Gethivetable (String tableName) {217 string method = "GET"; 218 string para = "/tables/ "+tablename;219 return Excute (para,method,null); }221 222/**223 * 224 * @param tableName table name to find.225 * @return226 */227 public static string Gethivetableinfo (String tableName) {228 string method = "GET"; 229 string para = "/ta Bles/"+tablename+"/exd-map ", Return Excute (Para,method,null); 231}232 233 234/**235 * 236 * @param projectName would list all tables in the project.237 * @p Aram Extoptional Boolean set true to get extend info of table.238 * @return239 */240 public static String ge Thivetables (String Projectname,boolean extoptional) {241 string method = "GET"; 242 string para = "/tables?project= "+projectname+" &ext= "+extoptional;243 return Excute (para,method,null); 244}245 246 247/**248 * 249 * @param tables table names you want to load from hive, separated With comma.250 * @param project the project which the tables would be loaded into.251 * @return252 */253 public static string Loadhivetables (String Tables,string project) {254 string method = "POST"; 255 string Para = "/tables/" +tables+ "/" +project;256 return Excute (para,method,null); 257}258 259/**260 * 261 * @param type ' METADATA ' or ' CUBE ' 262 * @param name Cache key, e.g t He cube name.263 * @param action ' create ', ' Update ' or ' drop ' */266 * @return265 public static Strin G Wipecache (string type,string name,string action) {267 string method = "POST"; 268 string para = "/cache/" + Type+ "/" +name+ "/" +action;269 return Excute (para,method,null); 270}271 272273 public static string query (string body) {274 string method = "POST"; 275 string para = "/query"; 276 277 return Excute (para,method,body) 278}279 280 281 282 private static String Excut E (String para,string method,string body) {283 284 StringBuilder out = new StringBuilder (); 285 try {286 URL url = new URL (baseurl+para); 287 HttpURLConnection connection = (httpurlconnection) url.openconnection (); 288 connection.setrequ Estmethod (method); 289 Connection.setdooutput (true); 290 Connection.setrequestproperty ("Authorization", "Basic" + E ncoding); 291 connection.setrequestproperty ("Content-type", "Application/json"); 292 if (body!=null) {293 byte[] outputinbytes = body.getbytes ("UTF-8"); 294 outp Utstream OS = Connection.getoutputstream (); 295 os.write (Outputinbytes); 296 Os.close (); 297}298 InputStream content = (InputStream) connection.getinputstream (); 299 BufferedReader in = new BufferedReader (new InputStreamReader (content)); String line;301 while (line = In.readline ())! = null) {302 out.append (line); 3 }304 In.close (); 305 connection.disconnect (); 306 307} catch (Exc Eption e) {308 e.printstacktrace (); 309}310 return out.tostring (); 311}312}
Reference:
Http://kylin.apache.org/docs15/howto/howto_use_restapi.html#authentication
Kylin Java RESTful API