Java Code Examples for javax.json.JsonReader

The following examples show how to use javax.json.JsonReader. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@RunAsClient
@Test(groups = TEST_GROUP_CDI,
    description = "Verify that the injected customString claim is as expected")
public void verifyInjectedCustomString() throws Exception {
    Reporter.log("Begin verifyInjectedCustomString\n");
    String uri = baseURL.toExternalForm() + "endp/verifyInjectedCustomString";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam("value", "customStringValue")
        .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"));
}
 
Example 2
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
    description = "Verify that the injected aud claim is as expected")
public void verifyInjectedAudience() throws Exception {
    Reporter.log("Begin verifyInjectedAudience\n");
    String uri = baseURL.toExternalForm() + "endp/verifyInjectedAudience";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.aud.name(), new String[]{"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();
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 3
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
    description = "Verify that the injected authenticated principal is as expected")
public void verifyInjectedPrincipal() throws Exception {
    Reporter.log("Begin verifyInjectedPrincipal, baseURL="+baseURL.toExternalForm() );
    String uri = baseURL.toExternalForm() + "endp/verifyInjectedPrincipal";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri);
    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"));
}
 
Example 4
Source Project: fido2   Source File: clientUtil.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public static String keyHandleDecode(String Input, int returnType) {

        JsonReader jsonReader = Json.createReader(new StringReader(Input));
        JsonObject jsonObject = jsonReader.readObject();
        jsonReader.close();
        //System.out.println("Last name : "+jsonObject.getString("swair"));
        if (returnType == 0) {
            return jsonObject.getString("key");

        } else if (returnType == 1) {

            return jsonObject.getString("sha1");

        } else {
            return jsonObject.getString("origin_hash");
        }

    }
 
Example 5
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
    description = "Verify that the injected groups claim is as expected")
public void verifyInjectedGroups() throws Exception {
    Reporter.log("Begin verifyInjectedGroups\n");
    String uri = baseURL.toExternalForm() + "endp/verifyInjectedGroups";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.groups.name(), new String[]{
                "Echoer", "Tester", "group1", "group2"})
            .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"));
}
 
Example 6
Source Project: rapid   Source File: Image.java    License: MIT License 6 votes vote down vote up
@GET
@Path("json")
public Response listImages(@DefaultValue("false") @QueryParam("all") String all,
                           @DefaultValue("false") @QueryParam("digests") String digests,
                           @QueryParam("filters") String filters) throws UnsupportedEncodingException {

    WebTarget target = resource().path(IMAGES).path("json")
            .queryParam("all", all)
            .queryParam("digests", digests);

    if (Objects.nonNull(filters))
        target = target.queryParam(FILTERS, URLEncoder.encode(filters, "UTF-8"));

    Response response = getResponse(target);
    try {
        String raw = response.readEntity(String.class);
        JsonReader reader = Json.createReader(new StringReader(raw));
        return Response.status(response.getStatus()).entity(reader.read()).build();
    } finally {
        response.close();
    }
}
 
Example 7
Source Project: fido2   Source File: Common.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * createClientData Decodes the returned value from a preregister webservice
 * request
 *
 * @param input String containing JSON object
 * @param type int value denoting the element we want from the JSON
 * @return String with the returned value from the JSON
 */
public static Object decodeRegistrationSignatureRequest(String input, int type) {
    JsonObject jsonObject;
    try (JsonReader jsonReader = Json.createReader(new StringReader(input))) {
        jsonObject = jsonReader.readObject();
    }

    switch (type) {
        case Constants.JSON_KEY_SESSIONID:
            return jsonObject.getString(Constants.JSON_KEY_SESSIONID_LABEL);
        case Constants.JSON_KEY_CHALLENGE:
            return jsonObject.getString(Constants.JSON_KEY_CHALLENGE_LABEL);
        case Constants.JSON_KEY_VERSION:
            return jsonObject.getString(Constants.JSON_KEY_VERSION_LABEL);
        case Constants.JSON_KEY_APPID:
            return jsonObject.getString(Constants.JSON_KEY_APPID_LABEL);
            case Constants.JSON_KEY_RP:
            return jsonObject.getJsonObject(Constants.JSON_KEY_RP_LABEL);
        default:
            return null; // Shouldn't happen, but....
    }
}
 
Example 8
Source Project: quarkus   Source File: PrimitiveInjectionUnitTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verify that the token customString claim is as expected
 *
 */
@Test()
public void verifyInjectedCustomString() {
    io.restassured.response.Response response = RestAssured.given().auth()
            .oauth2(token)
            .when()
            .queryParam("value", "customStringValue")
            .queryParam(Claims.auth_time.name(), authTimeClaim)
            .get("/endp/verifyInjectedCustomString").andReturn();

    Assertions.assertEquals(HttpURLConnection.HTTP_OK, response.getStatusCode());
    String replyString = response.body().asString();
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Assertions.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 9
Source Project: quarkus   Source File: RequiredClaimsUnitTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verify that the token upn claim is as expected
 *
 */
@Test()
public void verifyUPN() {
    io.restassured.response.Response response = RestAssured.given().auth()
            .oauth2(token)
            .when()
            .queryParam(Claims.upn.name(), "[email protected]")
            .queryParam(Claims.iss.name(), "https://server.example.com")
            .queryParam(Claims.auth_time.name(), authTimeClaim)
            .get("/endp/verifyUPN").andReturn();

    Assertions.assertEquals(HttpURLConnection.HTTP_OK, response.getStatusCode());
    String replyString = response.body().asString();
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Assertions.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 10
@Test
@Disabled
public void testNow() throws URISyntaxException {
    Response response = given()
            .when()
            .get("/data/time/now")
            .andReturn();

    Assertions.assertEquals(HttpURLConnection.HTTP_OK, response.getStatusCode());
    String replyString = response.body().asString();
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    System.out.println(reply);
    Now numbers = response.as(Now.class);
    System.out.println(numbers);
}
 
Example 11
Source Project: nifi   Source File: TestSiteToSiteStatusReportingTask.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessorStatusWithNullValues() throws IOException, InitializationException {
    final ProcessGroupStatus pgStatus = generateProcessGroupStatus("root", "Awesome", 1, 0);

    final Map<PropertyDescriptor, String> properties = new HashMap<>();
    properties.put(SiteToSiteUtils.BATCH_SIZE, "4");
    properties.put(SiteToSiteStatusReportingTask.COMPONENT_NAME_FILTER_REGEX, "Awesome.*");
    properties.put(SiteToSiteStatusReportingTask.COMPONENT_TYPE_FILTER_REGEX, "(Processor)");
    properties.put(SiteToSiteStatusReportingTask.ALLOW_NULL_VALUES,"true");

    MockSiteToSiteStatusReportingTask task = initTask(properties, pgStatus);
    task.onTrigger(context);

    final String msg = new String(task.dataSent.get(0), StandardCharsets.UTF_8);
    JsonReader jsonReader = Json.createReader(new ByteArrayInputStream(msg.getBytes()));
    JsonObject object = jsonReader.readArray().getJsonObject(0);
    JsonValue type = object.get("processorType");
    assertEquals(type, JsonValue.NULL);
}
 
Example 12
Source Project: rapid   Source File: Config.java    License: MIT License 6 votes vote down vote up
@DELETE
@Path("{id}")
public Response deleteConfig(@PathParam("id") String configId) {

    WebTarget target = resource().path(CONFIGS).path(configId);
    Response response = deleteResponse(target);

    String entity = response.readEntity(String.class);

    if (entity.isEmpty()) {
        JsonObjectBuilder jsonObject = Json.createObjectBuilder();
        jsonObject.add("id", configId);
        jsonObject.add("message", "the config is deleted.");

        return Response.ok(jsonObject.build()).build();
    }

    try (JsonReader json = Json.createReader(new StringReader(entity))) {
        return Response.status(response.getStatus()).entity(json.read()).build();
    }
}
 
Example 13
Source Project: jeddict   Source File: JsonParser.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public EntityMappings generateModel(EntityMappings entityMappings, Reader reader) throws IOException, ProcessInterruptedException {
    String progressMsg = getMessage(DocWizardDescriptor.class, "MSG_Progress_Class_Diagram_Pre"); //NOI18N;
    reporter.accept(progressMsg);

    String version = getModelerFileVersion();

    if (entityMappings == null) {
        entityMappings = EntityMappings.getNewInstance(version);
        entityMappings.setGenerated();
    }

    JsonReader jsonReader = Json.createReader(reader);
    JsonObject jsonObject = jsonReader.readObject();
    JavaClass javaClass;
    if (jpaSupport) {
        javaClass = generateEntity(entityMappings, "RootClass", jsonObject);
    } else {
        javaClass = generateClass(entityMappings, "RootClass", jsonObject);
    }
    javaClass.setXmlRootElement(jaxbSupport);
    entityMappings.setJaxbSupport(jaxbSupport);

    return entityMappings;
}
 
Example 14
Source Project: microprofile-jwt-auth   Source File: IssValidationTest.java    License: Apache License 2.0 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_CONFIG,
    description = "Validate that JWK with iss that matches mp.jwt.verify.issuer returns HTTP_OK")
public void testRequiredIss() throws Exception {
    Reporter.log("testRequiredIss, expect HTTP_OK");

    String uri = baseURL.toExternalForm() + "endp/verifyIssIsOk";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        ;
    Response response = echoEndpointTarget.request(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"));
}
 
Example 15
Source Project: takes   Source File: RsPrettyJson.java    License: MIT License 6 votes vote down vote up
/**
 * Format body with proper indents.
 * @param body Response body
 * @return New properly formatted body
 * @throws IOException If fails
 */
private static byte[] transform(final InputStream body) throws IOException {
    final ByteArrayOutputStream res = new ByteArrayOutputStream();
    try (JsonReader rdr = Json.createReader(body)) {
        final JsonObject obj = rdr.readObject();
        try (JsonWriter wrt = Json.createWriterFactory(
            Collections.singletonMap(JsonGenerator.PRETTY_PRINTING, true)
            )
            .createWriter(res)
        ) {
            wrt.writeObject(obj);
        }
    } catch (final JsonException ex) {
        throw new IOException(ex);
    }
    return res.toByteArray();
}
 
Example 16
@Test
public void testNoExceptions() throws Exception {
    configure(Collections.emptyMap(), Collections.emptyMap(), false);
    final String msg = "Logging test: JsonFormatterTestCase.testNoExceptions";
    int statusCode = getResponse(msg, Collections.singletonMap(LoggingServiceActivator.LOG_EXCEPTION_KEY, "false"));
    Assert.assertTrue("Invalid response statusCode: " + statusCode, statusCode == HttpStatus.SC_OK);

    final List<String> expectedKeys = createDefaultKeys();

    for (String s : Files.readAllLines(logFile, StandardCharsets.UTF_8)) {
        if (s.trim().isEmpty()) continue;
        try (JsonReader reader = Json.createReader(new StringReader(s))) {
            final JsonObject json = reader.readObject();

            validateDefault(json, expectedKeys, msg);
            validateStackTrace(json, false, false);
        }
    }
}
 
Example 17
Source Project: AIDR   Source File: FollowFilterTest.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testTest1() throws Exception {
    //String jsonObjectString = "{\"filter_level\":\"low\",\"retweeted\":false,\"in_reply_to_screen_name\":null,\"possibly_sensitive\":false,\"truncated\":false,\"lang\":\"fr\",\"in_reply_to_status_id_str\":null,\"id\":575924535930843140,\"in_reply_to_user_id_str\":null,\"timestamp_ms\":\"1426146084183\",\"in_reply_to_status_id\":null,\"created_at\":\"Thu Mar 12 07:41:24 +0000 2015\",\"favorite_count\":0,\"place\":null,\"coordinates\":null,\"text\":\"On à sorti le leader de premiere league en jouant tous les 3 jours, une avalanche de blessés et en jouant à 10 #CHELPSG #LT\",\"contributors\":null,\"geo\":null,\"entities\":{\"trends\":[],\"symbols\":[],\"urls\":[],\"hashtags\":[{\"text\":\"CHELPSG\",\"indices\":[111,119]},{\"text\":\"LT\",\"indices\":[120,123]}],\"user_mentions\":[]},\"source\":\"<a href=\\\"http://tapbots.com/tweetbot\\\" rel=\\\"nofollow\\\">Tweetbot for iΟS</a>\",\"favorited\":false,\"in_reply_to_user_id\":null,\"retweet_count\":0,\"id_str\":\"575924535930843136\",\"user\":{\"location\":\"Paris\",\"default_profile\":false,\"profile_background_tile\":false,\"statuses_count\":783,\"lang\":\"fr\",\"profile_link_color\":\"FF3300\",\"profile_banner_url\":\"https://pbs.twimg.com/profile_banners/2788189586/1410101854\",\"id\":2788189586,\"following\":null,\"protected\":false,\"favourites_count\":223,\"profile_text_color\":\"333333\",\"verified\":false,\"description\":\"30 Fucking Years Old\\nCG Artist, Lead Previz, 3D Senior Animator, Rigging and Tracking Skills\\n#Cinema #3D #PSG\",\"contributors_enabled\":false,\"profile_sidebar_border_color\":\"86A4A6\",\"name\":\"Beniga\",\"profile_background_color\":\"709397\",\"created_at\":\"Wed Sep 03 15:54:42 +0000 2014\",\"default_profile_image\":false,\"followers_count\":46,\"profile_image_url_https\":\"https://pbs.twimg.com/profile_images/554740197112688640/2ofATQtR_normal.jpeg\",\"geo_enabled\":false,\"profile_background_image_url\":\"http://abs.twimg.com/images/themes/theme6/bg.gif\",\"profile_background_image_url_https\":\"https://abs.twimg.com/images/themes/theme6/bg.gif\",\"follow_request_sent\":null,\"url\":null,\"utc_offset\":0,\"time_zone\":\"London\",\"notifications\":null,\"profile_use_background_image\":true,\"friends_count\":115,\"profile_sidebar_fill_color\":\"A0C5C7\",\"screen_name\":\"SunBeniga\",\"id_str\":\"2788189586\",\"profile_image_url\":\"http://pbs.twimg.com/profile_images/554740197112688640/2ofATQtR_normal.jpeg\",\"listed_count\":0,\"is_translator\":false},\"aidr\":{\"doctype\":\"twitter\",\"crisis_code\":\"150312104037_emsc_landslides_by_kw_fra\",\"crisis_name\":\"EMSC Landslides by KW fra\"}}";
	String jsonObjectString = "{\"filter_level\":\"medium\",\"contributors\":null,\"text\":\"@gvicks @OneLastStranger Dude-Thats such POOR taste, Respect a missing Plane of humans Its an #aviation tragedy #MH370 #MalaysiaAirlines\",\"geo\":null,\"retweeted\":false,\"in_reply_to_screen_name\":\"gvicks\",\"truncated\":false,\"lang\":\"en\",\"entities\":{\"hashtags\":[{\"text\":\"aviation\",\"indices\":[95,104]},{\"text\":\"MH370\",\"indices\":[113,119]},{\"text\":\"MalaysiaAirlines\",\"indices\":[120,137]}],\"symbols\":[],\"urls\":[],\"user_mentions\":[{\"id\":20862797,\"indices\":[0,7],\"screen_name\":\"gvicks\",\"id_str\":\"20862797\",\"name\":\"Vikram\"},{\"id\":31354692,\"indices\":[8,24],\"screen_name\":\"OneLastStranger\",\"id_str\":\"31354692\",\"name\":\"Busy Stranger\"}]},\"in_reply_to_status_id_str\":\"444322825088684033\",\"aidr\":{\"crisis_code\":\"2014-03-mh370\",\"doctype\":\"twitter\",\"crisis_name\":\"Malaysia Airlines flight #MH370\"},\"id\":445127578831966208,\"in_reply_to_user_id_str\":\"20862797\",\"source\":\"\",\"favorited\":false,\"in_reply_to_status_id\":444322825088684033,\"in_reply_to_user_id\":20862797,\"created_at\":\"Sun Mar 16 09:20:59 +0000 2014\",\"retweet_count\":0,\"favorite_count\":0,\"id_str\":\"445127578831966208\",\"place\":null,\"user\":{\"location\":\"Let Me Own Your Mind & Soul xx\",\"default_profile\":false,\"statuses_count\":15830,\"profile_background_tile\":false,\"lang\":\"en\",\"profile_link_color\":\"0084B4\",\"profile_banner_url\":\"https://pbs.twimg.com/profile_banners/1105766504/1391364260\",\"id\":1105766504,\"following\":null,\"favourites_count\":8861,\"protected\":false,\"profile_text_color\":\"666666\",\"description\":\"#Romantic #Poetry #Lover #Dom #Porn #BDSM~Lifestyle,,Not a Game, Prince of Darkness~Pain & Passion; Lust & Love~Submission Liberates~HLC~Pics with permission\",\"verified\":false,\"contributors_enabled\":false,\"profile_sidebar_border_color\":\"FFFFFF\",\"name\":\"Sir-Thor\",\"profile_background_color\":\"C0DEED\",\"created_at\":\"Sun Jan 20 08:57:28 +0000 2013\",\"is_translation_enabled\":false,\"default_profile_image\":false,\"followers_count\":2087,\"profile_image_url_https\":\"https://pbs.twimg.com/profile_images/378800000712615810/db2f0e2aae535c16eafee1f303289416_normal.jpeg\",\"geo_enabled\":false,\"profile_background_image_url\":\"http://abs.twimg.com/images/themes/theme9/bg.gif\",\"profile_background_image_url_https\":\"https://abs.twimg.com/images/themes/theme9/bg.gif\",\"follow_request_sent\":null,\"url\":\"http://followback.me/69_hornie\",\"utc_offset\":19800,\"time_zone\":\"Chennai\",\"notifications\":null,\"friends_count\":1153,\"profile_use_background_image\":true,\"profile_sidebar_fill_color\":\"252429\",\"screen_name\":\"69_hornie\",\"id_str\":\"1105766504\",\"profile_image_url\":\"http://pbs.twimg.com/profile_images/378800000712615810/db2f0e2aae535c16eafee1f303289416_normal.jpeg\",\"is_translator\":false,\"listed_count\":25},\"coordinates\":null}";
	JsonReader jsonReader = Json.createReader(new StringReader(jsonObjectString));
    JsonObject object = jsonReader.readObject();
    jsonReader.close();
    //
    boolean test = followFilter.test(object);
    //
    assertTrue(test);
    //
    String jsonObjectString1 = "{\"filter_level\":\"medium\",\"contributors\":null,\"text\":\"@gvicks @OneLastStranger Dude-Thats such POOR taste, Respect a missing Plane of humans Its an #aviation tragedy #MH370 #MalaysiaAirlines\",\"geo\":null,\"retweeted\":false,\"in_reply_to_screen_name\":\"gvicks\",\"truncated\":false,\"lang\":\"en\",\"entities\":{\"hashtags\":[{\"text\":\"aviation\",\"indices\":[95,104]},{\"text\":\"MH370\",\"indices\":[113,119]},{\"text\":\"MalaysiaAirlines\",\"indices\":[120,137]}],\"symbols\":[],\"urls\":[],\"user_mentions\":[{\"id\":20862797,\"indices\":[0,7],\"screen_name\":\"gvicks\",\"id_str\":\"20862797\",\"name\":\"Vikram\"},{\"id\":31354692,\"indices\":[8,24],\"screen_name\":\"OneLastStranger\",\"id_str\":\"31354692\",\"name\":\"Busy Stranger\"}]},\"in_reply_to_status_id_str\":\"444322825088684033\",\"aidr\":{\"crisis_code\":\"2014-03-mh370\",\"doctype\":\"twitter\",\"crisis_name\":\"Malaysia Airlines flight #MH370\"},\"id\":445127578831966208,\"in_reply_to_user_id_str\":\"20862797\",\"source\":\"\",\"favorited\":false,\"in_reply_to_status_id\":444322825088684033,\"in_reply_to_user_id\":20862797,\"created_at\":\"Sun Mar 16 09:20:59 +0000 2014\",\"retweet_count\":0,\"favorite_count\":0,\"id_str\":\"445127578831966208\",\"place\":null,\"user\":{\"location\":\"Let Me Own Your Mind & Soul xx\",\"default_profile\":false,\"statuses_count\":15830,\"profile_background_tile\":false,\"lang\":\"en\",\"profile_link_color\":\"0084B4\",\"profile_banner_url\":\"https://pbs.twimg.com/profile_banners/1105766504/1391364260\",\"id\":1105765504,\"following\":null,\"favourites_count\":8861,\"protected\":false,\"profile_text_color\":\"666666\",\"description\":\"#Romantic #Poetry #Lover #Dom #Porn #BDSM~Lifestyle,,Not a Game, Prince of Darkness~Pain & Passion; Lust & Love~Submission Liberates~HLC~Pics with permission\",\"verified\":false,\"contributors_enabled\":false,\"profile_sidebar_border_color\":\"FFFFFF\",\"name\":\"Sir-Thor\",\"profile_background_color\":\"C0DEED\",\"created_at\":\"Sun Jan 20 08:57:28 +0000 2013\",\"is_translation_enabled\":false,\"default_profile_image\":false,\"followers_count\":2087,\"profile_image_url_https\":\"https://pbs.twimg.com/profile_images/378800000712615810/db2f0e2aae535c16eafee1f303289416_normal.jpeg\",\"geo_enabled\":false,\"profile_background_image_url\":\"http://abs.twimg.com/images/themes/theme9/bg.gif\",\"profile_background_image_url_https\":\"https://abs.twimg.com/images/themes/theme9/bg.gif\",\"follow_request_sent\":null,\"url\":\"http://followback.me/69_hornie\",\"utc_offset\":19800,\"time_zone\":\"Chennai\",\"notifications\":null,\"friends_count\":1153,\"profile_use_background_image\":true,\"profile_sidebar_fill_color\":\"252429\",\"screen_name\":\"69_hornie\",\"id_str\":\"1105765504\",\"profile_image_url\":\"http://pbs.twimg.com/profile_images/378800000712615810/db2f0e2aae535c16eafee1f303289416_normal.jpeg\",\"is_translator\":false,\"listed_count\":25},\"coordinates\":null}";
	JsonReader jsonReader1 = Json.createReader(new StringReader(jsonObjectString1));
    JsonObject object1 = jsonReader1.readObject();
    jsonReader1.close();
    boolean test1 = followFilter.test(object1);
    //
    assertFalse(test1);
}
 
Example 18
Source Project: quarkus   Source File: PrimitiveInjectionUnitTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verify that the token aud claim is as expected
 *
 */
@Test()
public void verifyInjectedGroups() {
    io.restassured.response.Response response = RestAssured.given().auth()
            .oauth2(token)
            .when()
            .queryParam(Claims.groups.name(), "Echoer", "Tester", "group1", "group2")
            .queryParam(Claims.auth_time.name(), authTimeClaim)
            .get("/endp/verifyInjectedGroups").andReturn();

    Assertions.assertEquals(HttpURLConnection.HTTP_OK, response.getStatusCode());
    String replyString = response.body().asString();
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    Assertions.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
Example 19
@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"));
}
 
Example 20
Source Project: nifi   Source File: TestSiteToSiteStatusReportingTask.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPortStatus() throws IOException, InitializationException {
    ProcessGroupStatus pgStatus = generateProcessGroupStatus("root", "Awesome", 1, 0);

    final Map<PropertyDescriptor, String> properties = new HashMap<>();
    properties.put(SiteToSiteUtils.BATCH_SIZE, "4");
    properties.put(SiteToSiteStatusReportingTask.COMPONENT_NAME_FILTER_REGEX, "Awesome.*");
    properties.put(SiteToSiteStatusReportingTask.COMPONENT_TYPE_FILTER_REGEX, "(InputPort)");
    properties.put(SiteToSiteStatusReportingTask.ALLOW_NULL_VALUES,"false");

    MockSiteToSiteStatusReportingTask task = initTask(properties, pgStatus);
    task.onTrigger(context);

    final String msg = new String(task.dataSent.get(0), StandardCharsets.UTF_8);
    JsonReader jsonReader = Json.createReader(new ByteArrayInputStream(msg.getBytes()));
    JsonObject object = jsonReader.readArray().getJsonObject(0);
    JsonString runStatus = object.getJsonString("runStatus");
    assertEquals(RunStatus.Stopped.name(), runStatus.getString());
    boolean isTransmitting = object.getBoolean("transmitting");
    assertFalse(isTransmitting);
    JsonNumber inputBytes = object.getJsonNumber("inputBytes");
    assertEquals(5, inputBytes.intValue());
    assertNull(object.get("activeThreadCount"));
}
 
Example 21
/**
 * Ctor.
 *
 * @param request The http request
 * @throws IllegalStateException if the request's payload cannot be read
 */
public ArrayPayloadOf(final HttpRequest request) {
    try (JsonReader reader = Json.createReader(
        ((HttpEntityEnclosingRequest) request).getEntity().getContent())) {
        if (request instanceof HttpEntityEnclosingRequest) {
            this.resources =
                reader.readArray().getValuesAs(JsonObject.class).iterator();
        } else {
            this.resources = new ArrayList<JsonObject>().iterator();
        }
    } catch (final IOException ex) {
        throw new IllegalStateException(
            "Cannot read request payload", ex
        );
    }
}
 
Example 22
@RunAsClient
@Test(groups = TEST_GROUP_CDI_PROVIDER,
    description = "Verify that the injected raw token claim is as expected")
public void verifyInjectedOptionalAuthTime() throws Exception {
    Reporter.log("Begin verifyInjectedOptionalAuthTime\n");
    String uri = baseURL.toExternalForm() + "endp/verifyInjectedOptionalAuthTime";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .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"));
}
 
Example 23
@RunAsClient
@Test(groups = TEST_GROUP_CDI_JSON,
    description = "Verify that the injected customIntegerArray claim is as expected")
public void verifyInjectedCustomIntegerArray() throws Exception {
    Reporter.log("Begin verifyInjectedCustomIntegerArray\n");
    String uri = baseURL.toExternalForm() + "endp/verifyInjectedCustomIntegerArray";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam("value", 0, 1, 2, 3)
        .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"));
}
 
Example 24
Source Project: karaf-decanter   Source File: TestJsonMarshaller.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testInnerMap() throws Exception {
    Marshaller marshaller = new JsonMarshaller();

    Map<String, Object> map = new HashMap<>();
    map.put(EventConstants.TIMESTAMP, EXPECTED_TIMESTAMP);
    map.put("test", "test");
    Map<String, Object> inner = new HashMap<>();
    inner.put("other", "other");
    map.put("inner", inner);

    String jsonString = marshaller.marshal(new Event(EXPECTED_TOPIC, map));

    System.out.println(jsonString);

    JsonReader reader = Json.createReader(new StringReader(jsonString));
    JsonObject jsonObject = reader.readObject();
    Assert.assertEquals("Timestamp string", "2016-02-02T15:59:40,634Z", jsonObject.getString("@timestamp"));
    long ts = jsonObject.getJsonNumber(EventConstants.TIMESTAMP).longValue();
    Assert.assertEquals("timestamp long", EXPECTED_TIMESTAMP, ts);

    Assert.assertEquals("test", jsonObject.getString("test"));

    JsonObject innerObject = jsonObject.getJsonObject("inner");
    Assert.assertEquals("other", innerObject.getString("other"));
}
 
Example 25
@RunAsClient
@Test(groups = TEST_GROUP_CDI_JSON,
    description = "Verify that the injected customInteger claim is as expected from Token2")
public void verifyInjectedCustomInteger2() throws Exception {
    Reporter.log("Begin verifyInjectedCustomInteger2\n");
    String token2 = TokenUtils.generateTokenString("/Token2.json");
    String uri = baseURL.toExternalForm() + "endp/verifyInjectedCustomInteger";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam("value", 1234567892)
        .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"));
}
 
Example 26
Source Project: microprofile-jwt-auth   Source File: RequiredClaimsTest.java    License: Apache License 2.0 6 votes vote down vote up
@RunAsClient
@Test(groups = TEST_GROUP_JWT,
        description = "Verify that the exp claim is as expected")
public void verifyExpiration() throws Exception {
    Reporter.log("Begin verifyExpiration\n");
    String uri = baseURL.toExternalForm() + "endp/verifyExpiration";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
            .target(uri)
            .queryParam(Claims.exp.name(), expClaim)
            .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"));
}
 
Example 27
@RunAsClient
@Test(groups = TEST_GROUP_CONFIG,
    description = "Validate specifying the mp.jwt.verify.publickey.location as resource path to a JWKS key")
public void testKeyAsLocation() throws Exception {
    Reporter.log("testKeyAsLocation, expect HTTP_OK");

    PrivateKey privateKey = TokenUtils.readPrivateKey("/privateKey4k.pem");
    String kid = "publicKey4k";
    HashMap<String, Long> timeClaims = new HashMap<>();
    String token = TokenUtils.generateTokenString(privateKey, kid, "/Token1.json", null, timeClaims);

    String uri = baseURL.toExternalForm() + "jwks/endp/verifyKeyLocationAsJWKSResource";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam("kid", kid)
        ;
    Response response = echoEndpointTarget.request(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"));
}
 
Example 28
@RunAsClient
@Test(groups = TEST_GROUP_CONFIG,
    description = "Validate that JWT with aud that is contained in mp.jwt.verify.audiences returns HTTP_OK")
public void testRequiredAudMatch() throws Exception {
    Reporter.log("testRequiredAudMatch, expect HTTP_OK");

    String uri = baseURL.toExternalForm() + "endp/verifyAudIsOk";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        ;
    Response response = echoEndpointTarget.request(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"));
}
 
Example 29
Source Project: nifi   Source File: TestSiteToSiteStatusReportingTask.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testComponentNameFilter() throws IOException, InitializationException {
    final ProcessGroupStatus pgStatus = generateProcessGroupStatus("root", "Awesome", 1, 0);

    final Map<PropertyDescriptor, String> properties = new HashMap<>();
    properties.put(SiteToSiteUtils.BATCH_SIZE, "4");
    properties.put(SiteToSiteStatusReportingTask.COMPONENT_NAME_FILTER_REGEX, "Awesome.*processor.*");
    properties.put(SiteToSiteStatusReportingTask.COMPONENT_TYPE_FILTER_REGEX, ".*");

    MockSiteToSiteStatusReportingTask task = initTask(properties, pgStatus);
    task.onTrigger(context);

    assertEquals(3, task.dataSent.size());  // 3 processors for each of 4 groups
    final String msg = new String(task.dataSent.get(0), StandardCharsets.UTF_8);
    JsonReader jsonReader = Json.createReader(new ByteArrayInputStream(msg.getBytes()));
    JsonString componentId = jsonReader.readArray().getJsonObject(0).getJsonString("componentId");
    assertEquals("root.1.processor.1", componentId.getString());
}
 
Example 30
Source Project: boost   Source File: PropertiesReader.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Properties readFrom(Class<Properties> type, Type genericType, Annotation[] annotations, MediaType mediaType,
        MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
        throws IOException, WebApplicationException {

    JsonReader jr = Json.createReader(entityStream);
    JsonObject json = jr.readObject();
    Properties retVal = new Properties();

    json.keySet().forEach(key -> {
        JsonValue value = json.get(key);
        if (!JsonValue.NULL.equals(value)) {
            if (value.getValueType() != JsonValue.ValueType.STRING) {
                throw new IllegalArgumentException(
                        "Non-String JSON prop value found in payload.  Sample data is more than this sample can deal with.  It's not intended to handle any payload.");
            }
            JsonString jstr = (JsonString) value;

            retVal.setProperty(key, jstr.getString());
        }
    });
    return retVal;
}