本文整理匯總了Java中javax.json.JsonObject類的典型用法代碼示例。如果您正苦於以下問題:Java JsonObject類的具體用法?Java JsonObject怎麽用?Java JsonObject使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JsonObject類屬於javax.json包,在下文中一共展示了JsonObject類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: verifyInjectedJTI2
import javax.json.JsonObject; //導入依賴的package包/類
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
description = "Verify that the injected jti claim is as expected")
public void verifyInjectedJTI2() throws Exception {
Reporter.log("Begin verifyInjectedJTI\n");
String uri = baseURL.toExternalForm() + "/endp/verifyInjectedJTI";
WebTarget echoEndpointTarget = ClientBuilder.newClient()
.target(uri)
.queryParam(Claims.jti.name(), "a-123")
.queryParam(Claims.auth_time.name(), authTimeClaim);
Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
String replyString = response.readEntity(String.class);
JsonReader jsonReader = Json.createReader(new StringReader(replyString));
JsonObject reply = jsonReader.readObject();
Reporter.log(reply.toString());
Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
示例2: verifyInjectedRawTokenStandard
import javax.json.JsonObject; //導入依賴的package包/類
@RunAsClient
@Test(groups = TEST_GROUP_CDI,
description = "Verify that the injected raw token claim using @Claim(standard) is as expected")
public void verifyInjectedRawTokenStandard() throws Exception {
Reporter.log("Begin verifyInjectedRawTokenStandard\n");
String uri = baseURL.toExternalForm() + "/endp/verifyInjectedRawTokenStandard";
WebTarget echoEndpointTarget = ClientBuilder.newClient()
.target(uri)
.queryParam(Claims.raw_token.name(), token)
.queryParam(Claims.auth_time.name(), authTimeClaim);
Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
String replyString = response.readEntity(String.class);
JsonReader jsonReader = Json.createReader(new StringReader(replyString));
JsonObject reply = jsonReader.readObject();
Reporter.log(reply.toString());
Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
示例3: isStatusOk
import javax.json.JsonObject; //導入依賴的package包/類
/**
* Says if status is OK
* @return true if status is OK
*/
public boolean isStatusOk() {
if (jsonResult == null || jsonResult.isEmpty()) {
return false;
}
try {
JsonReader reader = Json.createReader(new StringReader(jsonResult));
JsonStructure jsonst = reader.read();
JsonObject object = (JsonObject) jsonst;
JsonString status = (JsonString) object.get("status");
if (status != null && status.getString().equals("OK")) {
return true;
} else {
return false;
}
} catch (Exception e) {
this.parseException = e;
invalidJsonStream = true;
return false;
}
}
示例4: getCookies
import javax.json.JsonObject; //導入依賴的package包/類
public List<Cookie> getCookies() {
List<Cookie> res = new ArrayList<>();
JsonObject o = inspector.sendCommand(Page.getCookies());
JsonArray cookies = o.getJsonArray("cookies");
if (cookies != null) {
for (int i = 0; i < cookies.size(); i++) {
JsonObject cookie = cookies.getJsonObject(i);
String name = cookie.getString("name");
String value = cookie.getString("value");
String domain = cookie.getString("domain");
String path = cookie.getString("path");
Date expiry = new Date(cookie.getJsonNumber("expires").longValue());
boolean isSecure = cookie.getBoolean("secure");
Cookie c = new Cookie(name, value, domain, path, expiry, isSecure);
res.add(c);
}
return res;
} else {
// TODO
}
return null;
}
示例5: verifyInjectedOptionalSubject
import javax.json.JsonObject; //導入依賴的package包/類
@GET
@Path("/verifyInjectedOptionalSubject")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyInjectedOptionalSubject(@QueryParam("sub") String subject) {
boolean pass = false;
String msg;
// sub
Optional<String> optSubValue = optSubject.getValue();
if(optSubValue == null || !optSubValue.isPresent()) {
msg = Claims.sub.name()+" value is null or missing, FAIL";
}
else if(optSubValue.get().equals(subject)) {
msg = Claims.sub.name()+" PASS";
pass = true;
}
else {
msg = String.format("%s: %s != %s", Claims.sub.name(), optSubValue, subject);
}
JsonObject result = Json.createObjectBuilder()
.add("pass", pass)
.add("msg", msg)
.build();
return result;
}
示例6: verifyInjectedSUB
import javax.json.JsonObject; //導入依賴的package包/類
@GET
@Path("/verifyInjectedSUB")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyInjectedSUB(@QueryParam("sub") String sub) {
boolean pass = false;
String msg;
// sUB
String subValue = this.subject;
if (subValue == null || subValue.length() == 0) {
msg = Claims.sub.name() + "value is null or empty, FAIL";
}
else if (subValue.equals(sub)) {
msg = Claims.sub.name() + " PASS";
pass = true;
}
else {
msg = String.format("%s: %s != %s", Claims.sub.name(), subValue, sub);
}
JsonObject result = Json.createObjectBuilder()
.add("pass", pass)
.add("msg", msg)
.build();
return result;
}
示例7: notifyMessageReceived
import javax.json.JsonObject; //導入依賴的package包/類
/** Notify listener that a message has been received */
protected final void notifyMessageReceived(JsonObject message) {
// If there's no id, it's an event message.
if (message.containsKey("id")) {
int commandId = message.getInt("id");
CommandFuture future = idToFuture.remove(commandId);
if (future != null) {
future.set(message);
}
// Or, it's a result object if it has a method.
} else if (message.containsKey("method")) {
DevtoolsEvent event = DevtoolsEvent.fromJson(message);
for (Consumer<DevtoolsEvent> listener : eventListeners) {
listener.accept(event);
}
} // Drop the message if we cannot identify it.
}
示例8: buildPostRunResponse
import javax.json.JsonObject; //導入依賴的package包/類
Response buildPostRunResponse(OccasionResponse occasionResponse) {
Throwable notificationThrowable = occasionResponse.getNotificationThrowable();
String requestResponse = occasionResponse.getNotificationType();
if (notificationThrowable != null) {
logger.fine("Throwable message: " + notificationThrowable.getMessage());
}
JsonBuilderFactory factory = Json.createBuilderFactory(null);
JsonObjectBuilder builder = factory.createObjectBuilder();
JsonObject responseBody = null;
if (requestResponse.equals(OccasionResponse.NOTIFICATION_TYPE_LOG)
|| requestResponse.equals(OccasionResponse.NOTIFICATION_TYPE_TWEET)) {
responseBody = builder.add(JSON_KEY_OCCASION_POST_RUN_SUCCESS, requestResponse).build();
} else {
responseBody = builder.add(JSON_KEY_OCCASION_POST_RUN_ERROR, requestResponse).build();
}
return Response.ok(responseBody, MediaType.APPLICATION_JSON).build();
}
示例9: notify
import javax.json.JsonObject; //導入依賴的package包/類
@POST
@Path("/")
@Consumes("application/json")
public Response notify(JsonObject payload) {
// Validate the JWT. At this point, anyone can submit a notification if they
// have a valid JWT.
try {
validateJWT();
} catch (JWTException jwte) {
return Response.status(Status.UNAUTHORIZED)
.type(MediaType.TEXT_PLAIN)
.entity(jwte.getMessage())
.build();
}
String notification = payload.getString(JSON_KEY_NOTIFICATION);
logger.info(notification);
return Response.ok().build();
}
示例10: verifyIssuerClaim
import javax.json.JsonObject; //導入依賴的package包/類
@RunAsClient
@Test(groups = TEST_GROUP_CDI,
description = "Verify that the injected token issuer claim is as expected")
public void verifyIssuerClaim() throws Exception {
Reporter.log("Begin verifyIssuerClaim");
String uri = baseURL.toExternalForm() + "/endp/verifyInjectedIssuer";
WebTarget echoEndpointTarget = ClientBuilder.newClient()
.target(uri)
.queryParam(Claims.iss.name(), TCKConstants.TEST_ISSUER)
.queryParam(Claims.auth_time.name(), authTimeClaim);
Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
String replyString = response.readEntity(String.class);
JsonReader jsonReader = Json.createReader(new StringReader(replyString));
JsonObject reply = jsonReader.readObject();
Reporter.log(reply.toString());
Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
示例11: verifyInjectedCustomDouble
import javax.json.JsonObject; //導入依賴的package包/類
@RunAsClient
@Test(groups = TEST_GROUP_CDI,
description = "Verify that the injected customDouble claim is as expected")
public void verifyInjectedCustomDouble() throws Exception {
Reporter.log("Begin verifyInjectedCustomDouble\n");
String uri = baseURL.toExternalForm() + "/endp/verifyInjectedCustomDouble";
WebTarget echoEndpointTarget = ClientBuilder.newClient()
.target(uri)
.queryParam("value", 3.141592653589793)
.queryParam(Claims.auth_time.name(), authTimeClaim);
Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
String replyString = response.readEntity(String.class);
JsonReader jsonReader = Json.createReader(new StringReader(replyString));
JsonObject reply = jsonReader.readObject();
System.out.println(reply);
Reporter.log(reply.toString());
Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
示例12: verifyOptionalAudience
import javax.json.JsonObject; //導入依賴的package包/類
@RunAsClient
@Test(groups = TEST_GROUP_JWT,
description = "Verify that the aud claim is as expected")
public void verifyOptionalAudience() throws Exception {
Reporter.log("Begin verifyOptionalAudience\n");
String uri = baseURL.toExternalForm() + "/endp/verifyOptionalAudience";
WebTarget echoEndpointTarget = ClientBuilder.newClient()
.target(uri)
.queryParam(Claims.aud.name(), null)
.queryParam(Claims.auth_time.name(), authTimeClaim);
Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
String replyString = response.readEntity(String.class);
JsonReader jsonReader = Json.createReader(new StringReader(replyString));
JsonObject reply = jsonReader.readObject();
Reporter.log(reply.toString());
Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
示例13: verifyInjectedUPN
import javax.json.JsonObject; //導入依賴的package包/類
@GET
@Path("/verifyInjectedUPN")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyInjectedUPN(@QueryParam("upn") String upn) {
boolean pass = false;
String msg;
// uPN
String upnValue = this.upn;
if (upnValue == null || upnValue.length() == 0) {
msg = Claims.upn.name() + "value is null or empty, FAIL";
}
else if (upnValue.equals(upn)) {
msg = Claims.upn.name() + " PASS";
pass = true;
}
else {
msg = String.format("%s: %s != %s", Claims.upn.name(), upnValue, upn);
}
JsonObject result = Json.createObjectBuilder()
.add("pass", pass)
.add("msg", msg)
.build();
return result;
}
示例14: testGeneratedMessageWithTypes
import javax.json.JsonObject; //導入依賴的package包/類
@Test
public void testGeneratedMessageWithTypes() {
JsonArray canonicalArguments =
Json.createArrayBuilder()
.add(Runtime.callArgument().withValue("val").withObjectId("567").properties())
.add(Runtime.callArgument().withValue(3).withObjectId("789").properties())
.build();
ImmutableList<Runtime.CallArgument> argumentsList =
ImmutableList.of(
Runtime.callArgument().withValue("val").withObjectId("567"),
Runtime.callArgument().withValue(3).withObjectId("789"));
DevtoolsCommand first =
Runtime.callFunctionOn("123", "function funky() { return 2; }")
.withArguments(argumentsList)
.withDoNotPauseOnExceptionAndMuteConsole(true)
.withGeneratePreview(false);
JsonObject firstParams = first.params();
assertThat(firstParams.getJsonArray("arguments")).isEqualTo(canonicalArguments);
}
示例15: verifyInjectedJTI
import javax.json.JsonObject; //導入依賴的package包/類
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
description = "Verify that the injected jti claim is as expected")
public void verifyInjectedJTI() throws Exception {
Reporter.log("Begin verifyInjectedJTI\n");
String uri = baseURL.toExternalForm() + "/endp/verifyInjectedJTI";
WebTarget echoEndpointTarget = ClientBuilder.newClient()
.target(uri)
.queryParam(Claims.jti.name(), "a-123")
.queryParam(Claims.auth_time.name(), authTimeClaim);
Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
String replyString = response.readEntity(String.class);
JsonReader jsonReader = Json.createReader(new StringReader(replyString));
JsonObject reply = jsonReader.readObject();
Reporter.log(reply.toString());
Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}