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;
}
});
}
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());
}
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;
}
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;
}
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;
}
Aggregations