use of us.monoid.json.JSONException in project tdi-studio-se by Talend.
the class ExchangeWebService method searchContributedExtensionJSONArray.
/**
*
* DOC hcyi Comment method "searchContributedExtensionJSONArray".
*
* @return
*/
public static JSONArray searchContributedExtensionJSONArray(String username, String passwordHash) {
JSONObject tokenMessage = new JSONObject();
JSONArray o = null;
try {
tokenMessage.put("username", username);
tokenMessage.put("passwordHash", passwordHash);
JSONObject token = new us.monoid.json.JSONObject();
token.put("contributedExtension", tokenMessage);
String u = exchangeWSServer + "contributedExtension.php?data=" + token;
JSONObject answer = readJsonFromUrl(u);
if (answer != null) {
JSONObject p = (JSONObject) answer.get("listContributedExtension");
o = p.getJSONArray("extensions");
}
} catch (JSONException e) {
//
} catch (IOException e) {
e.printStackTrace();
}
return o;
}
use of us.monoid.json.JSONException in project tdi-studio-se by Talend.
the class ExchangeWebService method insertionExtensionService.
/**
*
* DOC hcyi Comment method "insertionExtensionService".
*
* @param typeExtension
* @param username
* @param passwordHash
* @param category
* @param name
* @param description
* @return
*/
public static WebserviceStatus insertionExtensionService(String typeExtension, String username, String passwordHash, String category, String name, String description) {
WebserviceStatus ws = new WebserviceStatus();
ws.setResult(false);
Resty r = new Resty();
JSONObject tokenMessage = new JSONObject();
try {
tokenMessage.put("username", username);
tokenMessage.put("passwordHash", passwordHash);
tokenMessage.put("typeExtension", typeExtension);
tokenMessage.put("category", category);
tokenMessage.put("name", name);
tokenMessage.put("description", description);
JSONObject token = new us.monoid.json.JSONObject();
token.put("newExtension", tokenMessage);
AbstractContent ac = Resty.content(token);
MultipartContent mpc = Resty.form(new FormData("data", ac));
TextResource textResult = r.text(exchangeWSServer + "publishExtension.php", mpc);
JSONObject resultObject = new JSONObject(textResult.toString());
JSONObject object = (JSONObject) resultObject.get("resultNewExtension");
String idExtension = object.getString("idExtension");
//
ws.setValue(idExtension);
ws.setResult(true);
//$NON-NLS-1$
ws.setMessageException(Messages.getString("ExchangeWebService.insertionExtensionSuccessful"));
} catch (JSONException e) {
ws.setMessageException(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
ws.setMessageException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
ws.setMessageException(e.getMessage());
}
return ws;
}
use of us.monoid.json.JSONException in project tdi-studio-se by Talend.
the class ExchangeWebService method insertionRevisionService.
/**
*
* DOC hcyi Comment method "insertionRevisionService".
*
* @param idExtension
* @param typeExtension
* @param username
* @param passwordHash
* @param version
* @param listVersionCompatibles
* @param filename
* @param content
* @param description
* @param agreement
* @return
*/
public static WebserviceStatus insertionRevisionService(String idExtension, String typeExtension, String username, String passwordHash, String version, String listVersionCompatibles, String filename, String content, String description, String agreement) {
byte[] fileBytes = null;
try {
File f = new File(filename);
if (f != null) {
FileInputStream fis = new FileInputStream(f);
if (fis != null) {
int len = fis.available();
fileBytes = new byte[len];
fis.read(fileBytes);
}
}
} catch (Exception e) {
//
}
WebserviceStatus ws = new WebserviceStatus();
ws.setResult(false);
Resty r = new Resty();
JSONObject tokenMessage = new JSONObject();
try {
tokenMessage.put("username", username);
tokenMessage.put("passwordHash", passwordHash);
tokenMessage.put("idExtension", idExtension);
tokenMessage.put("typeExtension", typeExtension);
tokenMessage.put("version", version);
tokenMessage.put("versionCompatibles", listVersionCompatibles);
tokenMessage.put("filename", new Path(filename).lastSegment());
tokenMessage.put("content", asHex(fileBytes));
tokenMessage.put("description", description == null ? "" : description.replace(" ", "%20"));
tokenMessage.put("agreement", agreement);
JSONObject token = new us.monoid.json.JSONObject();
token.put("newRevision", tokenMessage);
AbstractContent ac = Resty.content(token);
MultipartContent mpc = Resty.form(new FormData("data", ac));
TextResource textResult = r.text(exchangeWSServer + "addRevision.php", mpc);
JSONObject resultObject = new JSONObject(textResult.toString());
JSONObject result = (JSONObject) resultObject.get("resultNewRevision");
String idRevision = result.getString("idRevision");
//
ws.setValue(idRevision);
ws.setResult(true);
//$NON-NLS-1$
ws.setMessageException(Messages.getString("ExchangeWebService.insertionRevisionSuccessful"));
} catch (JSONException e) {
ws.setMessageException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
ws.setMessageException(e.getMessage());
}
return ws;
}
use of us.monoid.json.JSONException in project tdi-studio-se by Talend.
the class ExchangeWebService method downloadingExtensionService.
/**
*
* DOC hcyi Comment method "downloadingExtensionService".
*
* @param idExtension
* @param typeExtension
* @param username
* @param passwordHash
* @return
*/
public static WebserviceStatus downloadingExtensionService(String idExtension, String typeExtension, String username, String passwordHash) {
WebserviceStatus ws = new WebserviceStatus();
ws.setResult(false);
JSONObject tokenMessage = new JSONObject();
try {
tokenMessage.put("typeExtension", typeExtension);
tokenMessage.put("idExtension", idExtension);
tokenMessage.put("username", username);
tokenMessage.put("passwordHash", passwordHash);
JSONObject token = new us.monoid.json.JSONObject();
token.put("downloadedExtension", tokenMessage);
String u = exchangeWSServer + "downloadedExtension.php?data=" + token;
JSONObject answer = readJsonFromUrl(u);
if (answer != null) {
JSONObject resultObj = (JSONObject) answer.get("resultDownloadExtension");
String linkDownload = resultObj.getString("linkDownload");
//
ws.setValue(linkDownload);
ws.setResult(true);
//$NON-NLS-1$
ws.setMessageException(Messages.getString("ExchangeWebService.downloadingExtensionSuccessful"));
}
} catch (JSONException e) {
//
ws.setMessageException(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
ws.setMessageException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
ws.setMessageException(e.getMessage());
}
return ws;
}
use of us.monoid.json.JSONException in project tdi-studio-se by Talend.
the class JobVMArgumentsUtil method readString.
public List<String> readString(String stringList) {
if (stringList == null || "".equals(stringList)) {
//$NON-NLS-1$
return EMPTY_STRING_LIST;
}
ArrayList<String> result = new ArrayList<String>(50);
try {
JSONObject root = new JSONObject(stringList);
//$NON-NLS-1$
Object obj = root.get("JOB_RUN_VM_ARGUMENTS");
if (obj != null && (obj instanceof JSONArray)) {
JSONArray array = (JSONArray) obj;
for (int i = 0; i < array.length(); i++) {
result.add((String) array.get(i));
}
}
} catch (JSONException e) {
ExceptionHandler.process(e);
}
return result;
}
Aggregations