use of javax.json.JsonArrayBuilder in project Payara by payara.
the class RestCollectionResponseBody method populateJson.
@Override
protected void populateJson(JsonObject object) throws JsonException {
super.populateJson(object);
JsonArrayBuilder array = Json.createArrayBuilder();
for (RestModel item : getItems()) {
array.add(JsonUtil.getJsonValue(item));
}
object.put("items", array.build());
}
use of javax.json.JsonArrayBuilder in project Payara by payara.
the class ResponseBody method populateJson.
protected void populateJson(JsonObject object) throws JsonException {
if (!getMessages().isEmpty()) {
JsonArrayBuilder array = Json.createArrayBuilder();
for (Message message : getMessages()) {
array.add(message.toJson());
}
object.put("messages", array.build());
}
if (includeResourceLinks && !getResourceLinks().isEmpty()) {
JsonArrayBuilder array = Json.createArrayBuilder();
for (ResourceLink link : getResourceLinks()) {
array.add(link.toJson());
}
object.put("resources", array.build());
}
}
use of javax.json.JsonArrayBuilder in project Payara by payara.
the class OptionsResultJsonProvider method getRespresenationForMethodMetaData.
public JsonArray getRespresenationForMethodMetaData(OptionsResult proxy) {
JsonArrayBuilder arr = Json.createArrayBuilder();
Set<String> methods = proxy.methods();
for (String methodName : methods) {
try {
MethodMetaData methodMetaData = proxy.getMethodMetaData(methodName);
JsonObjectBuilder method = Json.createObjectBuilder();
method.add(NAME, methodName);
// method.put(QUERY_PARAMETERS, getQueryParams(methodMetaData));
method.add(MESSAGE_PARAMETERS, getMessageParams(methodMetaData));
arr.add(method.build());
} catch (JsonException ex) {
RestLogging.restLogger.log(Level.SEVERE, null, ex);
}
}
return arr.build();
}
use of javax.json.JsonArrayBuilder in project Payara by payara.
the class RemoteRestAdminCommand method parseMetadata.
/**
* Parse the JSon metadata for the command.
*
* @param str the string
* @return the etag to compare the command cache model
*/
private CachedCommandModel parseMetadata(String str, String etag) {
if (logger.isLoggable(Level.FINER)) {
// XXX - assume "debug" == "FINER"
logger.finer("------- RAW METADATA RESPONSE ---------");
logger.log(Level.FINER, "ETag: {0}", etag);
logger.finer(str);
logger.finer("------- RAW METADATA RESPONSE ---------");
}
if (str == null) {
return null;
}
try (JsonParser parser = Json.createParser(new StringReader(str))) {
boolean sawFile = false;
parser.next();
JsonObject obj = parser.getObject();
obj = obj.getJsonObject("command");
CachedCommandModel cm = new CachedCommandModel(obj.getString("@name"), etag);
cm.dashOk = parseBoolean(obj, "@unknown-options-are-operands", false);
cm.managedJob = parseBoolean(obj, "@managed-job", false);
cm.setUsage(obj.getString("usage", null));
JsonValue optns = obj.get("option");
if (!JsonValue.NULL.equals(optns) && optns != null) {
JsonArray jsonOptions;
if (optns instanceof JsonArray) {
jsonOptions = (JsonArray) optns;
} else {
JsonArrayBuilder optBuilder = Json.createArrayBuilder();
optBuilder.add(optns);
jsonOptions = optBuilder.build();
}
for (int i = 0; i < jsonOptions.size(); i++) {
JsonObject jsOpt = jsonOptions.getJsonObject(i);
String type = jsOpt.getString("@type");
ParamModelData opt = new ParamModelData(jsOpt.getString("@name"), typeOf(type), parseBoolean(jsOpt, "@optional", false), jsOpt.getString("@default", null), jsOpt.getString("@short", null), parseBoolean(jsOpt, "@obsolete", false), jsOpt.getString("@alias", null));
opt.param._acceptableValues = jsOpt.getString("@acceptable-values", "");
if ("PASSWORD".equals(type)) {
opt.param._password = true;
opt.prompt = jsOpt.getString("@prompt", null);
opt.promptAgain = jsOpt.getString("@prompt-again", null);
} else if ("FILE".equals(type)) {
sawFile = true;
}
if (parseBoolean(jsOpt, "@primary", false)) {
opt.param._primary = true;
}
if (parseBoolean(jsOpt, "@multiple", false)) {
if (opt.type == File.class) {
opt.type = File[].class;
} else {
opt.type = List.class;
}
opt.param._multiple = true;
}
cm.add(opt);
}
}
if (sawFile) {
cm.add(new ParamModelData("upload", Boolean.class, true, null));
addedUploadOption = true;
cm.setAddedUploadOption(true);
}
if (notify) {
cm.add(new ParamModelData("notify", Boolean.class, false, "false"));
}
this.usage = cm.getUsage();
return cm;
} catch (Exception ex) {
logger.log(Level.SEVERE, "Can not parse command metadata", ex);
return null;
}
}
use of javax.json.JsonArrayBuilder in project Payara by payara.
the class OidcProvider method userinfoEndpoint.
@Path("/userinfo")
@Produces(APPLICATION_JSON)
@GET
public Response userinfoEndpoint(@HeaderParam(AUTHORIZATION_HEADER) String authorizationHeader) {
String accessToken = authorizationHeader.substring(BEARER_TYPE.length() + 1);
ResponseBuilder builder;
JsonObjectBuilder jsonBuilder = Json.createObjectBuilder();
if (ACCESS_TOKEN_VALUE.equals(accessToken)) {
builder = Response.ok();
jsonBuilder.add(SUBJECT_IDENTIFIER, getSubject()).add("name", "Gaurav").add("family_name", "Gupta ").add("given_name", "Gaurav Gupta").add("profile", "https://abc.com/+jGauravGupta").add("picture", "https://abc.com/photo.jpg").add("email", "gaurav.gupta.jc@gmail.com").add("email_verified", true).add("gender", "male").add("locale", "en");
if (rolesInUserInfoEndpoint) {
JsonArrayBuilder groupsBuilder = Json.createArrayBuilder();
userGroups.forEach(g -> {
groupsBuilder.add(g);
});
jsonBuilder.add(OpenIdConstant.GROUPS, groupsBuilder);
}
} else {
jsonBuilder.add(ERROR_PARAM, "invalid_access_token");
builder = Response.serverError();
}
return builder.entity(jsonBuilder.build().toString()).build();
}
Aggregations