Search in sources :

Example 91 with JSONObject

use of net.sf.json.JSONObject in project summer-mis by cn-cerc.

the class JuheSMS method sendByTemplateId.

// 2.发送短信
public boolean sendByTemplateId(String templateId, String templateValues) {
    String result = null;
    // 请求接口地址
    String url = "http://v.juhe.cn/sms/send";
    // 请求参数
    Map<String, Object> params = new HashMap<>();
    // 接收短信的手机号码
    params.put("mobile", mobile);
    // 短信模板ID,请参考个人中心短信模板设置
    params.put("tpl_id", templateId);
    // 变量名和变量值对。如果你的变量名或者变量值中带有#&=中的任意一个特殊符号,请先分别进行urlencode编码后再传递,<a
    params.put("tpl_value", templateValues);
    // href="http://www.juhe.cn/news/index/id/50"
    // target="_blank">详细说明></a>
    // 应用APPKEY(应用详细页查询)
    params.put("key", APPKEY);
    // 返回数据的格式,xml或json,默认json
    params.put("dtype", "");
    try {
        result = post(url, params, "GET");
        JSONObject object = JSONObject.fromObject(result);
        if (object.getInt("error_code") == 0) {
            log.info(object.get("result"));
            this.message = object.getString("result");
            log.info(String.format("send: %s, templateId: %s, result: %s", mobile, templateId, message));
            return true;
        } else {
            this.message = object.get("error_code") + ":" + object.get("reason");
            log.warn(String.format("send: %s, templateId: %s, result: %s", mobile, templateId, message));
            return false;
        }
    } catch (Exception e) {
        this.message = e.getMessage();
        log.error(String.format("send: %s, templateId: %s, result: %s", mobile, templateId, message));
        return false;
    }
}
Also used : JSONObject(net.sf.json.JSONObject) HashMap(java.util.HashMap) JSONObject(net.sf.json.JSONObject) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 92 with JSONObject

use of net.sf.json.JSONObject in project beijingThirdPeriod by weidongcao.

the class TestSpringOracle method testSpringConnectionOracle.

private static void testSpringConnectionOracle() {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("spring-module.xml");
    FtpDao ftpDao = (FtpDao) context.getBean("ftpDao");
    // 获取数据库一天的数据
    RegContentFtp ftp = ftpDao.getFtpById(1905067);
    JSONObject jsonObject = JSONObject.fromObject(ftp);
    System.out.println(jsonObject.toString());
    context.close();
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) JSONObject(net.sf.json.JSONObject) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RegContentFtp(com.rainsoft.domain.RegContentFtp) FtpDao(com.rainsoft.dao.FtpDao)

Example 93 with JSONObject

use of net.sf.json.JSONObject in project beijingThirdPeriod by weidongcao.

the class JsonUtils method getJsonValueByFile.

/**
 * 根据json配置文件及key获取Value类型为JSONArray的值
 * @param path 配置文件路径,此文件一定要在根目录下
 * @param key key
 * @return value
 */
public static JSONArray getJsonValueByFile(String path, String key) {
    InputStream in = JsonUtils.class.getClassLoader().getResourceAsStream(path);
    String oracleTableFieldsJson = null;
    try {
        oracleTableFieldsJson = IOUtils.toString(in, "utf-8");
    } catch (IOException e) {
        e.printStackTrace();
    }
    JSONObject jsonObject = JSONObject.fromObject(oracleTableFieldsJson);
    return jsonObject.optJSONArray(key);
}
Also used : JSONObject(net.sf.json.JSONObject) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 94 with JSONObject

use of net.sf.json.JSONObject in project jmeter-plugins-manager by undera.

the class RepoTest method checkPlugin.

private void checkPlugin(List<String> problems, File repoFile, JSONObject spec) {
    Plugin plugin = Plugin.fromJSON(spec);
    if (plugin.isVirtual()) {
        return;
    }
    String maxVersion = plugin.getMaxVersion();
    JSONObject maxVerObject = spec.getJSONObject("versions").getJSONObject(maxVersion);
    JSONObject newVersions = new JSONObject();
    newVersions.put(maxVersion, maxVerObject);
    try {
        System.out.println("Checking plugin: " + plugin);
        plugin.setCandidateVersion(maxVersion);
        plugin.download(jarSource, dummy);
        if (!plugin.isVersionFrozenToJMeter()) {
            File jar = new File(plugin.getTempName());
            File dest = new File(plugin.getDestName());
            File to = new File(libExt.getAbsolutePath() + File.separator + dest.getName());
            jar.renameTo(to);
            maxVerObject.put("downloadUrl", "lib/ext/" + dest.getName());
        }
    } catch (Throwable e) {
        problems.add(repoFile.getName() + ":" + plugin);
        System.err.println("Problem with " + plugin);
        e.printStackTrace(System.err);
    }
    checkLibs(problems, repoFile, plugin, maxVerObject);
    if (!maxVerObject.isEmpty()) {
        newVersions.put(maxVersion, maxVerObject);
        spec.put("versions", newVersions);
    }
}
Also used : JSONObject(net.sf.json.JSONObject) File(java.io.File)

Example 95 with JSONObject

use of net.sf.json.JSONObject in project jmeter-plugins-manager by undera.

the class RepoTest method testAll.

public void testAll() throws IOException {
    Map<String, String> env = System.getenv();
    if (env.containsKey("TRAVIS")) {
        System.out.println("Not running test inside Travis CI");
        return;
    }
    List<String> problems = new ArrayList<>();
    File[] files = getRepoFiles();
    JSONArray merged = new JSONArray();
    for (File repoFile : files) {
        System.out.println("Checking repo: " + repoFile.getCanonicalPath());
        String content = new String(Files.readAllBytes(Paths.get(repoFile.getAbsolutePath())), "UTF-8");
        JSON json = JSONSerializer.toJSON(content, new JsonConfig());
        JSONArray list = (JSONArray) json;
        for (Object item : list) {
            JSONObject spec = (JSONObject) item;
            checkPlugin(problems, repoFile, spec);
            merged.add(spec);
        }
    }
    if (problems.size() > 0) {
        throw new AssertionFailedError(problems.toString());
    }
    try (PrintWriter out = new PrintWriter(new File(repo.getAbsolutePath() + s + "all.json"))) {
        out.print(merged.toString(1));
    }
}
Also used : JsonConfig(net.sf.json.JsonConfig) ArrayList(java.util.ArrayList) JSONArray(net.sf.json.JSONArray) JSON(net.sf.json.JSON) JSONObject(net.sf.json.JSONObject) JSONObject(net.sf.json.JSONObject) AssertionFailedError(junit.framework.AssertionFailedError) File(java.io.File) PrintWriter(java.io.PrintWriter)

Aggregations

JSONObject (net.sf.json.JSONObject)493 Test (org.junit.Test)99 JSONArray (net.sf.json.JSONArray)94 IOException (java.io.IOException)49 HashMap (java.util.HashMap)48 ArrayList (java.util.ArrayList)36 JSON (net.sf.json.JSON)26 PrintWriter (java.io.PrintWriter)25 Map (java.util.Map)23 File (java.io.File)21 InputStream (java.io.InputStream)18 URISyntaxException (java.net.URISyntaxException)15 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14 JsonConfig (net.sf.json.JsonConfig)14 FreeStyleBuild (hudson.model.FreeStyleBuild)13 URI (java.net.URI)13 URL (java.net.URL)13 JSONException (net.sf.json.JSONException)13 Context (org.zaproxy.zap.model.Context)12 Transactional (org.springframework.transaction.annotation.Transactional)11