Refine search
@Override public JSONObject createContent() { if (requestsByLanguage.size() == 0) { return null; } Map<String, AtomicLong> currentRequests = new TreeMap<>(requestsByLanguage); requestsByLanguage.clear(); JSONObject payload = new JSONObject(); for (Map.Entry<String, AtomicLong> entry : currentRequests.entrySet()) { payload.put(entry.getKey(), entry.getValue().longValue()); } return payload; }
/** * Create a JSON representation of a resource bundle * * @param bundle The resource bundle. * @return The bundle JSON. */ private static JSONObject toJSONObject(@Nonnull ResourceBundle bundle) { JSONObject json = new JSONObject(); for (String key : bundle.keySet()) { json.put(key, bundle.getString(key)); } return json; } }
/** * For internal use. */ @JavaScriptMethod public final JSONObject news() { lastNewsTime = System.currentTimeMillis(); JSONObject r = new JSONObject(); try { r.put("data", data()); } catch (RuntimeException x) { LOG.log(Level.WARNING, "failed to update " + uri, x); status = ERROR; } Object statusJSON = status == 1 ? "done" : status == CANCELED ? "canceled" : status == ERROR ? "error" : status; r.put("status", statusJSON); if (statusJSON instanceof String) { // somehow completed LOG.log(Level.FINE, "finished in news so releasing {0}", boundId); release(); } lastNewsTime = System.currentTimeMillis(); LOG.log(Level.FINER, "news from {0}", uri); return r; }
/** * Returns whether the system needs a restart, and if it is supported * e.g. { restartRequired: true, restartSupported: false } */ @Restricted(DoNotUse.class) // WebOnly public HttpResponse doRestartStatus() throws IOException { JSONObject response = new JSONObject(); Jenkins jenkins = Jenkins.get(); response.put("restartRequired", jenkins.getUpdateCenter().isRestartRequiredForCompletion()); response.put("restartSupported", jenkins.getLifecycle().canRestart()); return HttpResponses.okJSON(response); }
@Override protected void writeStatusBody(StaplerResponse response, Run<?, ?> build, BuildStatus status) { try { JSONObject object = new JSONObject(); object.put("sha", sha1); if (build != null) { object.put("id", build.getNumber()); } object.put("status", status.getValue()); writeBody(response, object); } catch (IOException e) { throw HttpResponses.error(500, "Failed to generate response"); } }
Jenkins j = Jenkins.getInstance(); JSONObject o = new JSONObject(); o.put("stat",1); o.put("install", j.getLegacyInstanceId()); o.put("servletContainer", j.servletContext.getServerInfo()); o.put("version", Jenkins.VERSION); JSONObject n = new JSONObject(); if(c.getNode()==j) { n.put("master",true); for( PluginWrapper pw : j.getPluginManager().getPlugins() ) { if(!pw.isActive()) continue; // treat disabled plugins as if they are uninstalled JSONObject p = new JSONObject(); p.put("name",pw.getShortName()); p.put("version",pw.getVersion()); o.put("plugins",plugins); JSONObject jobs = new JSONObject();
Map<String,JSONObject> allPlugins = new HashMap<>(); for (PluginWrapper plugin : plugins) { JSONObject pluginInfo = new JSONObject(); pluginInfo.put("installed", true); pluginInfo.put("name", plugin.getShortName()); pluginInfo.put("title", plugin.getDisplayName()); pluginInfo.put("active", plugin.isActive()); pluginInfo.put("enabled", plugin.isEnabled()); JSONObject pluginInfo = allPlugins.get(plugin.name); if(pluginInfo == null) { pluginInfo = new JSONObject(); pluginInfo.put("installed", false);
JSONObject data = new JSONObject(); try { data = telemetry.createContent(); JSONObject wrappedData = new JSONObject(); wrappedData.put("type", telemetry.getId()); wrappedData.put("payload", data); String correlationId = ExtensionList.lookupSingleton(Correlator.class).getCorrelationId(); wrappedData.put("correlator", DigestUtils.sha256Hex(correlationId + telemetry.getId()));
/** * Installs a list of plugins from a JSON POST. * @param req The request object. * @return A JSON response that includes a "correlationId" in the "data" element. * That "correlationId" can then be used in calls to * {@link UpdateCenter#doInstallStatus(org.kohsuke.stapler.StaplerRequest)}. * @throws IOException Error reading JSON payload fro request. */ @RequirePOST @Restricted(DoNotUse.class) // WebOnly public HttpResponse doInstallPlugins(StaplerRequest req) throws IOException { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); String payload = IOUtils.toString(req.getInputStream(), req.getCharacterEncoding()); JSONObject request = JSONObject.fromObject(payload); JSONArray pluginListJSON = request.getJSONArray("plugins"); List<String> plugins = new ArrayList<>(); for (int i = 0; i < pluginListJSON.size(); i++) { plugins.add(pluginListJSON.getString(i)); } UUID correlationId = UUID.randomUUID(); try { boolean dynamicLoad = request.getBoolean("dynamicLoad"); install(plugins, dynamicLoad, correlationId); JSONObject responseData = new JSONObject(); responseData.put("correlationId", correlationId.toString()); return hudson.util.HttpResponses.okJSON(responseData); } catch (Exception e) { return hudson.util.HttpResponses.errorJSON(e.getMessage()); } }
/** * @param list the list of layer identifiers to serialize * @return {@code null} if {@code list} is null, empty or contains only null objects; the JSON * array representation of {@code list} otherwise, with any null element stripped off. */ public static String toString(List<AuthorityURLInfo> obj) { if (obj == null || obj.isEmpty()) { return null; } JSONArray array = new JSONArray(); for (AuthorityURLInfo auth : obj) { if (auth == null) { continue; } JSONObject jsonAuth = new JSONObject(); jsonAuth.put(NAME, auth.getName()); jsonAuth.put(HREF, auth.getHref()); array.add(jsonAuth); } if (array.size() == 0) { // list was made of only null objects? return null; } String serialized = array.toString(); return serialized; } }
/** * @param list the list of auth urls to serialize * @return {@code null} if {@code list} is null, empty, or contains only null objects; the JSON * array representation of {@code list} otherwise, with any null element stripped off. */ public static String toString(List<LayerIdentifierInfo> list) { if (list == null || list.isEmpty()) { return null; } JSONArray array = new JSONArray(); for (LayerIdentifierInfo id : list) { if (id == null) { continue; } JSONObject jsonId = new JSONObject(); jsonId.put(AUTHORITY, id.getAuthority()); jsonId.put(IDENTIFIER, id.getIdentifier()); array.add(jsonId); } if (array.size() == 0) { // list was made of only null objects? return null; } String serialized = array.toString(); return serialized; } }
public static JSONObject getJsonObject(String key, String value) { JSONObject json = new JSONObject(); json.put(key, value); return json; }
public static JSONObject getJson(int code) { JSONObject json = new JSONObject(); json.put("code",code); return json; } public static JSONObject getJson(int code, String msg) {
public static JSONObject getJson(String code , String message) { // TODO Auto-generated method stub JSONObject json = new JSONObject(); json.put("code", code); json.put("msg", message); return json; }
public static JSONObject getErrJson(int code, String message) { final JSONObject json = new JSONObject(); json.put("code", code); json.put("msg", message); return json; }
public static JSONObject getOkJson(String msg) { JSONObject json = new JSONObject(); json.put("code", JSON_CODE_OK); json.put("msg", msg); return json; }
public static JSONObject getErrorJsonResult(String message) { JSONObject json = new JSONObject(); json.put("statusCode", 300); json.put("message", message); return json; }
public static JSONObject getTechnicianJson(String message) { // TODO Auto-generated method stub JSONObject json = new JSONObject(); json.put("code", "20003"); json.put("msg", message); return json; }
public static JSONObject getJson(int code, String msg) { JSONObject json = new JSONObject(); json.put("code", code+""); json.put("msg", msg); return json; }
public static JSONObject getJson(int code, int left) { JSONObject json = new JSONObject(); json.put("code", code); json.put("left", left); return json; }