List of usage examples for org.json JSONObject getString
public String getString(String key) throws JSONException
From source file:org.wso2.carbon.connector.integration.test.quickbooks.QuickbooksConnectorIntegrationTest.java
/** * Positive test case for createBillPayment method with mandatory parameters. *//*from w w w . ja v a 2 s. co m*/ @Test(priority = 2, dependsOnMethods = { "testCreateAccountWithMandatoryParameters", "testCreateVendorWithOptionalParameters", "testCreateCustomerWithOptionalParameters", "testCreateBillWithMandatoryParameters", "testCreateBillWithOptionalParameters" }, description = "quickbooks {createBillPayment} integration test with mandatory parameters.") public void testCreateBillPaymentWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:createBillPayment"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_createBillPayment_mandatory.json"); JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("BillPayment"); String billPaymentId = esbResponseObject.getString("Id"); String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/billpayment/" + billPaymentId; String OAuthHeader = getOAuthHeader("GET", apiEndPoint); apiRequestHeadersMap.put("Authorization", OAuthHeader); RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap); JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("BillPayment"); Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"), apiResponseObject.getJSONObject("MetaData").getString("CreateTime")); Assert.assertEquals(esbResponseObject.getString("domain"), apiResponseObject.getString("domain")); Assert.assertEquals(esbResponseObject.getString("SyncToken"), apiResponseObject.getString("SyncToken")); Assert.assertEquals(esbResponseObject.getString("TxnDate"), apiResponseObject.getString("TxnDate")); }
From source file:org.wso2.carbon.connector.integration.test.quickbooks.QuickbooksConnectorIntegrationTest.java
/** * Positive test case for createBillPayment method with optional parameters. *//*from www .j a v a 2 s . c o m*/ @Test(priority = 2, dependsOnMethods = { "testCreateAccountWithMandatoryParameters", "testCreateVendorWithOptionalParameters", "testCreateCustomerWithOptionalParameters", "testCreateBillWithMandatoryParameters", "testCreateBillWithOptionalParameters" }, description = "quickbooks {createBillPayment} integration test with mandatory parameters.") public void testCreateBillPaymentWithOptionalParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:createBillPayment"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_createBillPayment_optional.json"); JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("BillPayment"); String billPaymentId = esbResponseObject.getString("Id"); String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/billpayment/" + billPaymentId; String OAuthHeader = getOAuthHeader("GET", apiEndPoint); apiRequestHeadersMap.put("Authorization", OAuthHeader); RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap); JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("BillPayment"); Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"), apiResponseObject.getJSONObject("MetaData").getString("CreateTime")); Assert.assertEquals(esbResponseObject.getString("domain"), apiResponseObject.getString("domain")); Assert.assertEquals(esbResponseObject.getString("SyncToken"), apiResponseObject.getString("SyncToken")); Assert.assertEquals(esbResponseObject.getString("PrivateNote"), apiResponseObject.getString("PrivateNote")); Assert.assertEquals(esbResponseObject.getString("sparse"), apiResponseObject.getString("sparse")); }
From source file:org.wso2.carbon.connector.integration.test.quickbooks.QuickbooksConnectorIntegrationTest.java
/** * Positive test case for query method with mandatory parameters. *//*from w w w. j av a 2 s . c om*/ @Test(priority = 1, description = "quickbooks {query} integration test with mandatory parameters.") public void testQueryWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:query"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_query_mandatory.json"); JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("QueryResponse"); JSONArray esbAccountArray = esbResponseObject.getJSONArray("Account"); String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/query?query=select%20*%20from%20Account%20ORDERBY%20Id%20MAXRESULTS%2010"; String OAuthHeader = getOAuthHeader("GET", apiEndPoint); apiRequestHeadersMap.put("Authorization", OAuthHeader); RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap); JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("QueryResponse"); JSONArray apiAccountArray = apiResponseObject.getJSONArray("Account"); Assert.assertEquals(esbAccountArray.length(), apiAccountArray.length()); Assert.assertEquals(esbAccountArray.getJSONObject(0).getString("Name"), apiAccountArray.getJSONObject(0).getString("Name")); Assert.assertEquals(esbAccountArray.getJSONObject(0).getString("AccountType"), apiAccountArray.getJSONObject(0).getString("AccountType")); Assert.assertEquals(esbResponseObject.getString("maxResults"), apiResponseObject.getString("maxResults")); Assert.assertEquals(esbResponseObject.getString("startPosition"), apiResponseObject.getString("startPosition")); }
From source file:it.unicaradio.android.tasks.DownloadCaptchaAsyncTask.java
/** * {@inheritDoc}/*from w w w.j ava 2s .co m*/ */ @Override protected Response<String> doInBackground(Void... params) { try { JSONObject request = new JSONObject(); request.put("method", "getCaptcha"); byte[] postData = request.toString().getBytes(); Response<String> response = new Response<String>(); byte[] resultBytes = NetworkUtils.httpPost(WEB_SERVICE, postData, "application/json"); String resultString = new String(resultBytes); Log.d(TAG, "Got CAPTCHA answer: " + resultString); JSONObject resultJSON = new JSONObject(resultString); response.setResult(resultJSON.getString("result")); return response; } catch (ClientProtocolException e) { Log.e(TAG, e.getMessage(), e); return new Response<String>(Error.INTERNAL_GENERIC_ERROR); } catch (IOException e) { Log.e(TAG, e.getMessage(), e); return new Response<String>(Error.INTERNAL_DOWNLOAD_ERROR); } catch (HttpException e) { Log.e(TAG, e.getMessage(), e); return new Response<String>(Error.INTERNAL_GENERIC_ERROR); } catch (JSONException e) { Log.e(TAG, e.getMessage(), e); return new Response<String>(Error.INTERNAL_GENERIC_ERROR); } }
From source file:hu.bme.iit.quiz.endpoint.IndexEndpoint.java
@OnMessage public String onMessage(String jMessage, Session session) { logger.debug("onMessage websocket event: " + jMessage); JSONObject message = new JSONObject(jMessage); try {//from ww w . jav a 2 s. c o m logger.debug("type: " + message.getString("type")); switch (message.getString("type")) { case "STARTLOBBY": startGatheringQuiz(message.getString("userkey"), message.getString("quizkey")); break; default: logger.warn("Websocket SWITCH drive in default case."); break; } } catch (Exception e) { logger.error(e); } return null; }
From source file:com.example.klaudia.myapplication.Searcher.java
public HashMap<String, Bitmap> getRecipesTitlesmagesFromArray(JSONArray array) { HashMap<String, Bitmap> result = new HashMap<String, Bitmap>(); try {/*from w w w .ja v a 2 s .com*/ for (int i = 0; i < array.length(); i++) { JSONObject recipe = array.getJSONObject(i); String title = recipe.getString("title"); Bitmap tmp = new DownloadImageTask().execute(recipe.getString("image")).get(); Bitmap scaled = Bitmap.createScaledBitmap(tmp, 50, 50, true); result.put(title, scaled); } } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:org.wso2.carbon.connector.integration.test.canvas.CanvasConnectorIntegrationTest.java
/** * Test listCalendarEvents method with Mandatory Parameters. *//*w w w . j ava2s .co m*/ @Test(priority = 1, dependsOnMethods = { "testCreateCalendarEventWithMandatoryParameters" }, description = "Canvas {listCalendarEvents} integration test with mandatory parameters.") public void testListCalendarEventsWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listCalendarEvents"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listCalendarEvents_mandatory.json"); final String apiUrl = connectorProperties.getProperty("apiUrl") + "/api/v1/calendar_events?start_date=" + connectorProperties.getProperty("calenderEventStartDate") + "T00:00:00Z"; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiUrl, "GET", apiRequestHeadersMap); JSONArray esbResponseArray = new JSONArray(esbRestResponse.getBody().getString("output")); JSONArray apiResponseArray = new JSONArray(apiRestResponse.getBody().getString("output")); Assert.assertEquals(apiResponseArray.length(), esbResponseArray.length()); if (apiResponseArray.length() > 0) { JSONObject esbFirstResult = esbResponseArray.getJSONObject(0); JSONObject apiFirstResult = apiResponseArray.getJSONObject(0); Assert.assertEquals(apiFirstResult.getString("id"), esbFirstResult.getString("id")); Assert.assertEquals(apiFirstResult.getString("title"), esbFirstResult.getString("title")); Assert.assertEquals(apiFirstResult.getString("context_code"), esbFirstResult.getString("context_code")); } }
From source file:org.wso2.carbon.connector.integration.test.canvas.CanvasConnectorIntegrationTest.java
/** * Test listCalendarEvents method with Optional Parameters. *///from w w w . j a v a 2 s . c o m @Test(priority = 1, dependsOnMethods = { "testCreateCalendarEventWithMandatoryParameters" }, description = "Canvas {listCalendarEvents} integration test with optional parameters.") public void testListCalendarEventsWithOptionalParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listCalendarEvents"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listCalendarEvents_optional.json"); final String apiUrl = connectorProperties.getProperty("apiUrl") + "/api/v1/calendar_events?all_events=true&per_page=4&start_date=" + connectorProperties.getProperty("calenderEventStartDate") + "T00:00:00Z"; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiUrl, "GET", apiRequestHeadersMap); JSONArray esbResponseArray = new JSONArray(esbRestResponse.getBody().getString("output")); JSONArray apiResponseArray = new JSONArray(apiRestResponse.getBody().getString("output")); Assert.assertEquals(apiResponseArray.length(), esbResponseArray.length()); if (apiResponseArray.length() > 0) { JSONObject esbFirstResult = esbResponseArray.getJSONObject(0); JSONObject apiFirstResult = apiResponseArray.getJSONObject(0); Assert.assertEquals(apiFirstResult.getString("id"), esbFirstResult.getString("id")); Assert.assertEquals(apiFirstResult.getString("title"), esbFirstResult.getString("title")); Assert.assertEquals(apiFirstResult.getString("context_code"), esbFirstResult.getString("context_code")); } }
From source file:org.wso2.carbon.connector.integration.test.canvas.CanvasConnectorIntegrationTest.java
/** * Test search method with Optional Parameters. *///from w w w . java 2 s . c o m @Test(priority = 1, dependsOnMethods = { "testCreateCalendarEventWithMandatoryParameters" }, description = "Canvas {search} integration test with optional parameters.") public void testSearchWithOptionalParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:search"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_search_optional.json"); final String apiUrl = connectorProperties.getProperty("apiUrl") + "/api/v1/search/recipients?context=" + connectorProperties.getProperty("contextCode"); RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiUrl, "GET", apiRequestHeadersMap); JSONArray esbResponseArray = new JSONArray(esbRestResponse.getBody().getString("output")); JSONArray apiResponseArray = new JSONArray(apiRestResponse.getBody().getString("output")); Assert.assertEquals(apiResponseArray.length(), esbResponseArray.length()); if (apiResponseArray.length() > 0) { JSONObject esbFirstResult = esbResponseArray.getJSONObject(0); JSONObject apiFirstResult = apiResponseArray.getJSONObject(0); Assert.assertEquals(apiFirstResult.getString("id"), esbFirstResult.getString("id")); Assert.assertEquals(apiFirstResult.getString("name"), esbFirstResult.getString("name")); Assert.assertEquals(apiFirstResult.getString("avatar_url"), esbFirstResult.getString("avatar_url")); } }
From source file:org.wso2.carbon.connector.integration.test.canvas.CanvasConnectorIntegrationTest.java
/** * Positive test case for listDiscussionTopics method with mandatory parameters. *//*from w ww. j a va 2 s. com*/ @Test(groups = { "wso2.esb" }, dependsOnMethods = { "testCreateCourseWithMandatoryParameters" }, description = "Canvas {listDiscussionTopics} integration test with mandatory parameters.") public void testListDiscussionTopicsWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listDiscussionTopics"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listDiscussionTopics_mandatory.json"); String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/api/v1/courses/" + connectorProperties.getProperty("courseId") + "/discussion_topics"; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap); JSONArray esbResponseArray = new JSONArray(esbRestResponse.getBody().getString("output")); JSONArray apiResponseArray = new JSONArray(apiRestResponse.getBody().getString("output")); Assert.assertEquals(apiResponseArray.length(), esbResponseArray.length()); if (apiResponseArray.length() > 0) { JSONObject esbFirstResult = esbResponseArray.getJSONObject(0); JSONObject apiFirstResult = apiResponseArray.getJSONObject(0); Assert.assertEquals(apiFirstResult.getString("id"), esbFirstResult.getString("id")); Assert.assertEquals(apiFirstResult.getString("title"), esbFirstResult.getString("title")); Assert.assertEquals(apiFirstResult.getString("message"), esbFirstResult.getString("message")); } }