private static JsonObject parseJson(String jsonString, Errors.Collector collector, String description) { try { return JSON.createReader(new StringReader(jsonString)).readObject(); } catch (Exception e) { collector.fatal(jsonString, description + " is not a valid JSON object"); return null; } }
/** * Resource configuration for OIDC Metadata * containing endpoints to various identity services, as well as information about the identity server. * * @param resource resource pointing to the JSON structure * @return udpated builder instance */ public Builder oidcMetadata(Resource resource) { this.oidcMetadata = JSON.createReader(resource.stream()).readObject(); return this; }
private void loadOidcMetadata(Errors.Collector collector) { if ((null == oidcMetadata) && oidcMetadataWellKnown) { try { String wellKnown = identityUri + OidcConfig.DEFAULT_OIDC_METADATA_URI; oidcMetadata = JSON.createReader(Resource.create(URI.create(wellKnown)).stream()).readObject(); LOGGER.finest(() -> "OIDC Metadata loaded from well known URI: " + wellKnown); } catch (Exception e) { collector.fatal(e, "Failed to load metadata: " + e.getClass().getName() + ": " + e.getMessage()); } } }
/** * Load keys from a resource (must point to JSON text content). * * @param resource the resource with JSON data (file, classpath, URI etc.) * @return updated builder instance * @throws NullPointerException in case the path is null */ public Builder resource(Resource resource) { Objects.requireNonNull(resource, "Json resource must not be null"); try (InputStream is = resource.stream()) { JsonObject jsonObject = JSON.createReader(is).readObject(); addKeys(jsonObject); } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to close input stream on resource: " + resource); } return this; }
/** * Returns a function (reader) converting {@link Flow.Publisher Publisher} of {@link java.nio.ByteBuffer}s to * a JSON-P object. * <p> * It is intended for derivation of others, more specific readers. * * @param charset a charset to use charset * @return the byte array content reader that transforms a publisher of byte buffers to a completion stage that * might end exceptionally with a {@link IllegalArgumentException} in case of I/O error or * a {@link javax.json.JsonException} */ public Reader<JsonStructure> reader(Charset charset) { return (publisher, clazz) -> ContentReaders.byteArrayReader() .apply(publisher) .thenApply(bytes -> jsonReaderFactory.createReader(new ByteArrayInputStream(bytes), charset).read()); }
private JwkKeys loadPublicKeyJWK(String jwkJson) { if (jwkJson.contains("keys")) { return JwkKeys.builder() .resource(Resource.create("public key from PKCS8", jwkJson)) .build(); } JsonObject jsonObject = JSON.createReader(new StringReader(jwkJson)).readObject(); return JwkKeys.builder().addKey(Jwk.create(jsonObject)).build(); }
protected JsonReader findReader(MediaType mediaType, InputStream is) { ContextResolver<JsonReaderFactory> resolver = providers.getContextResolver(JsonReaderFactory.class, mediaType); JsonReaderFactory factory = null; if (resolver != null) { factory = resolver.getContext(JsonReaderFactory.class); } if (factory == null) { factory = readerFactory; } Charset charset = getCharset(mediaType); return charset == null ? factory.createReader(is) : factory.createReader(is, charset); }
@Override public JsonReader createReader(final InputStream in) { return readerFactory.createReader(in); }
@Override public JsonReader createReader(final InputStream in) { return readerFactory.createReader(in); }
@Override public JsonReader createReader(final Reader reader) { return readerFactory.createReader(reader); }
@Override public JsonReader createReader(final Reader reader) { return readerFactory.createReader(reader); }
@Override public JsonReader createReader(final InputStream in) { return readerFactory.createReader(in); }
@Override public JsonReader createReader(final Reader reader) { return readerFactory.createReader(reader); }
/** * Get a {@link JsonReader}, synchronized for thread-safety. * * @param reader source of input * * @return a reader */ @Nonnull protected synchronized JsonReader getJsonReader(@Nonnull final Reader reader) { return readerFactory.createReader(reader); }
@Nonnull public static JsonObject toJsonObject( @Nonnull final String content ) { final StringReader stringReader = new StringReader( content ); try ( final JsonReader reader = c_readerFactory.createReader( stringReader ) ) { return reader.readObject(); } }
@Override public JsonValue readFrom(Class<JsonValue> jsonValueClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> stringStringMultivaluedMap, InputStream inputStream) throws IOException, WebApplicationException { try (JsonReader reader = rf.createReader(inputStream)) { return reader.readValue(); } } }
@Override public JsonStructure readFrom(Class<JsonStructure> jsonStructureClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> stringStringMultivaluedMap, InputStream inputStream) throws IOException, WebApplicationException { try (JsonReader reader = rf.createReader(inputStream)) { return reader.read(); } } }
public <T> T readTypedArray(final InputStream stream, final Class<?> elementType, final Class<T> arrayType) { try (final JsonReader reader = charset == null ? readerFactory.createReader(stream(stream)): readerFactory.createReader(stream(stream), charset)) { return arrayType.cast(mapArray(elementType, reader)); } }
public <T> T readTypedArray(final InputStream stream, final Class<?> elementType, final Class<T> arrayType) { try (final JsonReader reader = charset == null ? readerFactory.createReader(stream(stream)): readerFactory.createReader(stream(stream), charset)) { return arrayType.cast(mapArray(elementType, reader)); } }
public <T> T[] readArray(final InputStream stream, final Class<T> clazz) { try (final JsonReader reader = charset == null ? readerFactory.createReader(stream(stream)): readerFactory.createReader(stream(stream), charset)) { return (T[]) mapArray(clazz, reader); } }