Java 类javax.json.Json 实例源码

项目:JSON-Processing-with-Java-EE    文件:StreamingExample1.java   
private static void parseJsonString() {

        JsonParser parser = Json.createParser(new StringReader(JSON));

        while (parser.hasNext()) {
            JsonParser.Event event = parser.next();
            switch (event) {
                case START_ARRAY:
                case END_ARRAY:
                case START_OBJECT:
                case END_OBJECT:
                case VALUE_FALSE:
                case VALUE_NULL:
                case VALUE_TRUE:
                    System.out.println(event.toString());
                    break;
                case KEY_NAME:
                    System.out.print(event.toString() + " " + parser.getString() + " - ");
                    break;
                case VALUE_STRING:
                case VALUE_NUMBER:
                    System.out.println(event.toString() + " " + parser.getString());
                    break;
            }
        }
    }
项目:microprofile-jwt-auth    文件:JsonValuejectionEndpoint.java   
@GET
@Path("/verifyInjectedIssuer")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed("Tester")
public JsonObject verifyInjectedIssuer(@QueryParam("iss") String iss) {
    boolean pass = false;
    String msg;
    String issValue = issuer.getString();
    if(issValue == null || issValue.length() == 0) {
        msg = Claims.iss.name()+"value is null or empty, FAIL";
    }
    else if(issValue.equals(iss)) {
        msg = Claims.iss.name()+" PASS";
        pass = true;
    }
    else {
        msg = String.format("%s: %s != %s", Claims.iss.name(), issValue, iss);
    }
    JsonObject result = Json.createObjectBuilder()
        .add("pass", pass)
        .add("msg", msg)
        .build();
    return result;
}
项目:microprofile-jwt-auth    文件:ProviderInjectionEndpoint.java   
@GET
@Path("/verifyInjectedIssuer")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyInjectedIssuer(@QueryParam("iss") String iss) {
    boolean pass = false;
    String msg;
    String issValue = issuer.get();
    if(issValue == null || issValue.length() == 0) {
        msg = Claims.iss.name()+"value is null or empty, FAIL";
    }
    else if(issValue.equals(iss)) {
        msg = Claims.iss.name()+" PASS";
        pass = true;
    }
    else {
        msg = String.format("%s: %s != %s", Claims.iss.name(), issValue, iss);
    }
    JsonObject result = Json.createObjectBuilder()
        .add("pass", pass)
        .add("msg", msg)
        .build();
    return result;
}
项目:javaee-calculator    文件:AdditionResourceIT.java   
@Test
public void additionWithIncompleteInput() {
    JsonObject input = Json.createObjectBuilder().
            add("b", 2).
            build();
    Response response = this.tut.
            request(MediaType.APPLICATION_JSON).
            post(json(input));
    assertThat(response.getStatus(), is(400));
    String cause = response.getHeaderString("cause");
    assertThat(cause, containsString(" a "));

    input = Json.createObjectBuilder().
            add("a", 2).
            build();
    response = this.tut.
            request(MediaType.APPLICATION_JSON).
            post(json(input));
    assertThat(response.getStatus(), is(400));
    cause = response.getHeaderString("cause");
    assertThat(cause, containsString(" b "));
}
项目:E-Clinic    文件:ReligionRestEndPoint.java   
@GET
@Path("find")
@Produces(MediaType.APPLICATION_JSON)
public Response find() {
    JsonArray build = null;
    try {
        build = religionService.get().stream().map(h -> Json.createObjectBuilder()
                .add("id", h.getReligionId())
                .add("name", h.getName())
                .build())
                .collect(Json::createArrayBuilder, JsonArrayBuilder::add, JsonArrayBuilder::add)
                .build();
    } catch (Exception ex) {
        return Response.ok().header("Exception", ex.getMessage()).build();
    }
    return Response.ok().entity(build == null ? "No data found" : build).build();
}
项目:poi-visualizer    文件:TreeObservable.java   
public void mergeProperties(final String properties) {
    if (StringUtils.isEmpty(properties)) {
        return;
    }

    if (StringUtils.isEmpty(getProperties())) {
        setProperties(properties);
        return;
    }

    final JsonReaderFactory fact = Json.createReaderFactory(null);
    final JsonReader r1 = fact.createReader(new StringReader(getProperties()));
    final JsonObjectBuilder jbf = Json.createObjectBuilder(r1.readObject());

    final JsonReader r2 = fact.createReader(new StringReader(getProperties()));
    final JsonObject obj2 = r2.readObject();

    for (Entry<String, JsonValue> jv : obj2.entrySet()) {
        jbf.add(jv.getKey(), jv.getValue());
    }

    setProperties(jbf.build().toString());
}
项目:microprofile-jwt-auth    文件:ProviderInjectionEndpoint.java   
@GET
@Path("/verifyInjectedAudience")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyInjectedAudience(@QueryParam("aud") String audience) {
    boolean pass = false;
    String msg;
    // aud
    Set<String> audValue = aud.get();
    if(audValue == null || audValue.size() == 0) {
        msg = Claims.aud.name()+"value is null or empty, FAIL";
    }
    else if(audValue.contains(audience)) {
        msg = Claims.aud.name()+" PASS";
        pass = true;
    }
    else {
        msg = String.format("%s: %s != %s", Claims.aud.name(), audValue, audience);
    }
    JsonObject result = Json.createObjectBuilder()
        .add("pass", pass)
        .add("msg", msg)
        .build();
    return result;
}
项目:microprofile-jwt-auth    文件:ClaimValueInjectionEndpoint.java   
@GET
@Path("/verifyInjectedCustomDouble")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyInjectedCustomDouble(@QueryParam("value") Double value) {
    boolean pass = false;
    String msg;
    // iat
    JsonNumber customValue = customDouble.getValue();
    if(customValue == null) {
        msg = "customDouble value is null, FAIL";
    }
    else if(Math.abs(customValue.doubleValue() - value.doubleValue()) < 0.00001) {
        msg = "customDouble PASS";
        pass = true;
    }
    else {
        msg = String.format("customDouble: %s != %.8f", customValue, value);
    }
    JsonObject result = Json.createObjectBuilder()
        .add("pass", pass)
        .add("msg", msg)
        .build();
    return result;
}
项目:microprofile-jwt-auth    文件:RequiredClaimsEndpoint.java   
@GET
@Path("/verifyIssuedAt")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyIssuedAt(@QueryParam("iat") Long iat) {
    boolean pass = false;
    String msg;
    // iat
    Long iatValue = rawTokenJson.getIssuedAtTime();
    if (iatValue == null || iatValue.intValue() == 0) {
        msg = Claims.iat.name() + "value is null or empty, FAIL";
    }
    else if (iatValue.equals(iat)) {
        msg = Claims.iat.name() + " PASS";
        pass = true;
    }
    else {
        msg = String.format("%s: %s != %s", Claims.iat.name(), iatValue, iat);
    }
    JsonObject result = Json.createObjectBuilder()
            .add("pass", pass)
            .add("msg", msg)
            .build();
    return result;
}
项目:microprofile-jwt-auth    文件:ProviderInjectionTest.java   
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
    description = "Verify that the injected sub claim is as expected")
public void verifyInjectedOptionalSubject() throws Exception {
    Reporter.log("Begin verifyInjectedOptionalSubject\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedOptionalSubject";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.sub.name(), "24400320")
        .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"));
}
项目:microprofile-jwt-auth    文件:JsonValueInjectionTest.java   
@RunAsClient
@Test(groups = TEST_GROUP_CDI_JSON,
    description = "Verify that the injected customDouble claim is as expected")
public void verifyInjectedCustomDouble2() throws Exception {
    Reporter.log("Begin verifyInjectedCustomDouble2\n");
    String token2 = TokenUtils.generateTokenString("/Token2.json");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedCustomDouble";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam("value", 3.241592653589793)
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token2).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"));
}
项目:microprofile-jwt-auth    文件:PrimitiveInjectionTest.java   
@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"));
}
项目:microprofile-jwt-auth    文件:RequiredClaimsTest.java   
@RunAsClient
@Test(groups = TEST_GROUP_JWT,
        description = "Verify that the token issuer claim is as expected")
public void verifyIssuerClaim() throws Exception {
    Reporter.log("Begin verifyIssuerClaim");
    String uri = baseURL.toExternalForm() + "/endp/verifyIssuer";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
            .target(uri)
            .queryParam(Claims.iss.name(), 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"));
}
项目:microprofile-jwt-auth    文件:ClaimValueInjectionTest.java   
@RunAsClient
@Test(groups = TEST_GROUP_CDI,
    description = "Verify that the injected iat claim using @Claim(standard) is as expected")
public void verifyInjectedIssuedAtStandard() throws Exception {
    Reporter.log("Begin verifyInjectedIssuedAtStandard\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedIssuedAtStandard";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.iat.name(), iatClaim)
        .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"));
}
项目:KITE    文件:RTCIceCandidatePairStats.java   
@Override
public JsonObjectBuilder getJsonObjectBuilder() {
    JsonObjectBuilder jsonObjectBuilder =
            Json.createObjectBuilder()
                    .add("transportId", this.transportId)
                    .add("localCandidateId", this.localCandidateId)
                    .add("remoteCandidateId", this.remoteCandidateId)
                    .add("state", this.state)
                    .add("priority", this.priority)
                    .add("nominated", this.nominated)
                    .add("bytesSent", this.bytesSent)
                    .add("currentRoundTripTime", this.currentRoundTripTime)
                    .add("totalRoundTripTime", this.totalRoundTripTime)
                    .add("bytesReceived", this.bytesReceived);
    return jsonObjectBuilder;
}
项目:versioneye-api    文件:JsonAuthenticatedTestCase.java   
/**
 * JsonAuthenticated can fetch the raw json.
 */
@Test
public void knowsJson() {
    final Authenticated auth = new JsonAuthenticated(
        Json.createObjectBuilder()
            .add("username", "amihaiemil")
            .add("active", true)
            .build()
    );
    JsonObject user = auth.json();
    MatcherAssert.assertThat(user, Matchers.notNullValue());
    MatcherAssert.assertThat(
        user.getString("username"), Matchers.equalTo("amihaiemil")
    );
    MatcherAssert.assertThat(
        user.getBoolean("active"), Matchers.is(true)
    );

}
项目:microprofile-jwt-auth    文件:ClaimValueInjectionEndpoint.java   
@GET
@Path("/verifyInjectedIssuedAt")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyInjectedIssuedAt(@QueryParam("iat") Long iat) {
    boolean pass = false;
    String msg;
    // iat
    Long iatValue = issuedAt.getValue();
    if(iatValue == null || iatValue.intValue() == 0) {
        msg = Claims.iat.name()+"value is null or empty, FAIL";
    }
    else if(iatValue.equals(iat)) {
        msg = Claims.iat.name()+" PASS";
        pass = true;
    }
    else {
        msg = String.format("%s: %s != %s", Claims.iat.name(), iatValue, iat);
    }
    JsonObject result = Json.createObjectBuilder()
        .add("pass", pass)
        .add("msg", msg)
        .build();
    return result;
}
项目:microprofile-jwt-auth    文件:RequiredClaimsTest.java   
@RunAsClient
@Test(groups = TEST_GROUP_JWT,
        description = "Verify that the jti claim is as expected")
public void verifyJTI() throws Exception {
    Reporter.log("Begin verifyJTI\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyJTI";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
            .target(uri)
            .queryParam(Claims.jti.name(), "a-f2b2180c")
            .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"));
}
项目:KITE    文件:DataCenterServlet.java   
/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

  JsonReader jsonReader = null;
  JsonObject jsonObject = null;
  try {
    jsonReader = Json.createReader(request.getReader());
    jsonObject = jsonReader.readObject();
    if (log.isDebugEnabled())
      log.debug("in->jsonObject: " + jsonObject);
    System.out.println("Json object data->"+jsonObject);
    DataCenterQueueManager.getInstance().queue.put(jsonObject);
  } catch (JsonException | IllegalStateException | InterruptedException e) {
    log.error("adding to queue", e);
  } finally {
    if (jsonReader != null)
      jsonReader.close();
  }
}
项目:versioneye-api    文件:JsonVulnerabilityTestCase.java   
/**
 * JsonVulnerability can return more affected version. 
 */
@Test
public void returnsMoreAffectedVersions() {
    final Vulnerability vln = new JsonVulnerability(
        Json.createObjectBuilder()
            .add(
                "affected_versions",
                Json.createArrayBuilder()
                    .add("1")
                    .add("2")
                    .add("3")
                )
            .build()
    );
    final List<String> affected = vln.affectedVersions();
    MatcherAssert.assertThat(affected, Matchers.hasSize(3));
    MatcherAssert.assertThat(affected.get(0), Matchers.is("1"));
    MatcherAssert.assertThat(affected.get(1), Matchers.is("2"));
    MatcherAssert.assertThat(affected.get(2), Matchers.is("3"));
}
项目:microprofile-jwt-auth    文件:ProviderInjectionTest.java   
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
    description = "Verify that the injected customDouble claim is as expected")
public void verifyInjectedCustomDouble2() 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();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
项目:E-Clinic    文件:GenderRestEndPoint.java   
@GET
@Path("find")
@Produces(MediaType.APPLICATION_JSON)
public Response find() {
    JsonArray build = null;
    try {
        build = genderService.get().stream().map(h -> Json.createObjectBuilder()
                .add("id", h.getGenderId())
                .add("value", h.getGenderName())
                .build())
                .collect(Json::createArrayBuilder, JsonArrayBuilder::add, JsonArrayBuilder::add)
                .build();
    } catch (Exception ex) {
        return Response.ok().header("Exception", ex.getMessage()).build();
    }
    return Response.ok().entity(build == null ? "No data found" : build).build();
}
项目:microprofile-jwt-auth    文件:ClaimValueInjectionTest.java   
@RunAsClient
@Test(groups = TEST_GROUP_CDI,
    description = "Verify that the injected sub claim is as expected")
public void verifyInjectedOptionalSubject() throws Exception {
    Reporter.log("Begin verifyInjectedOptionalSubject\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedOptionalSubject";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.sub.name(), "24400320")
        .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"));
}
项目:microprofile-jwt-auth    文件:ClaimValueInjectionEndpoint.java   
@GET
@Path("/verifyInjectedAudienceStandard")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject verifyInjectedAudienceStandard(@QueryParam("aud") String audience) {
    boolean pass = false;
    String msg;
    // aud
    Set<String> audValue = audStandard.getValue();
    if(audValue == null || audValue.size() == 0) {
        msg = Claims.aud.name()+"value is null or empty, FAIL";
    }
    else if(audValue.contains(audience)) {
        msg = Claims.aud.name()+" PASS";
        pass = true;
    }
    else {
        msg = String.format("%s: %s != %s", Claims.aud.name(), audValue, audience);
    }
    JsonObject result = Json.createObjectBuilder()
        .add("pass", pass)
        .add("msg", msg)
        .build();
    return result;
}
项目:KITE    文件:GetUpdateTest.java   
@Override
public Object testScript() throws Exception {
    String result = "";
    webDriver = this.getWebDriverList().get(0);
    JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
    for (String target: subjectList.keySet()){
        subject = target;
        this.takeAction();
        result = this.testJavaScript();
        subjectList.replace(target,result);
        jsonObjectBuilder.add(target, result);
    }
    JsonObject payload = jsonObjectBuilder.build();
    if (logger.isInfoEnabled())
      logger.info(payload.toString());
    return payload.toString();
}
项目:E-Clinic    文件:ReceptionistRestEndPoint.java   
@GET
@Path("find")
@Produces(MediaType.APPLICATION_JSON)
public Response find() {
    JsonArray build = null;
    try {
        build = receptionistService.get().stream().map(h -> Json.createObjectBuilder()
                .add("id", h.getReceptionistId())
                .add("name", h.getPersonId().getFirstName())
                .build())
                .collect(Json::createArrayBuilder, JsonArrayBuilder::add, JsonArrayBuilder::add)
                .build();
    } catch (Exception ex) {
        return Response.ok().header("Exception", ex.getMessage()).build();
    }
    return Response.ok().entity(build == null ? "No data found" : build).build();
}
项目:E-Clinic    文件:AddressRestEndPoint.java   
@GET
@Path("find")
@Produces(MediaType.APPLICATION_JSON)
public Response find() {
    JsonArray build = null;
    try {
        build = addressService.get().stream().map(h -> Json.createObjectBuilder()
                .add("id", h.getAddressId())
                .add("name", h.getStreetName())
                .build())
                .collect(Json::createArrayBuilder, JsonArrayBuilder::add, JsonArrayBuilder::add)
                .build();
    } catch (Exception ex) {
        return Response.ok().header("Exception", ex.getMessage()).build();
    }
    return Response.ok().entity(build == null ? "No data found" : build).build();
}
项目:microprofile-jwt-auth    文件:ClaimValueInjectionTest.java   
@RunAsClient
@Test(groups = TEST_GROUP_CDI,
    description = "Verify that the injected aud claim using @Claim(standard) is as expected")
public void verifyInjectedAudienceStandard() throws Exception {
    Reporter.log("Begin verifyInjectedAudienceStandard\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedAudienceStandard";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.aud.name(), "s6BhdRkqt3")
        .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"));
}
项目:WiFiProbeAnalysis    文件:UserFlowEncoder.java   
public String encode(UserVisitBean userDiagramData) throws EncodeException {
    StringWriter writer = new StringWriter();
    //Makes use of the JSON Streaming API to build the JSON string.
    Json.createGenerator(writer)
            .writeStartObject()
            .write("time", String.valueOf(userDiagramData.getTime()))
            .write("totalFlow", userDiagramData.getTotalFlow())
            .write("checkInFlow", userDiagramData.getCheckInFlow())
            .write("checkInRatio", userDiagramData.getCheckInRate())
            .write("deepVisitRatio", userDiagramData.getDeepVisitRate())
            .write("jumpRatio", userDiagramData.getShallowVisitRate())
            .writeEnd()
            .flush();
    //System.out.println(writer.toString());
    return writer.toString();
}
项目:launcher-backend    文件:MissionControlStatusEndpoint.java   
@OnOpen
public void onOpen(Session session, @PathParam("uuid") String uuid) {
    UUID key = UUID.fromString(uuid);
    peers.put(key, session);
    JsonArrayBuilder builder = Json.createArrayBuilder();
    for (StatusEventType statusEventType : StatusEventType.values()) {
        JsonObjectBuilder object = Json.createObjectBuilder();
        builder.add(object.add(statusEventType.name(), statusEventType.getMessage()).build());
    }

    RemoteEndpoint.Async asyncRemote = session.getAsyncRemote();
    asyncRemote.sendText(builder.build().toString());
    // Send pending messages
    List<String> messages = messageBuffer.remove(key);
    if (messages != null) {
        messages.forEach(asyncRemote::sendText);
    }
}
项目:comdor    文件:GithubStepsTestCase.java   
/**
 * GithubSteps logs the received comment and author and
 * executes the given steps.
 * @throws Exception If something goes wrong.
 */
@Test
public void logsAndExecutesSteps() throws Exception {
    final Command comment = Mockito.mock(Command.class);
    Mockito.when(comment.json()).thenReturn(
        Json.createObjectBuilder().add("body", "@comdor run").build()
    );
    Mockito.when(comment.author()).thenReturn("amihaiemil");
    final Step toExecute = Mockito.mock(Step.class);

    final Steps steps = new GithubSteps(toExecute, comment);

    final Log log = Mockito.mock(Log.class);
    final Logger slf4j = Mockito.mock(Logger.class);
    Mockito.when(log.logger()).thenReturn(slf4j);

    steps.perform(log);

    Mockito.verify(slf4j).info("Received command: @comdor run");
    Mockito.verify(slf4j).info("Author login: amihaiemil");
    Mockito.verify(toExecute).perform(comment, log);
}
项目:bluemix-liberty-microprofile-demo    文件:ReservationJsonAdapter.java   
@Override
public JsonObject toJson(Reservation reservation) {
    Objects.requireNonNull(reservation, RESERVATION_ISNT_ALLOWED_TO_BE_NULL);
    JsonObjectBuilder builder = Json.createObjectBuilder();
       if (reservation.getId() != null)
           builder = builder.add("id", reservation.getId());
       if (reservation.getVenue() != null)
        builder = builder.add("venue", reservation.getVenue());
       if (reservation.getReservedBy() != null)
        builder = builder.add("reservedBy", reservation.getReservedBy());
       if (reservation.getDate() != null)           
        builder = builder.add("date", format(reservation.getDate()));
       if (reservation.getStartTime() != null)
        builder = builder.add("startAt", format(reservation.getStartTime()));
       if (reservation.getDuration() != null)
           builder = builder.add("duration", format(reservation.getDuration()));
       return builder.build();
}
项目:microprofile-jwt-auth    文件:JsonValuejectionEndpoint.java   
@GET
@Path("/verifyInjectedIssuedAt")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed("Tester")
public JsonObject verifyInjectedIssuedAt(@QueryParam("iat") Long iat) {
    boolean pass = false;
    String msg;
    // iat
    Long iatValue = issuedAt.longValue();
    if(iatValue == null || iatValue.intValue() == 0) {
        msg = Claims.iat.name()+"value is null or empty, FAIL";
    }
    else if(iatValue.equals(iat)) {
        msg = Claims.iat.name()+" PASS";
        pass = true;
    }
    else {
        msg = String.format("%s: %s != %s", Claims.iat.name(), iatValue, iat);
    }
    JsonObject result = Json.createObjectBuilder()
        .add("pass", pass)
        .add("msg", msg)
        .build();
    return result;
}
项目:microprofile-jwt-auth    文件:JsonValueInjectionTest.java   
@RunAsClient
@Test(groups = TEST_GROUP_CDI_JSON,
    description = "Verify that the injected token issuer claim is as expected from Token2")
public void verifyIssuerClaim2() throws Exception {
    Reporter.log("Begin verifyIssuerClaim2");
    String token2 = TokenUtils.generateTokenString("/Token2.json");
    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 " + token2).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"));
}
项目:microprofile-jwt-auth    文件:JsonValueInjectionTest.java   
@RunAsClient
@Test(groups = TEST_GROUP_CDI_JSON,
    description = "Verify that the injected aud claim is as expected from Token2")
public void verifyInjectedAudience2() throws Exception {
    Reporter.log("Begin verifyInjectedAudience2\n");
    String token2 = TokenUtils.generateTokenString("/Token2.json");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedAudience";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.aud.name(), "s6BhdRkqt3.2")
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token2).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"));
}
项目:tap17-muggl-javaee    文件:StatusEndpoint.java   
private static String jsonStudentList(List<Student> students) {

        StringWriter swriter = new StringWriter();
        try (JsonGenerator gen = Json.createGenerator(swriter)) {
            gen.writeStartObject();
            gen.write("type", "list");
            gen.writeStartArray("body");
            for (Student student : students) {
                gen.writeStartObject();
                gen.write("name", student.getName());
                gen.write("status", student.getStatus().toString());
                gen.writeEnd();
            }
            gen.writeEnd();
            gen.writeEnd();
        }

        return swriter.toString();
    }
项目:microprofile-jwt-auth    文件:ProviderInjectionTest.java   
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
    description = "Verify that the injected raw token claim is as expected")
public void verifyInjectedRawToken() throws Exception {
    Reporter.log("Begin verifyInjectedRawToken\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedRawToken";
    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"));
}
项目:microprofile-jwt-auth    文件:ClaimValueInjectionTest.java   
@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"));
}
项目:E-Clinic    文件:DoctorRestEndPoint.java   
@GET
@Path("find/{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response find(@PathParam("id") @Valid String id) {
    JsonObject build = null;
    try {
        Doctor get = doctorService.get(Integer.valueOf(id));
        build = Json.createObjectBuilder()
                .add("firstname", get.getPersonId().getFirstName())
                .add("lastname", get.getPersonId().getLastName())
                .add("id", get.getDoctorId())
                .build();

    } catch (Exception ex) {
        return Response.ok().header("Exception", ex.getMessage()).build();
    }
    return Response.ok().entity(build == null ? "No data found" : build).build();
}