Search in sources :

Example 1 with JSONParser

use of org.json.simple.parser.JSONParser in project hadoop by apache.

the class TestHttpFSWithKerberos method testDelegationTokenHttpFSAccess.

@Test
@TestDir
@TestJetty
@TestHdfs
public void testDelegationTokenHttpFSAccess() throws Exception {
    createHttpFSServer();
    KerberosTestUtils.doAsClient(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            //get delegation token doing SPNEGO authentication
            URL url = new URL(TestJettyHelper.getJettyURL(), "/webhdfs/v1/?op=GETDELEGATIONTOKEN");
            AuthenticatedURL aUrl = new AuthenticatedURL();
            AuthenticatedURL.Token aToken = new AuthenticatedURL.Token();
            HttpURLConnection conn = aUrl.openConnection(url, aToken);
            Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
            JSONObject json = (JSONObject) new JSONParser().parse(new InputStreamReader(conn.getInputStream()));
            json = (JSONObject) json.get(DelegationTokenAuthenticator.DELEGATION_TOKEN_JSON);
            String tokenStr = (String) json.get(DelegationTokenAuthenticator.DELEGATION_TOKEN_URL_STRING_JSON);
            //access httpfs using the delegation token
            url = new URL(TestJettyHelper.getJettyURL(), "/webhdfs/v1/?op=GETHOMEDIRECTORY&delegation=" + tokenStr);
            conn = (HttpURLConnection) url.openConnection();
            Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
            //try to renew the delegation token without SPNEGO credentials
            url = new URL(TestJettyHelper.getJettyURL(), "/webhdfs/v1/?op=RENEWDELEGATIONTOKEN&token=" + tokenStr);
            conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("PUT");
            Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_UNAUTHORIZED);
            //renew the delegation token with SPNEGO credentials
            url = new URL(TestJettyHelper.getJettyURL(), "/webhdfs/v1/?op=RENEWDELEGATIONTOKEN&token=" + tokenStr);
            conn = aUrl.openConnection(url, aToken);
            conn.setRequestMethod("PUT");
            Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
            //cancel delegation token, no need for SPNEGO credentials
            url = new URL(TestJettyHelper.getJettyURL(), "/webhdfs/v1/?op=CANCELDELEGATIONTOKEN&token=" + tokenStr);
            conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("PUT");
            Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
            //try to access httpfs with the canceled delegation token
            url = new URL(TestJettyHelper.getJettyURL(), "/webhdfs/v1/?op=GETHOMEDIRECTORY&delegation=" + tokenStr);
            conn = (HttpURLConnection) url.openConnection();
            Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_UNAUTHORIZED);
            return null;
        }
    });
}
Also used : InputStreamReader(java.io.InputStreamReader) Token(org.apache.hadoop.security.token.Token) URL(java.net.URL) AuthenticatedURL(org.apache.hadoop.security.authentication.client.AuthenticatedURL) HttpURLConnection(java.net.HttpURLConnection) JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) AuthenticatedURL(org.apache.hadoop.security.authentication.client.AuthenticatedURL) TestJetty(org.apache.hadoop.test.TestJetty) TestHdfs(org.apache.hadoop.test.TestHdfs) TestDir(org.apache.hadoop.test.TestDir) Test(org.junit.Test)

Example 2 with JSONParser

use of org.json.simple.parser.JSONParser in project OpenGrok by OpenGrok.

the class StatsMessageTest method testGetValidJson.

@Test
public void testGetValidJson() {
    testGet();
    Message m = new StatsMessage();
    m.setText("get");
    byte[] out = null;
    try {
        out = m.apply(env);
    } catch (Exception ex) {
        Assert.fail("Should not throw any exception");
    }
    JSONParser p = new JSONParser();
    Object o = null;
    try {
        o = p.parse(new String(out));
    } catch (ParseException ex) {
        Assert.fail("Should not throw any exception");
    }
    Assert.assertNotNull(o);
    Statistics stat = Statistics.from((JSONObject) o);
    Assert.assertTrue(stat instanceof Statistics);
    Assert.assertEquals(1, stat.getRequests());
    Assert.assertEquals(1, stat.getMinutes());
    Assert.assertEquals(0, stat.getRequestCategories().size());
    Assert.assertEquals(0, stat.getTiming().size());
}
Also used : JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) ParseException(org.json.simple.parser.ParseException) Statistics(org.opensolaris.opengrok.web.Statistics) ParseException(org.json.simple.parser.ParseException) Test(org.junit.Test)

Example 3 with JSONParser

use of org.json.simple.parser.JSONParser in project rest.li by linkedin.

the class BigDataClientExample method parseConfig.

private static JSONObject parseConfig() throws IOException, ParseException {
    String path = new File(new File(".").getAbsolutePath()).getCanonicalPath() + "/src/main/config/bigDataExample.json";
    JSONParser parser = new JSONParser();
    Object object = parser.parse(new FileReader(path));
    return (JSONObject) object;
}
Also used : JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) FileReader(java.io.FileReader) File(java.io.File)

Example 4 with JSONParser

use of org.json.simple.parser.JSONParser in project rest.li by linkedin.

the class ProfileClientExample method parseConfig.

private static JSONObject parseConfig() throws IOException, ParseException {
    String path = new File(new File(".").getAbsolutePath()).getCanonicalPath() + "/src/main/config/profileLoadBalancerExample.json";
    JSONParser parser = new JSONParser();
    Object object = parser.parse(new FileReader(path));
    return (JSONObject) object;
}
Also used : JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) FileReader(java.io.FileReader) File(java.io.File)

Example 5 with JSONParser

use of org.json.simple.parser.JSONParser in project rest.li by linkedin.

the class CacheClientExample method parseConfig.

private static JSONObject parseConfig() throws IOException, ParseException {
    String path = new File(new File(".").getAbsolutePath()).getCanonicalPath() + "/src/main/config/cacheClientExample.json";
    JSONParser parser = new JSONParser();
    Object object = parser.parse(new FileReader(path));
    return (JSONObject) object;
}
Also used : JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) FileReader(java.io.FileReader) File(java.io.File)

Aggregations

JSONParser (org.json.simple.parser.JSONParser)146 JSONObject (org.json.simple.JSONObject)136 JSONArray (org.json.simple.JSONArray)61 HttpClient (org.apache.commons.httpclient.HttpClient)44 ParseException (org.json.simple.parser.ParseException)40 GetMethod (org.apache.commons.httpclient.methods.GetMethod)34 Test (org.junit.Test)18 IOException (java.io.IOException)15 File (java.io.File)13 URL (java.net.URL)13 InputStreamReader (java.io.InputStreamReader)11 PostMethod (org.apache.commons.httpclient.methods.PostMethod)11 HashMap (java.util.HashMap)10 Map (java.util.Map)10 MapLayer (au.org.emii.portal.menu.MapLayer)9 Point (com.vividsolutions.jts.geom.Point)9 FileReader (java.io.FileReader)9 ArrayList (java.util.ArrayList)9 InputStream (java.io.InputStream)7 Facet (au.org.ala.legend.Facet)6