com.hadoopz.cloud.JCloud.SDK.utils.TablesFinder Maven / Gradle / Ivy
The newest version!
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.hadoopz.cloud.JCloud.SDK.utils;
import com.mycomm.IProtocol.log.UniversalLogHolder;
import com.mycomm.YesHttp.core.HttpMethod;
import com.mycomm.YesHttp.core.Request;
import com.mycomm.YesHttp.core.Response;
import com.mycomm.YesHttp.core.StringRequest;
import com.mycomm.YesHttp.core.TextBaseResponseListener;
import com.mycomm.YesHttp.core.YesHttpEngine;
import com.mycomm.YesHttp.core.YesHttpError;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
/**
*
* @author jw362j
*/
public class TablesFinder {
public List getTables(final String jcloudToken) {
final StringBuilder result = new StringBuilder();
String url = EndpointBuilder.getFullUrlForTablesLoader();
//final JSONObject ps = new JSONObject();
Request request = new StringRequest(HttpMethod.POST, url, new TextBaseResponseListener() {
@Override
public void responseMe(String msg) {
try {
YesLog.yeslog.d("the requestjSON TextBaseResponseListener.responseMe:" + msg);
JSONObject response = new JSONObject(msg);
if (response.has("datas")) {
result.append(response.getString("datas"));
}
} catch (JSONException ex) {
UniversalLogHolder.d(getClass().getSimpleName(), ex.getMessage());
}
}
}, new Response.ErrorListener() {
public void onErrorResponse(YesHttpError error) {
YesLog.yeslog.e("the requestjSON ErrorListener.onErrorResponse:" + error.getMessage());
}
}, YesLog.yeslog, Request.Protocol.HTTP) {
@Override
public void getHeaders(Map headers) {
headers.put("Authorization", jcloudToken);
}
@Override
public void getParams(Map ps) {
ps.put("jcloudToken", jcloudToken); //To change body of generated methods, choose Tools | Templates.
}
};
YesHttpEngine.getYesHttpEngine().send(request);
if (result.length() <= 0) {
return null;
}
List response = new ArrayList();
if (!result.toString().contains(",")) {
response.add(result.toString());
return response;
}
response.addAll(Arrays.asList(result.toString().split(",")));
return response;
}
}