javax.json.JsonReader Java Examples
The following examples show how to use
javax.json.JsonReader.
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
Source File: JsonFormatterTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@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 #2
Source File: PrincipalInjectionTest.java From microprofile-jwt-auth with Apache License 2.0 | 6 votes |
@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 #3
Source File: clientUtil.java From fido2 with GNU Lesser General Public License v2.1 | 6 votes |
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 #4
Source File: Image.java From rapid with MIT License | 6 votes |
@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 #5
Source File: RequiredClaimsUnitTest.java From quarkus with Apache License 2.0 | 6 votes |
/** * 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 #6
Source File: PrimitiveInjectionUnitTest.java From quarkus with Apache License 2.0 | 6 votes |
/** * 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 #7
Source File: Common.java From fido2 with GNU Lesser General Public License v2.1 | 6 votes |
/** * 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 File: PrimitiveInjectionTest.java From microprofile-jwt-auth with Apache License 2.0 | 6 votes |
@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 #9
Source File: ClaimValueInjectionTest.java From microprofile-jwt-auth with Apache License 2.0 | 6 votes |
@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 #10
Source File: WorldClockApiTest.java From Hands-On-Enterprise-Java-Microservices-with-Eclipse-MicroProfile with MIT License | 6 votes |
@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 File: TestSiteToSiteStatusReportingTask.java From nifi with Apache License 2.0 | 6 votes |
@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 File: Config.java From rapid with MIT License | 6 votes |
@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 File: JsonParser.java From jeddict with Apache License 2.0 | 6 votes |
@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 File: IssValidationTest.java From microprofile-jwt-auth with Apache License 2.0 | 6 votes |
@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 File: RsPrettyJson.java From takes with MIT License | 6 votes |
/** * 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
Source File: PrimitiveInjectionTest.java From microprofile-jwt-auth with Apache License 2.0 | 6 votes |
@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 #17
Source File: PrimitiveInjectionUnitTest.java From quarkus with Apache License 2.0 | 6 votes |
/** * 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 #18
Source File: ClaimValueInjectionTest.java From microprofile-jwt-auth with Apache License 2.0 | 6 votes |
@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 #19
Source File: TestSiteToSiteStatusReportingTask.java From nifi with Apache License 2.0 | 6 votes |
@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 #20
Source File: ArrayPayloadOf.java From docker-java-api with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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 #21
Source File: ProviderInjectionTest.java From microprofile-jwt-auth with Apache License 2.0 | 6 votes |
@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 #22
Source File: JsonValueInjectionTest.java From microprofile-jwt-auth with Apache License 2.0 | 6 votes |
@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 #23
Source File: TestJsonMarshaller.java From karaf-decanter with Apache License 2.0 | 6 votes |
@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 #24
Source File: JsonValueInjectionTest.java From microprofile-jwt-auth with Apache License 2.0 | 6 votes |
@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 #25
Source File: RequiredClaimsTest.java From microprofile-jwt-auth with Apache License 2.0 | 6 votes |
@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 #26
Source File: PublicKeyAsJWKSLocationTest.java From microprofile-jwt-auth with Apache License 2.0 | 6 votes |
@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 #27
Source File: AudArrayValidationTest.java From microprofile-jwt-auth with Apache License 2.0 | 6 votes |
@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 #28
Source File: TestSiteToSiteStatusReportingTask.java From nifi with Apache License 2.0 | 6 votes |
@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 #29
Source File: PropertiesReader.java From boost with Eclipse Public License 1.0 | 6 votes |
@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; }
Example #30
Source File: SystemInputJsonReader.java From tcases with MIT License | 6 votes |
/** * Returns a {@link SystemInputDef} instance. */ public SystemInputDef getSystemInputDef() { JsonValidationService service = JsonValidationService.newInstance(); JsonSchema schema = service.readSchema( getClass().getResourceAsStream( "/schema/system-input-schema.json")); ProblemHandler handler = ProblemHandler.throwing(); try( JsonReader reader = service.createReader( stream_, schema, handler)) { JsonObject json; try { json = reader.readObject(); } catch( Exception e) { throw new SystemInputException( "Invalid system input definition", e); } return SystemInputJson.asSystemInputDef( json); } }