当前位置: 首页>>代码示例>>Java>>正文


Java JsonObject类代码示例

本文整理汇总了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"));
}
 
开发者ID:eclipse,项目名称:microprofile-jwt-auth,代码行数:19,代码来源:ProviderInjectionTest.java

示例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"));
}
 
开发者ID:eclipse,项目名称:microprofile-jwt-auth,代码行数:19,代码来源:ClaimValueInjectionTest.java

示例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;
}

   }
 
开发者ID:kawansoft,项目名称:aceql-http,代码行数:30,代码来源:ResultAnalyzer.java

示例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;
}
 
开发者ID:google,项目名称:devtools-driver,代码行数:23,代码来源:RemoteIOSWebDriver.java

示例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;
}
 
开发者ID:eclipse,项目名称:microprofile-jwt-auth,代码行数:25,代码来源:ClaimValueInjectionEndpoint.java

示例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;
}
 
开发者ID:eclipse,项目名称:microprofile-jwt-auth,代码行数:25,代码来源:PrimitiveInjectionEndpoint.java

示例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.
}
 
开发者ID:google,项目名称:devtools-driver,代码行数:18,代码来源:DevtoolsDebugger.java

示例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();
  }
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:19,代码来源:OccasionResource.java

示例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();
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:22,代码来源:NotificationResource.java

示例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"));
}
 
开发者ID:eclipse,项目名称:microprofile-jwt-auth,代码行数:19,代码来源:ClaimValueInjectionTest.java

示例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"));
}
 
开发者ID:eclipse,项目名称:microprofile-jwt-auth,代码行数:20,代码来源:ClaimValueInjectionTest.java

示例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"));
}
 
开发者ID:eclipse,项目名称:microprofile-jwt-auth,代码行数:19,代码来源:RequiredClaimsTest.java

示例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;
}
 
开发者ID:eclipse,项目名称:microprofile-jwt-auth,代码行数:25,代码来源:PrimitiveInjectionEndpoint.java

示例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);
}
 
开发者ID:google,项目名称:devtools-driver,代码行数:21,代码来源:CommandGenerationTest.java

示例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"));
}
 
开发者ID:eclipse,项目名称:microprofile-jwt-auth,代码行数:19,代码来源:PrimitiveInjectionTest.java


注:本文中的javax.json.JsonObject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。