List of usage examples for org.json JSONObject toString
public String toString()
From source file:org.wso2.carbon.connector.integration.test.flickr.FlickrConnectoreIntegrationTest.java
/** * Positive test case for getPhotos method with Optional parameters. */// w ww. ja v a 2 s.co m @Test(priority = 3, groups = { "wso2.esb" }, description = "flickr {getPhotos} integration test with Optional parameters") public void testFlickrGetPhotosWithOptionalParameters() throws Exception { String jsonRequestFilePath = pathToRequestsDirectory + "optional/" + "flickr_getPhotos.txt"; String methodName = "flickr_getPhotos"; String rawString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath); rawString = rawString.replace("dummyvalue", flickrConnectorProperties.getProperty("userId")); rawString = rawString.replace("dummyminuploaddate", flickrConnectorProperties.getProperty("minDate")); rawString = rawString.replace("dummymaxuploaddate", flickrConnectorProperties.getProperty("maxDate")); rawString = rawString.replace("dummymaxtakendate", flickrConnectorProperties.getProperty("maxDate")); rawString = rawString.replace("dummymintakendate", flickrConnectorProperties.getProperty("minDate")); rawString = rawString.replace("dummyextra", flickrConnectorProperties.getProperty("extraInfo")); final String jsonString = addCredentials(rawString); final String proxyFilePath = "file:///" + pathToProxiesDirectory + "optional/" + methodName + ".xml"; proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath))); try { JSONObject responseConnector = ConnectorIntegrationUtil.sendRequest("POST", getProxyServiceURL(methodName), jsonString); String httpMethod = "GET"; String parameters = "format=json&nojsoncallback=1&method=flickr.people.getPhotos&api_key=" + flickrConnectorProperties.getProperty("consumerKey") + "&user_id=" + flickrConnectorProperties.getProperty("userId") + "&min_upload_date=" + flickrConnectorProperties.getProperty("minDate") + "&max_upload_date=" + flickrConnectorProperties.getProperty("maxDate") + "&max_taken_date=" + flickrConnectorProperties.getProperty("maxDate") + "&min_taken_date=" + flickrConnectorProperties.getProperty("minDate") + "&extras=" + flickrConnectorProperties.getProperty("extraInfo"); JSONObject responseDirect = ConnectorIntegrationUtil.sendRestRequest(false, httpMethod, parameters, flickrConnectorProperties); Assert.assertTrue(responseConnector.toString().equals(responseDirect.toString())); } finally { proxyAdmin.deleteProxy(methodName); } }
From source file:org.wso2.carbon.connector.integration.test.flickr.FlickrConnectoreIntegrationTest.java
/** * Positive test case for getRecentCommentsForContacts method with Optional parameters. *//* ww w. j a va2 s . c om*/ @Test(priority = 3, groups = { "wso2.esb" }, description = "flickr {isLogged} integration test with Optional parameters.") public void testFlickrGetRecentCommentsForContactsWithOptionalParameters() throws Exception { String jsonRequestFilePath = pathToRequestsDirectory + "flickr_getRecentCommentsForContacts.txt"; String methodName = "flickr_getRecentCommentsForContacts"; final String rawString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath); final String jsonString = addCredentials(rawString); final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml"; proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath))); try { JSONObject responseConnector = ConnectorIntegrationUtil.sendRequest("POST", getProxyServiceURL(methodName), jsonString); String httpMethod = "GET"; String parameters = "format=json" + "&method=flickr.photos.comments.getRecentForContacts" + "&nojsoncallback=1" + "&oauth_consumer_key=" + flickrConnectorProperties.getProperty("consumerKey") + "&oauth_nonce=dummynonce" + "&oauth_signature_method=HMAC-SHA1" + "&oauth_timestamp=dummytimestamp" + "&oauth_token=" + flickrConnectorProperties.getProperty("accessToken") + "&oauth_version=1.0"; JSONObject responseDirect = ConnectorIntegrationUtil.sendRestRequest(true, httpMethod, parameters, flickrConnectorProperties); Assert.assertTrue(responseConnector.toString().equals(responseDirect.toString())); } finally { proxyAdmin.deleteProxy(methodName); } }
From source file:org.wso2.carbon.connector.integration.test.flickr.FlickrConnectoreIntegrationTest.java
/** * Positive test case for getCommentsList method with OptionalNegative parameters. *//*from w w w. j a v a2s . co m*/ @Test(priority = 4, groups = { "wso2.esb" }, description = "flickr {getCommentsList} integration test with OptionalNegative parameters") public void testFlickrGetCommentsListWithOptionalNegativeParameters() throws Exception { String jsonRequestFilePath = pathToRequestsDirectory + "optional/flickr_getCommentList.txt"; String methodName = "flickr_getCommentList"; String rawString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath); rawString = rawString.replace("dummyvalue", flickrConnectorProperties.getProperty("photoId")); rawString = rawString.replace("dummymindate", flickrConnectorProperties.getProperty("invalidMinDate")); rawString = rawString.replace("dummymaxdate", flickrConnectorProperties.getProperty("invalidMaxDate")); final String jsonString = addCredentials(rawString); final String proxyFilePath = "file:///" + pathToProxiesDirectory + "optional/" + methodName + ".xml"; proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath))); try { JSONObject responseConnector = ConnectorIntegrationUtil.sendRequest("POST", getProxyServiceURL(methodName), jsonString); String httpMethod = "GET"; String parameters = "format=json&nojsoncallback=1&method=flickr.photos.comments.getList&api_key=" + flickrConnectorProperties.getProperty("consumerKey") + "&photo_id=" + flickrConnectorProperties.getProperty("photoId") + "&min_comment_date=" + flickrConnectorProperties.getProperty("invalidMinDate") + "&max_comment_date=" + flickrConnectorProperties.getProperty("invalidMaxDate"); JSONObject responseDirect = ConnectorIntegrationUtil.sendRestRequest(false, httpMethod, parameters, flickrConnectorProperties); Assert.assertTrue(!responseConnector.toString().contains("author") && responseDirect.toString().equals(responseConnector.toString())); } finally { proxyAdmin.deleteProxy(methodName); } }
From source file:org.wso2.carbon.connector.integration.test.flickr.FlickrConnectoreIntegrationTest.java
/** * Positive test case for getPhotos method with OptionalNegative parameters. */// w w w . j a v a 2 s.co m @Test(priority = 4, groups = { "wso2.esb" }, description = "flickr {getPhotos} integration test with OptionalNegative parameters") public void testFlickrGetPhotosWithOptionalNegativeParameters() throws Exception { String jsonRequestFilePath = pathToRequestsDirectory + "optional/" + "flickr_getPhotos.txt"; String methodName = "flickr_getPhotos"; String rawString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath); rawString = rawString.replace("dummyvalue", flickrConnectorProperties.getProperty("userId")); rawString = rawString.replace("dummyminuploaddate", flickrConnectorProperties.getProperty("invalidMinDate")); rawString = rawString.replace("dummymaxuploaddate", flickrConnectorProperties.getProperty("invalidMaxDate")); rawString = rawString.replace("dummymaxtakendate", flickrConnectorProperties.getProperty("invalidMaxDate")); rawString = rawString.replace("dummymintakendate", flickrConnectorProperties.getProperty("invalidMinDate")); rawString = rawString.replace("dummyextra", flickrConnectorProperties.getProperty("invalidExtraInfo")); final String jsonString = addCredentials(rawString); final String proxyFilePath = "file:///" + pathToProxiesDirectory + "optional/" + methodName + ".xml"; proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath))); try { JSONObject responseConnector = ConnectorIntegrationUtil.sendRequest("POST", getProxyServiceURL(methodName), jsonString); String httpMethod = "GET"; String parameters = "format=json&nojsoncallback=1&method=flickr.people.getPhotos&api_key=" + flickrConnectorProperties.getProperty("consumerKey") + "&user_id=" + flickrConnectorProperties.getProperty("userId") + "&min_upload_date=" + flickrConnectorProperties.getProperty("invalidMinDate") + "&max_upload_date=" + flickrConnectorProperties.getProperty("invalidMaxDate") + "&max_taken_date=" + flickrConnectorProperties.getProperty("invalidMaxDate") + "&min_taken_date=" + flickrConnectorProperties.getProperty("invalidMinDate") + "&extras=" + flickrConnectorProperties.getProperty("invalidExtraInfo"); JSONObject responseDirect = ConnectorIntegrationUtil.sendRestRequest(false, httpMethod, parameters, flickrConnectorProperties); Assert.assertTrue(!responseConnector.toString().contains("license") && responseConnector.toString().equals(responseDirect.toString())); } finally { proxyAdmin.deleteProxy(methodName); } }
From source file:de.decoit.visa.http.ajax.handlers.DefaultHandler.java
@Override public void handle(HttpExchange he) throws IOException { log.warn("Unknown AJAX request: " + he.getRequestURI().toString()); // Fill the response with the error code JSONObject rv = new JSONObject(); try {/*from www .j a va2s .c o m*/ rv.put("status", AJAXServer.AJAX_ERROR_UNKNOWN_REQ); } catch (JSONException ex) { /* Ignore */ } String response = rv.toString(); // Send the response sendResponse(he, response); }
From source file:org.uiautomation.ios.server.command.impl.session.GetCapabilities.java
public WebDriverLikeResponse handle() throws Exception { JSONObject caps = new JSONObject(); caps.put("simulator", true); caps.put("version", "5.1"); caps.put("type", "iphone"); JSONObject json = new JSONObject(); json.put("sessionId", getSessionsManager().getCurrentSessionId()); json.put("status", 0); json.put("value", caps.toString()); WebDriverLikeResponse r = new WebDriverLikeResponse(json); return r;// w w w.j a v a2s. c o m }
From source file:org.shredzone.shariff.ShariffServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String url = getUrl(req);/*w w w .j a va 2 s .c o m*/ if (url == null) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "missing url parameter"); return; } if (!isValidHost(url, req)) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "invalid host"); return; } if (backend == null) { backend = createBackend(); } JSONObject json = new JSONObject(); for (Map.Entry<String, Integer> count : getCountsCached(url).entrySet()) { json.put(count.getKey(), count.getValue()); } resp.setContentType("Content-type: application/json"); resp.setCharacterEncoding("utf-8"); resp.getWriter().append(json.toString()); }
From source file:com.qcadoo.mes.genealogies.GenealogyController.java
@RequestMapping(value = "genealogyAttribute", method = RequestMethod.GET) public ModelAndView getGenealogyAttributesPageView(final Locale locale) { JSONObject json = new JSONObject( ImmutableMap.of("form.id", genealogyService.getGenealogyAttributeId().toString())); Map<String, String> arguments = ImmutableMap.of("context", json.toString()); return crudController.prepareView(GenealogiesConstants.PLUGIN_IDENTIFIER, GenealogiesConstants.VIEW_CURRENT_ATTRIBUTE, arguments, locale); }
From source file:org.zaizi.alfresco.rating.controller.RecommendationJSONScript.java
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException { List<NodeRef> nodes = getNodeRefs(req); try {// w w w. ja va 2s .co m JSONObject object = JsonNodeRefUtil.transform(nodes); String jsonString = object.toString(); res.getWriter().write(jsonString); res.setContentType("application/json"); res.setStatus(Status.STATUS_OK); } catch (JSONException e) { throw new WebScriptException("Error writing JSON", e); } }
From source file:cgeo.geocaching.connector.gc.GCParser.java
public static boolean editModifiedCoordinates(Geocache cache, Geopoint wpt) { final String userToken = getUserToken(cache); if (StringUtils.isEmpty(userToken)) { return false; }//w w w . j a v a2 s. c o m try { JSONObject jo; if (wpt != null) { jo = new JSONObject().put("dto", (new JSONObject().put("ut", userToken).put("data", new JSONObject() .put("lat", wpt.getLatitudeE6() / 1E6).put("lng", wpt.getLongitudeE6() / 1E6)))); } else { jo = new JSONObject().put("dto", (new JSONObject().put("ut", userToken))); } final String uriSuffix = wpt != null ? "SetUserCoordinate" : "ResetUserCoordinate"; final String uriPrefix = "http://www.geocaching.com/seek/cache_details.aspx/"; final HttpResponse response = Network.postJsonRequest(uriPrefix + uriSuffix, jo); Log.i("Sending to " + uriPrefix + uriSuffix + " :" + jo.toString()); if (response != null && response.getStatusLine().getStatusCode() == 200) { Log.i("GCParser.editModifiedCoordinates - edited on GC.com"); return true; } } catch (final JSONException e) { Log.e("Unknown exception with json wrap code", e); } Log.e("GCParser.deleteModifiedCoordinates - cannot delete modified coords"); return false; }