/** * Produces HikariDataSource for default HikariCP configuration * defined in file META-INF/hikaricp.properties * * @param hdsFactory * @return */ @Singleton @Classed(HikariProperties.class) public DataSource propertiesBasedHikariDataSource(@Classed(HikariConfiguration.class) Supplier<DataSource> hdsFactory) { return hdsFactory.get(new HikariProperties()); }
@Override public <V> V read(Class<V> type, ReaderContext context) { // try get accurate reader final Supplier<RestletTeleReader> supplier = ioc.supplierOrNull(new ClassedKey<>(RestletTeleReader.class, type)); if (supplier != null) { final TeleReader<V, ReaderContext> reader = supplier.get(null); return reader.read(context); } // no accurate reader. read as json HttpContext httpContext = httpContextProv.get(); try (InputStream is = httpContext.getRequest().getInputStream()) { return jsonConverter.fromJson(is, type); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public <V> void write(Class<V> type, V value, WriterContext context) { final Supplier<RestletTeleWriter> supplier = ioc.supplierOrNull(new ClassedKey<>(RestletTeleWriter.class, type)); if (supplier != null) { final TeleWriter<V, WriterContext> writer = supplier.get(null); writer.write(value, context); return; } HttpContext httpContext = httpContextProv.get(); HttpResponse httpResponse = httpContext.getResponse(); String json = jsonConverter.toJson(value); if (json == null) { httpResponse.sendText("", RESPONSE_CONTENT_TYPE, 204); } else { httpResponse.sendData(ByteBuffer.wrap(json.getBytes()), RESPONSE_CONTENT_TYPE, 200); } }