use of org.noggit.JSONParser in project disgear by yangbutao.
the class ZkStateReader method fromJSON.
public static Object fromJSON(byte[] utf8) {
// convert directly from bytes to chars
// and parse directly from that instead of going through
// intermediate strings or readers
CharArr chars = new CharArr();
ByteUtils.UTF8toUTF16(utf8, 0, utf8.length, chars);
JSONParser parser = new JSONParser(chars.getArray(), chars.getStart(), chars.length());
try {
return ObjectBuilder.getVal(parser);
} catch (IOException e) {
// should never happen w/o using real
throw new RuntimeException(e);
// IO
}
}
use of org.noggit.JSONParser in project ranger by apache.
the class SolrCollectionBootstrapper method postDataAndGetResponse.
public static Map postDataAndGetResponse(CloudSolrClient cloudClient, String uri, ByteBuffer bytarr) throws IOException {
HttpPost httpPost = null;
HttpEntity entity;
String response = null;
Map m = null;
try {
httpPost = new HttpPost(uri);
httpPost.setHeader("Content-Type", "application/octet-stream");
httpPost.setEntity(new ByteArrayEntity(bytarr.array(), bytarr.arrayOffset(), bytarr.limit()));
entity = cloudClient.getLbClient().getHttpClient().execute(httpPost).getEntity();
try {
response = EntityUtils.toString(entity, StandardCharsets.UTF_8);
m = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
} catch (JSONParser.ParseException e) {
logger.severe("Error response: " + response);
}
} finally {
httpPost.releaseConnection();
}
return m;
}
use of org.noggit.JSONParser in project lucene-solr by apache.
the class TestSolrConfigHandler method runConfigCommand.
public static void runConfigCommand(RestTestHarness harness, String uri, String payload) throws IOException {
String json = SolrTestCaseJ4.json(payload);
log.info("going to send config command. path {} , payload: {}", uri, payload);
String response = harness.post(uri, json);
Map map = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
assertNull(response, map.get("errors"));
}
use of org.noggit.JSONParser in project lucene-solr by apache.
the class TestConfigSetImmutable method testSchemaHandlerImmutable.
@Test
public void testSchemaHandlerImmutable() throws Exception {
String payload = "{\n" + " 'add-field' : {\n" + " 'name':'a1',\n" + " 'type': 'string',\n" + " 'stored':true,\n" + " 'indexed':false\n" + " },\n" + " }";
String response = restTestHarness.post("/schema?wt=json", json(payload));
Map map = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
assertNotNull(map.get("errors"));
assertTrue(map.get("errors").toString().contains("immutable"));
}
use of org.noggit.JSONParser in project lucene-solr by apache.
the class TestManagedResource method testLoadingAndStoringOfManagedData.
/**
* Tests managed data storage to and loading from {@link ManagedResourceStorage.InMemoryStorageIO}.
*/
@SuppressWarnings("unchecked")
@Test
public void testLoadingAndStoringOfManagedData() throws Exception {
String resourceId = "/config/test/foo";
String storedResourceId = "_config_test_foo.json";
MockAnalysisComponent observer = new MockAnalysisComponent();
List<ManagedResourceObserver> observers = Arrays.asList((ManagedResourceObserver) observer);
// put some data in the storage impl so that we can test
// initialization of managed data from storage
String storedJson = "{'initArgs':{'someArg':'someVal', 'arg2':true, 'arg3':['one','two','three']," + " 'arg4':18, 'arg5':0.9, 'arg6':{ 'uno':1, 'dos':2}},'" + ManagedResource.MANAGED_JSON_LIST_FIELD + "':['1','2','3']}";
ManagedResourceStorage.InMemoryStorageIO storageIO = new ManagedResourceStorage.InMemoryStorageIO();
storageIO.storage.put(storedResourceId, new BytesRef(json(storedJson)));
ManagedTestResource res = new ManagedTestResource(resourceId, new SolrResourceLoader(Paths.get("./")), storageIO);
res.loadManagedDataAndNotify(observers);
assertTrue("Observer was not notified by ManagedResource!", observer.wasNotified);
// now update the managed data (as if it came from the REST API)
List<String> updatedData = new ArrayList<>();
updatedData.add("1");
updatedData.add("2");
updatedData.add("3");
updatedData.add("4");
res.storeManagedData(updatedData);
StringReader stringReader = new StringReader(storageIO.storage.get(storedResourceId).utf8ToString());
Map<String, Object> jsonObject = (Map<String, Object>) ObjectBuilder.getVal(new JSONParser(stringReader));
List<String> jsonList = (List<String>) jsonObject.get(ManagedResource.MANAGED_JSON_LIST_FIELD);
assertTrue("Managed data was not updated correctly!", jsonList.contains("4"));
}
Aggregations