Search in sources :

Example 1 with JSONException

use of us.monoid.json.JSONException in project tdi-studio-se by Talend.

the class ExchangeService method checkUserAndPass.

@Override
public String checkUserAndPass(String username, String password) {
    String errorMessage = "Wrong user or password";
    if (username == null || "".equals(username) || password == null || "".equals(password)) {
        return errorMessage;
    }
    JSONObject tokenMessage = new JSONObject();
    try {
        tokenMessage.put("username", username);
        tokenMessage.put("passwordHash", password);
        JSONObject token = new us.monoid.json.JSONObject();
        token.put("contributedExtension", tokenMessage);
        String u = ExchangeWebService.exchangeWSServer + "contributedExtension.php?data=" + token;
        JSONObject answer = ExchangeWebService.readJsonFromUrl(u);
        if (answer != null && answer.get("result") != null && answer.get("result").equals("ERROR USERNAME/PASSWORD")) {
            return errorMessage;
        }
    } catch (JSONException e) {
        // if there is no result , user and pass are right and can list the extensions
        return null;
    } catch (IOException e) {
        return errorMessage;
    }
    return null;
}
Also used : JSONObject(us.monoid.json.JSONObject) JSONException(us.monoid.json.JSONException) IOException(java.io.IOException)

Example 2 with JSONException

use of us.monoid.json.JSONException in project tdi-studio-se by Talend.

the class ExchangeWebService method searchExtensionJSONArray.

/**
     * 
     * DOC hcyi Comment method "searchExtensionJSONArray".
     * 
     * @return
     */
public static JSONArray searchExtensionJSONArray(String typeExtension, String versionStudio, String category) {
    JSONObject tokenMessage = new JSONObject();
    JSONArray o = null;
    try {
        tokenMessage.put("typeExtension", typeExtension);
        tokenMessage.put("versionStudio", versionStudio);
        tokenMessage.put("search", category);
        JSONObject token = new us.monoid.json.JSONObject();
        token.put("searchExtension", tokenMessage);
        String u = exchangeWSServer + "availableExtension.php?data=" + token;
        JSONObject answer = readJsonFromUrl(u);
        if (answer != null) {
            JSONObject p = (JSONObject) answer.get("resultSearch");
            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 3 with JSONException

use of us.monoid.json.JSONException in project tdi-studio-se by Talend.

the class ExchangeWebService method webServiceToken.

public void webServiceToken(String[] args) {
    Resty r = new Resty();
    JSONObject token = new us.monoid.json.JSONObject();
    try {
        JSONObject tokenMessage = new JSONObject();
        tokenMessage.put("version", "4.2.2r56343");
        tokenMessage.put("uniqueId", "XXXXXX");
        tokenMessage.put("typeStudio", "TOS");
        JSONObject properties = new JSONObject();
        properties.put("tos.count.localprojects", "10");
        properties.put("tos.count.jobs", "48");
        properties.put("tos.count.jobsperproject", "5");
        // ... //
        tokenMessage.put("properties", properties);
        token.put("tokenStudio", tokenMessage);
        AbstractContent ac = Resty.content(token);
        MultipartContent mpc = Resty.form(new FormData("data", ac));
        TextResource result = r.text("http://www.talend.com/TalendRegisterWS/tokenstudio.php", mpc);
        System.out.println(result.toString());
    } catch (JSONException e) {
    //
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
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 4 with JSONException

use of us.monoid.json.JSONException in project tdi-studio-se by Talend.

the class ExchangeWebService method searchExtensionViewDetail.

public static JSONObject searchExtensionViewDetail(String idExtension, String typeExtension) {
    Resty r = new Resty();
    JSONObject token = new us.monoid.json.JSONObject();
    JSONObject extension = new us.monoid.json.JSONObject();
    try {
        JSONObject tokenMessage = new JSONObject();
        tokenMessage.put("typeExtension", typeExtension);
        tokenMessage.put("idExtension", idExtension);
        token.put("viewDetail", tokenMessage);
        AbstractContent ac = Resty.content(token);
        MultipartContent mpc = Resty.form(new FormData("data", ac));
        TextResource result = r.text(exchangeWSServer + "availableExtension.php", mpc);
        JSONObject jbo = new JSONObject(result.toString());
        JSONObject resultViewDetail = jbo.getJSONObject("resultViewDetail");
        extension = resultViewDetail.getJSONObject("extension");
    } catch (JSONException e) {
    //
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return extension;
}
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 5 with JSONException

use of us.monoid.json.JSONException in project tdi-studio-se by Talend.

the class ExchangeWebService method insertReviewService.

/**
     * 
     * DOC hcyi Comment method "insertReviewService".
     * 
     * @param idExtension
     * @param typeExtension
     * @param username
     * @param passwordHash
     * @param title
     * @param description
     * @param userRating
     * @return
     */
public static WebserviceStatus insertReviewService(String idExtension, String typeExtension, String username, String passwordHash, String title, String description, String userRating) {
    WebserviceStatus ws = new WebserviceStatus();
    ws.setResult(false);
    Resty r = new Resty();
    JSONObject tokenMessage = new JSONObject();
    try {
        tokenMessage.put("typeExtension", typeExtension);
        tokenMessage.put("idExtension", idExtension);
        tokenMessage.put("username", username);
        tokenMessage.put("passwordHash", passwordHash);
        tokenMessage.put("title", title);
        tokenMessage.put("description", description);
        tokenMessage.put("userRating", userRating);
        JSONObject token = new us.monoid.json.JSONObject();
        token.put("review", tokenMessage);
        AbstractContent ac = Resty.content(token);
        MultipartContent mpc = Resty.form(new FormData("data", ac));
        TextResource textResult = r.text(exchangeWSServer + "downloadedExtension.php", mpc);
        JSONObject resultObject = new JSONObject(textResult.toString());
        //
        Object object = resultObject.get("result");
        if (object != null && object.equals("INSERT OK")) {
            ws.setResult(true);
            //$NON-NLS-1$
            ws.setMessageException(Messages.getString("ExchangeWebService.insertReviewSuccessful"));
        } else {
            ws.setMessageException(object.toString());
        }
    } 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) JSONObject(us.monoid.json.JSONObject) IOException(java.io.IOException) JSONException(us.monoid.json.JSONException) IOException(java.io.IOException)

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