Example usage for org.json JSONObject get

List of usage examples for org.json JSONObject get

Introduction

In this page you can find the example usage for org.json JSONObject get.

Prototype

public Object get(String key) throws JSONException 

Source Link

Document

Get the value object associated with a key.

Usage

From source file:com.kaltura.playersdk.PlayerViewController.java

private void doNativeAction(String params) {
    Log.d("NativeAction", params);
    try {//from   w  w w. j a  va  2 s.  co  m
        JSONObject actionObj = new JSONObject(params);
        if (actionObj.get("actionType").equals("share")) {
            share(actionObj);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.kaltura.playersdk.PlayerViewController.java

private void share(JSONObject shareParams) {
    if (mShareListener != null) {
        try {// w  w w  .j  a v a  2s. c  o  m
            String videoUrl = (String) shareParams.get("sharedLink");
            String videoName = (String) shareParams.get("videoName");
            ShareManager.SharingType type = ShareStrategyFactory.getType(shareParams);
            if (!mShareListener.onShare(videoUrl, type, videoName)) {
                ShareManager.share(shareParams, mActivity);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    } else {
        ShareManager.share(shareParams, mActivity);
    }
}

From source file:org.openqa.selendroid.server.inspector.view.InspectorView.java

private String displayCapabilities() throws JSONException {
    if (driver.getSession() != null) {
        StringBuffer capabilities = new StringBuffer();
        JSONObject capa = driver.getSession().getCapabilities();
        if (capa == null) {
            return "No capabilities available.";
        }/*from w w w  .j  av a  2  s . c om*/

        for (Iterator<String> keyIter = capa.keys(); keyIter.hasNext();) {
            String key = keyIter.next();
            capabilities.append("<p><b>" + key + "</b>: " + capa.get(key) + "</p>");
        }
        return capabilities.toString();
    }
    return "No capabilities available. Model = null";
}

From source file:org.qi4j.library.shiro.web.servlet.Qi4jShiroServletFilter.java

private void applyFilterChain(Application application) throws JSONException {

    String filterChainsConfig = getFilterConfig().getInitParameter(FILTER_CHAINS_PARAM);
    NullArgumentException.validateNotEmpty(FILTER_CHAINS_PARAM, filterChainsConfig);

    JSONObject filterChainsJson = new JSONObject(filterChainsConfig);

    Ini ini = new Ini();
    Section urls = ini.addSection("urls");
    Iterator it = filterChainsJson.keys();
    while (it.hasNext()) {
        String eachUrl = (String) it.next();
        urls.put(eachUrl, (String) filterChainsJson.get(eachUrl));
    }//from  ww  w  .ja va  2  s  .c  om

    Section filters = ini.addSection("filters");
    filters.put("authcBasic.applicationName", application.name());
    filters.put("authcX509", X509AuthenticationFilter.class.getName());

    IniFilterChainResolverFactory filterChainResolverFactory = new IniFilterChainResolverFactory(ini);
    filterChainResolverFactory.setFilterConfig(getFilterConfig());
    setFilterChainResolver(filterChainResolverFactory.getInstance());
}

From source file:controllers.WatermarkControllerTest.java

@Test
public void testGetWatermark() {
    String result = ninjaTestBrowser.postJson(getServerAddress() + "/watermark/journal",
            getDocumentPayload(TEST_TITLE, TEST_AUTHOR));

    JSONObject document;
    Integer id = 0;/*from  w w w  .j a  v  a2 s  . co  m*/
    try {
        document = new JSONObject(result);
        id = (Integer) document.get("id");

    } catch (JSONException e) {
        assertTrue("No JSON String", false);
    }

    String url = getServerAddress() + "/watermark/" + id.toString();
    result = ninjaTestBrowser.makeJsonRequest(url);
    assertTrue(result.contains("Not Found"));
    try {
        Thread.sleep(WatermarkMaker.WATERMARKING + 1);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    result = ninjaTestBrowser.makeJsonRequest(url);
    assertTrue(result.contains("title"));
    assertTrue(result.contains(TEST_TITLE));
    assertTrue(result.contains("author"));
    assertTrue(result.contains(TEST_AUTHOR));
    assertTrue(result.contains("content"));
    assertTrue(result.contains("journal"));
}

From source file:com.karura.framework.utils.UrlUtils.java

public static String jsonToQuery(String jsonString, String scheme, String authority) throws JSONException {
    Builder builder = new Builder();
    builder.scheme(scheme);/*from w  w w. j  a  v  a  2 s.  c  o m*/
    builder.authority(authority);

    JSONObject json = new JSONObject(jsonString.trim());
    Iterator<?> keys = json.keys();
    String key = null;
    String value = null;
    while (keys.hasNext()) {
        key = String.valueOf(keys.next());
        value = String.valueOf(json.get(key));
        builder.appendQueryParameter(key, value);
    }
    return builder.build().toString();
}

From source file:org.wso2.carbon.connector.integration.test.spotify.SpotifyConnectorIntegrationTest.java

/**
 * Mandatory parameter test case for getAnArtist method.
 *///from ww  w . j a va2  s .co  m
@Test(enabled = true, groups = {
        "wso2.esb" }, description = "spotify {getAnArtist} integration test with mandatory parameter.")
public void testGetAnArtistWithMandatoryParameter() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "getAnArtist_Mandatory.txt";
    String methodName = "spotify";
    final String jsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";
    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));
    String modifiedJsonString = String.format(jsonString, spotifyConnectorProperties.getProperty("artistId1"));
    JSONObject jsonResponse;
    try {
        jsonResponse = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName), modifiedJsonString);
        JSONObject jsonObject = new JSONObject(modifiedJsonString);
        Assert.assertEquals(jsonObject.getString("artistId"), jsonResponse.get("id"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.spotify.SpotifyConnectorIntegrationTest.java

/**
 * Mandatory parameter test case for getTopTracksOfAnArtist method.
 *///from ww  w.  j  a va  2s.  c o  m
@Test(enabled = true, groups = {
        "wso2.esb" }, description = "spotify {getTopTracksOfAnArtist} integration test with mandatory parameters.")
public void testGetTopTracksOfAnArtistWithMandatoryParameters() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "getTopTracksOfAnArtist_Mandatory.txt";
    String methodName = "spotify";
    final String jsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";
    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));
    String modifiedJsonString = String.format(jsonString, spotifyConnectorProperties.getProperty("artistId1"));
    try {
        JSONObject jsonResponse = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                modifiedJsonString);
        JSONObject jsonObject = new JSONObject(modifiedJsonString);
        JSONArray artists = ((JSONObject) jsonResponse.getJSONArray("tracks").get(0)).getJSONArray("artists");
        boolean exi = false;
        for (int i = 0; i < artists.length(); i++) {
            JSONObject a = (JSONObject) artists.get(i);
            if (a.getString("id").equals(jsonObject.getString("artistId"))) {
                exi = true;
            }
        }
        Assert.assertEquals(exi, true);
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.spotify.SpotifyConnectorIntegrationTest.java

/**
 * Mandatory parameter test case for getATrack method.
 */// w  ww  .  ja  v  a2s .com
@Test(enabled = true, groups = {
        "wso2.esb" }, description = "spotify {getATrack} integration test with mandatory parameters.")
public void testGetATrackWithMandatoryParameters() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "getATrack_Mandatory.txt";
    String methodName = "spotify";
    final String jsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";
    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));
    String modifiedJsonString = String.format(jsonString, spotifyConnectorProperties.getProperty("trackId1"));
    try {
        JSONObject jsonResponse = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                modifiedJsonString);
        JSONObject jsonObject = new JSONObject(modifiedJsonString);
        Assert.assertEquals(jsonObject.getString("trackId"), jsonResponse.get("id"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.spotify.SpotifyConnectorIntegrationTest.java

/**
 * Test case for getTracksOfCurrentUser method.
 *///www  . ja  v  a  2s . c om
@Test(enabled = true, groups = {
        "wso2.esb" }, description = "spotify {getTracksOfCurrentUser} integration test.")
public void getTracksOfCurrentUser() throws Exception {
    String methodName = "spotify";
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";
    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));
    String jsonRequestFilePath = pathToRequestsDirectory + "getTracksOfCurrentUser_Mandatory.txt";
    final String jsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    String modifiedJsonString = String.format(jsonString, spotifyConnectorProperties.getProperty("clientId"),
            spotifyConnectorProperties.getProperty("clientSecret"),
            spotifyConnectorProperties.getProperty("grantType"),
            spotifyConnectorProperties.getProperty("refreshToken"));
    JSONObject jsonResponse = null;
    try {
        jsonResponse = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName), modifiedJsonString);
        String myTrackId = ((JSONObject) jsonResponse.getJSONArray("items").get(0)).getJSONObject("track")
                .getString("id");
        String myTrackId1 = ((JSONObject) jsonResponse.getJSONArray("items").get(1)).getJSONObject("track")
                .getString("id");
        spotifyConnectorProperties.setProperty("myTrackId", myTrackId);
        spotifyConnectorProperties.setProperty("myTrackId1", myTrackId1);
        String jsonObj = jsonResponse.getString("total");
        Assert.assertNotEquals(jsonObj, 0);
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}