use of org.jboss.hal.js.JsonObject in project console by hal.
the class UploadPayloadProcessor method extractFailure.
private String extractFailure(final JsonObject jsonResponse) {
String failure = UNKNOWN;
JsonType type = jsonResponse.get(FAILURE_DESCRIPTION).getType();
if (type == JsonType.STRING) {
failure = jsonResponse.getString(FAILURE_DESCRIPTION);
} else if (type == JsonType.OBJECT) {
JsonObject failureObject = jsonResponse.getObject(FAILURE_DESCRIPTION);
for (String key : failureObject.keys()) {
if (key.contains(FAILURE) && failureObject.getString(key) != null) {
failure = failureObject.getString(key);
break;
}
}
}
return failure;
}
use of org.jboss.hal.js.JsonObject in project console by hal.
the class ReadChildrenResult method asJson.
JsonObject asJson() {
JsonObject object = JsonObject.create();
object.put(NAME, name);
JsonArray addresses = JsonArray.create();
int i = 0;
for (Map.Entry<String, String> entry : this.addresses.entrySet()) {
JsonObject keyValue = JsonObject.create();
keyValue.put(KEY, entry.getKey());
keyValue.put(VALUE, entry.getValue());
addresses.set(i, keyValue);
i++;
}
object.put(ADDRESSES, addresses);
return object;
}
use of org.jboss.hal.js.JsonObject in project console by hal.
the class ExtensionRegistry method verifyMetadata.
@JsIgnore
public void verifyMetadata(String url, MetadataCallback metadataCallback) {
SafeUri safeUrl = UriUtils.fromString(url);
XMLHttpRequest xhr = new XMLHttpRequest();
xhr.onload = event -> {
int status = (int) xhr.status;
if (status >= 200 && status < 400) {
String responseText = xhr.responseText;
if (Strings.isNullOrEmpty(responseText)) {
// 415 - Unsupported Media Type
metadataCallback.result(415, null);
} else {
JsonObject extensionJson = Json.parse(responseText);
metadataCallback.result(status, extensionJson);
}
} else {
metadataCallback.result(status, null);
}
};
// NON-NLS
xhr.addEventListener("error", event -> metadataCallback.result(503, null), false);
xhr.open(GET.name(), safeUrl.asString(), true);
xhr.send();
}
use of org.jboss.hal.js.JsonObject in project console by hal.
the class ReadChildrenRenderer method render.
@Override
public String render(JsonObject item, String query) {
String name = item.get(NAME).asString();
SafeHtmlBuilder builder = new SafeHtmlBuilder();
builder.appendHtmlConstant("<div class=\"" + autocompleteSuggestion + "\" data-val=\"" + name + "\">");
JsonArray addresses = item.getArray(ADDRESSES);
if (addresses.length() != 0) {
for (int i = 0; i < addresses.length(); i++) {
JsonObject keyValue = addresses.getObject(i);
builder.appendHtmlConstant("<span title=\"" + keyValue.getString(KEY) + "\" class=\"" + address + "\">");
builder.appendEscaped(keyValue.getString(VALUE));
builder.appendEscaped(" / ");
builder.appendHtmlConstant("</span>");
}
}
// NON-NLS
builder.appendHtmlConstant(highlight(query).replace(name, "<b>$1</b>")).appendHtmlConstant("</div>");
return builder.toSafeHtml().asString();
}
use of org.jboss.hal.js.JsonObject in project console by hal.
the class EndpointManager method checkKeycloakAdapter.
private void checkKeycloakAdapter(String baseUrl, Consumer<String> kcExistsCallback, Callback wildflyCallback) {
String keycloakAdapterUrl = getKeycloakAdapterUrl(baseUrl);
XMLHttpRequest xhr = new XMLHttpRequest();
xhr.onload = event -> {
int status = xhr.status;
if (status == 200) {
JsonObject kcConfig = Json.parse(xhr.responseText);
String keycloakServerJsUrl = kcConfig.getString(AUTH_SERVER_URL) + "/js/keycloak.js";
kcExistsCallback.accept(keycloakServerJsUrl);
} else {
logger.error("Keycloak adapter '{}' doesn't exist - status: {}", keycloakAdapterUrl, status);
wildflyCallback.execute();
}
};
xhr.addEventListener("error", event -> {
logger.error("Keycloak adapter '{}' failed: {}", keycloakAdapterUrl, event);
wildflyCallback.execute();
});
xhr.open(GET.name(), keycloakAdapterUrl, true);
xhr.send();
}
Aggregations