List of usage examples for org.json.simple JSONObject toJSONString
public String toJSONString()
From source file:ch.simas.jtoggl.JToggl.java
/** * Stop the given time entry./*from w w w .ja v a2 s.c o m*/ * * @param timeEntry * to time entry to stop * @return the stopped {@link TimeEntry} */ public TimeEntry stopTimeEntry(TimeEntry timeEntry) { Client client = prepareClient(); String url = TIME_ENTRY_STOP.replace(PLACEHOLDER, timeEntry.getId().toString()); WebResource webResource = client.resource(url); JSONObject object = createTimeEntryRequestParameter(timeEntry); String response = webResource.entity(object.toJSONString(), MediaType.APPLICATION_JSON_TYPE) .put(String.class); object = (JSONObject) JSONValue.parse(response); JSONObject data = (JSONObject) object.get(DATA); return new TimeEntry(data.toJSONString()); }
From source file:ch.simas.jtoggl.JToggl.java
/** * Update a time entry.// ww w . ja va 2 s . co m * * @param timeEntry * @return created {@link TimeEntry} */ public TimeEntry updateTimeEntry(TimeEntry timeEntry) { Client client = prepareClient(); String url = TIME_ENTRY.replace(PLACEHOLDER, timeEntry.getId().toString()); WebResource webResource = client.resource(url); JSONObject object = createTimeEntryRequestParameter(timeEntry); String response = webResource.entity(object.toJSONString(), MediaType.APPLICATION_JSON_TYPE) .put(String.class); object = (JSONObject) JSONValue.parse(response); JSONObject data = (JSONObject) object.get(DATA); return new TimeEntry(data.toJSONString()); }
From source file:ch.simas.jtoggl.JToggl.java
/** * Update a client./*from w w w . ja v a 2s.c om*/ * * @param clientObject * @return updated {@link ch.simas.jtoggl.Client} */ public ch.simas.jtoggl.Client updateClient(ch.simas.jtoggl.Client clientObject) { Client client = prepareClient(); String url = CLIENT.replace(PLACEHOLDER, clientObject.getId().toString()); WebResource webResource = client.resource(url); JSONObject object = createClientRequestParameter(clientObject); String response = webResource.entity(object.toJSONString(), MediaType.APPLICATION_JSON_TYPE) .put(String.class); object = (JSONObject) JSONValue.parse(response); JSONObject data = (JSONObject) object.get(DATA); return new ch.simas.jtoggl.Client(data.toJSONString()); }
From source file:ch.simas.jtoggl.JToggl.java
/** * Create a new project user.// w ww . j a v a2 s .c o m * * @param projectUser * @return created {@link ProjectUser} */ public ProjectUser createProjectUser(ProjectUser projectUser) { Client client = prepareClient(); WebResource webResource = client.resource(PROJECT_USERS); JSONObject object = createProjectUserRequestParameter(projectUser); String response = webResource.entity(object.toJSONString(), MediaType.APPLICATION_JSON_TYPE) .post(String.class); object = (JSONObject) JSONValue.parse(response); JSONObject data = (JSONObject) object.get(DATA); return new ProjectUser(data.toJSONString()); }
From source file:HttpClient.HttpCalendarClient.java
private String send_request(JSONObject req, String operation) { String success = null;/*from w ww .j a v a 2s . c om*/ //imposto il "contenitore" della risposta JSON CloseableHttpResponse response1 = null; //creo una richiesta di tipo POSTal WS HttpPost r_post = new HttpPost(url + operation); //imposto l'HEADER della richiesta a JSON r_post.addHeader(new BasicHeader("Content-Type", "application/json")); //Creo l'entita' da inserire nella richiesta, ipostandone come contenuto il JSON StringEntity param = new StringEntity(req.toJSONString(), "UTF8"); param.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); r_post.setEntity(param); //EFFETTUO LA RICHIESTA try { //EFFETTUO la richiesta ed attendo la risposta dal WS response1 = httpclient.execute(r_post); if (response1.getEntity() != null) { //converto lo stream ottenuto in un oggetto JSON JSONObject risposta = convertStreamToJson(response1.getEntity().getContent()); if (risposta != null) { String result = (String) risposta.get("code"); if (result.equalsIgnoreCase("201")) { success = (String) risposta.get("id"); } } } } catch (IOException ex) { Logger.getLogger(HttpCalendarClient.class.getName()).log(Level.SEVERE, null, ex); } finally { try { response1.close(); } catch (IOException ex) { Logger.getLogger(HttpCalendarClient.class.getName()).log(Level.SEVERE, null, ex); } } return success; }
From source file:edu.iu.incntre.flowscale.FlowscaleController.java
/** * Method called from flowscalehttplistener (may be called also from cli) in * order to create a new group not that this method will NOT store the deta * in the database at the time being, that will be done by the calling * interface itself/*ww w. j a v a 2s .c om*/ * * @param groupIdString * @param groupName * @param inputSwitchDatapathIdString * @param outputSwitchDatapathIdString * @param inputPortListString * @param outputPortListString * @param typeString * @param priorityString * @param valuesString * @param maximumFlowsAllowedString * @param networkProtocolString * @param transportDirectionString * @return a string that will be presented in JSON format to be interpreted * by the interface */ public String addGroupFromInterface(String groupIdString, String groupName, String inputSwitchDatapathIdString, String outputSwitchDatapathIdString, String inputPortListString, String outputPortListString, String typeString, String priorityString, String valuesString, String maximumFlowsAllowedString, String networkProtocolString, String transportDirectionString) { Group g = new Group(this); g.addGroupDetails(groupIdString, groupName, inputSwitchDatapathIdString, outputSwitchDatapathIdString, inputPortListString, outputPortListString, typeString, priorityString, valuesString, maximumFlowsAllowedString, networkProtocolString, transportDirectionString); g.pushRules(); groupList.put(Integer.parseInt(groupIdString), g); JSONObject jsonObject = new JSONObject(); jsonObject.put("result", "group added"); return jsonObject.toJSONString(); }
From source file:ch.simas.jtoggl.JToggl.java
/** * Get running time entry//w ww. jav a2 s. c om * * @return The running time entry or null if none */ public TimeEntry getCurrentTimeEntry() { Client client = prepareClient(); WebResource webResource = client.resource(CURRENT_TIME_ENTRY); String response = null; try { response = webResource.get(String.class); } catch (UniformInterfaceException uniformInterfaceException) { return null; } JSONObject object = (JSONObject) JSONValue.parse(response); JSONObject data = (JSONObject) object.get(DATA); if (data == null) return null; return new TimeEntry(data.toJSONString()); }
From source file:ch.simas.jtoggl.JToggl.java
/** * Get a time entry.//from w ww . j a va 2s .c o m * * @param id * @return TimeEntry or null if no Entry is found. */ public TimeEntry getTimeEntry(Long id) { Client client = prepareClient(); String url = TIME_ENTRY.replace(PLACEHOLDER, id.toString()); WebResource webResource = client.resource(url); String response = null; try { response = webResource.get(String.class); } catch (UniformInterfaceException uniformInterfaceException) { return null; } JSONObject object = (JSONObject) JSONValue.parse(response); JSONObject data = (JSONObject) object.get(DATA); if (data == null) return null; return new TimeEntry(data.toJSONString()); }
From source file:com.fujitsu.dc.core.rs.StatusResource.java
/** * GET???./*from w ww . j a v a2s . co m*/ * @return JAS-RS Response */ @SuppressWarnings("unchecked") @GET @Produces("application/json") public Response get() { StringBuilder sb = new StringBuilder(); // Properties props = DcCoreConfig.getProperties(); JSONObject responseJson = new JSONObject(); JSONObject propertiesJson = new JSONObject(); for (String key : props.stringPropertyNames()) { String value = props.getProperty(key); propertiesJson.put(key, value); } responseJson.put("properties", propertiesJson); // Cell?/ //responseJson.put("service", checkServiceStatus()); // Ads?? responseJson.put("ads", checkAds()); // ElasticSearch Health EsClient client = EsModel.client(); JSONObject esJson = new JSONObject(); esJson.put("health", client.checkHealth()); responseJson.put("ElasticSearch", esJson); sb.append(responseJson.toJSONString()); return Response.status(HttpStatus.SC_OK).entity(sb.toString()).build(); }
From source file:com.mcapanel.web.controllers.SettingsController.java
@SuppressWarnings("unchecked") public boolean updateLicense() throws IOException { if (isMethod("POST")) { includeIndex(false);/* w w w .ja v a2s. co m*/ mimeType("application/json"); JSONObject obj = new JSONObject(); if (isLoggedIn() && user.getGroup().hasPermission("mcapanel.properties.edit")) { String licemail = request.getParameter("licemail"); String lickey = request.getParameter("lickey"); config.setValue("license-email", licemail); config.setValue("license-key", lickey); config.saveConfig(); obj.put("good", "Successfully updated your license!"); } else obj.put("error", "You do not have permission to do that."); response.getWriter().println(obj.toJSONString()); return true; } return error(); }