Search in sources :

Example 16 with JSONException

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;
}
Also used : JSONObject(us.monoid.json.JSONObject) JSONArray(us.monoid.json.JSONArray) JSONException(us.monoid.json.JSONException) IOException(java.io.IOException)

Example 17 with JSONException

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;
}
Also used : FormData(us.monoid.web.FormData) TextResource(us.monoid.web.TextResource) JSONObject(us.monoid.json.JSONObject) AbstractContent(us.monoid.web.AbstractContent) Resty(us.monoid.web.Resty) JSONException(us.monoid.json.JSONException) MultipartContent(us.monoid.web.mime.MultipartContent) IOException(java.io.IOException) JSONException(us.monoid.json.JSONException) IOException(java.io.IOException)

Example 18 with JSONException

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;
}
Also used : Path(org.eclipse.core.runtime.Path) FormData(us.monoid.web.FormData) TextResource(us.monoid.web.TextResource) AbstractContent(us.monoid.web.AbstractContent) JSONException(us.monoid.json.JSONException) MultipartContent(us.monoid.web.mime.MultipartContent) FileInputStream(java.io.FileInputStream) JSONException(us.monoid.json.JSONException) IOException(java.io.IOException) JSONObject(us.monoid.json.JSONObject) Resty(us.monoid.web.Resty) File(java.io.File)

Example 19 with JSONException

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;
}
Also used : JSONObject(us.monoid.json.JSONObject) JSONException(us.monoid.json.JSONException) IOException(java.io.IOException) JSONException(us.monoid.json.JSONException) IOException(java.io.IOException)

Example 20 with JSONException

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;
}
Also used : JSONObject(us.monoid.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(us.monoid.json.JSONArray) JSONException(us.monoid.json.JSONException) JSONObject(us.monoid.json.JSONObject)

Aggregations

JSONException (us.monoid.json.JSONException)20 JSONObject (us.monoid.json.JSONObject)20 IOException (java.io.IOException)15 JSONArray (us.monoid.json.JSONArray)9 AbstractContent (us.monoid.web.AbstractContent)5 FormData (us.monoid.web.FormData)5 Resty (us.monoid.web.Resty)5 TextResource (us.monoid.web.TextResource)5 MultipartContent (us.monoid.web.mime.MultipartContent)5 ArrayList (java.util.ArrayList)4 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 Path (org.eclipse.core.runtime.Path)1 EList (org.eclipse.emf.common.util.EList)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 Project (org.talend.core.model.general.Project)1 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)1 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)1 RoutineItem (org.talend.core.model.properties.RoutineItem)1 SQLPatternItem (org.talend.core.model.properties.SQLPatternItem)1