use of jakarta.json.JsonArray in project JsonPath by jayway.
the class JakartaJsonProvider method proxyAll.
private JsonStructure proxyAll(JsonStructure jsonStruct) {
if (jsonStruct == null) {
return null;
} else if (jsonStruct instanceof JsonArrayProxy) {
return (JsonArray) jsonStruct;
} else if (jsonStruct instanceof JsonArray) {
List<Object> array = new ArrayList<>();
for (JsonValue v : (JsonArray) jsonStruct) {
if (v instanceof JsonStructure) {
v = proxyAll((JsonStructure) v);
}
array.add(v);
}
return new JsonArrayProxy(jsonBuilderFactory.createArrayBuilder(array).build());
} else if (jsonStruct instanceof JsonObjectProxy) {
return (JsonObject) jsonStruct;
} else if (jsonStruct instanceof JsonObject) {
Map<String, Object> map = new LinkedHashMap<>();
for (Map.Entry<String, JsonValue> e : ((JsonObject) jsonStruct).entrySet()) {
JsonValue v = e.getValue();
if (v instanceof JsonStructure) {
v = proxyAll((JsonStructure) v);
}
map.put(e.getKey(), v);
}
return new JsonObjectProxy(jsonBuilderFactory.createObjectBuilder(map).build());
} else {
throw new IllegalArgumentException();
}
}
use of jakarta.json.JsonArray in project core by weld.
the class ProbeJmxIntegrationTest method testReceiveObservers.
@Test
public void testReceiveObservers() throws Exception {
try (WeldContainer container = new Weld().initialize()) {
assertNotNull(container.select(ProbeExtension.class).get());
Object[] params = new Object[] { 0, 50, "", "" };
String[] signature = new String[] { int.class.getName(), int.class.getName(), String.class.getName(), String.class.getName() };
JsonObject obj = invokeMBeanOperation("receiveObservers", params, signature);
JsonArray beansDataArray = obj.getJsonArray(Strings.DATA);
JsonObject omegaObserverJson = getJsonObjectByClass(beansDataArray, OmegaObserver.class);
assertNotNull(omegaObserverJson);
assertEquals(omegaObserverJson.getJsonString(Strings.OBSERVED_TYPE).getString(), Omega.class.getName());
assertEquals(omegaObserverJson.getJsonString(Strings.RECEPTION).getString(), "ALWAYS");
assertEquals(omegaObserverJson.getJsonString(Strings.PRIORITY_RANGE).getString(), Strings.APPLICATION.toUpperCase());
assertEquals(omegaObserverJson.getInt(Strings.PRIORITY), jakarta.interceptor.Interceptor.Priority.APPLICATION + 500);
}
}
use of jakarta.json.JsonArray in project dash-licenses by eclipse.
the class TestLicenseToolModule method getHttpClientService.
public IHttpClientService getHttpClientService() {
return new IHttpClientService() {
@Override
public int post(String url, String contentType, String payload, Consumer<String> handler) {
if (url.equals(settings.getClearlyDefinedDefinitionsUrl())) {
// The file contains only the information for the one record; the
// ClearlyDefined service expects a Json collection as the response,
// so insert the file contents into an array and pass that value to
// the handler.
JsonReader reader = Json.createReader(new StringReader(payload));
JsonArray items = (JsonArray) reader.read();
var builder = new StringBuilder();
builder.append("{");
for (int index = 0; index < items.size(); index++) {
if (index > 0)
builder.append(",");
var id = items.getString(index);
builder.append("\"");
builder.append(id);
builder.append("\" :");
switch(id) {
case "npm/npmjs/-/write/1.0.3":
case "npm/npmjs/-/write/1.0.4":
case "npm/npmjs/-/write/1.0.5":
case "npm/npmjs/-/write/1.0.6":
builder.append(new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("/write-1.0.3.json"), StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n")));
break;
case "npm/npmjs/@yarnpkg/lockfile/1.1.0":
case "npm/npmjs/@yarnpkg/lockfile/1.1.1":
case "npm/npmjs/@yarnpkg/lockfile/1.1.2":
case "npm/npmjs/@yarnpkg/lockfile/1.1.3":
builder.append(new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("/lockfile-1.1.0.json"), StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n")));
break;
/*
* I've run into cases where the ClearlyDefined API throws an error because of
* one apparently well-formed and otherwise correct ID. When this situation is
* encountered, an error message and nothing else is returned, regardless of how
* many IDs were included in the request.
*/
case "npm/npmjs/breaky/mcbreakyface/1.0.0":
case "npm/npmjs/breaky/mcbreakyface/1.0.1":
handler.accept("An error occurred when trying to fetch coordinates for one of the components");
return 200;
default:
builder.append("{}");
}
}
builder.append("}");
handler.accept(builder.toString());
return 200;
}
if (url.equals(settings.getLicenseCheckUrl())) {
if (payload.startsWith("request=")) {
var json = URLDecoder.decode(payload.substring("request=".length()), StandardCharsets.UTF_8);
var approved = Json.createObjectBuilder();
var rejected = Json.createObjectBuilder();
var reader = Json.createReader(new StringReader(json));
var root = reader.readObject().asJsonObject();
root.getJsonArray("dependencies").forEach(key -> {
var id = ((JsonString) key).getString();
var item = Json.createObjectBuilder();
switch(id) {
case "npm/npmjs/-/write/0.2.0":
item.add("authority", "CQ7766");
item.add("confidence", 100);
item.add("id", id);
item.add("license", "Apache-2.0");
item.addNull("sourceUrl");
item.add("status", "approved");
approved.add(id, item);
break;
case "npm/npmjs/@yarnpkg/lockfile/1.1.0":
item.add("authority", "CQ7722");
item.add("confidence", 100);
item.add("id", id);
item.add("license", "GPL-2.0");
item.addNull("sourceUrl");
item.add("status", "rejected");
rejected.add(id, item);
break;
}
});
var parent = Json.createObjectBuilder();
parent.add("approved", approved);
parent.add("rejected", rejected);
handler.accept(parent.build().toString());
return 200;
}
}
return 404;
}
@Override
public int get(String url, String contentType, Consumer<InputStream> handler) {
if (url.equals(settings.getApprovedLicensesUrl())) {
handler.accept(this.getClass().getResourceAsStream("/licenses.json"));
return 200;
}
switch(url) {
case "https://registry.npmjs.org/chalk":
handler.accept(this.getClass().getResourceAsStream("/chalk.json"));
return 200;
case "https://pypi.org/pypi/asn1crypto/json":
handler.accept(this.getClass().getResourceAsStream("/test_data_asn1crypto.json"));
return 200;
case "https://raw.githubusercontent.com/clearlydefined/service/HEAD/schemas/curation-1.0.json":
handler.accept(this.getClass().getResourceAsStream("/test_data_curation-1.0.json"));
return 200;
}
return 404;
}
@Override
public boolean remoteFileExists(String url) {
switch(url) {
case "https://search.maven.org/artifact/group.path/artifact/1.0/jar":
case "https://search.maven.org/remotecontent?filepath=group/path/artifact/1.0/artifact-1.0-sources.jar":
case "https://github.com/sindresorhus/chalk/archive/v0.1.0.zip":
case "https://registry.npmjs.org/chalk/-/chalk-0.1.0.tgz":
return true;
}
return IHttpClientService.super.remoteFileExists(url);
}
};
}
use of jakarta.json.JsonArray in project core by weld.
the class ProbeJmxIntegrationTest method testReceiveBeans.
@Test
public void testReceiveBeans() throws Exception {
try (WeldContainer container = new Weld().initialize()) {
assertNotNull(container.select(ProbeExtension.class).get());
container.select(Omega.class).get().ping();
Object[] params = new Object[] { 0, 50, "", "" };
String[] signature = new String[] { int.class.getName(), int.class.getName(), String.class.getName(), String.class.getName() };
JsonObject obj = invokeMBeanOperation("receiveBeans", params, signature);
JsonArray beansDataArray = obj.getJsonArray(Strings.DATA);
JsonObject omegaBeanJson = getJsonObjectByClass(beansDataArray, Omega.class);
assertNotNull(omegaBeanJson);
assertEquals(omegaBeanJson.getJsonString(Strings.SCOPE).getString(), "@" + Dependent.class.getSimpleName());
}
}
use of jakarta.json.JsonArray in project JsonPath by json-path.
the class JakartaJsonProvider method proxyAll.
private JsonStructure proxyAll(JsonStructure jsonStruct) {
if (jsonStruct == null) {
return null;
} else if (jsonStruct instanceof JsonArrayProxy) {
return (JsonArray) jsonStruct;
} else if (jsonStruct instanceof JsonArray) {
List<Object> array = new ArrayList<>();
for (JsonValue v : (JsonArray) jsonStruct) {
if (v instanceof JsonStructure) {
v = proxyAll((JsonStructure) v);
}
array.add(v);
}
return new JsonArrayProxy(jsonBuilderFactory.createArrayBuilder(array).build());
} else if (jsonStruct instanceof JsonObjectProxy) {
return (JsonObject) jsonStruct;
} else if (jsonStruct instanceof JsonObject) {
Map<String, Object> map = new LinkedHashMap<>();
for (Map.Entry<String, JsonValue> e : ((JsonObject) jsonStruct).entrySet()) {
JsonValue v = e.getValue();
if (v instanceof JsonStructure) {
v = proxyAll((JsonStructure) v);
}
map.put(e.getKey(), v);
}
return new JsonObjectProxy(jsonBuilderFactory.createObjectBuilder(map).build());
} else {
throw new IllegalArgumentException();
}
}
Aggregations