ratpack.jackson.Jackson Java Examples
The following examples show how to use
ratpack.jackson.Jackson.
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: NewsServiceApp.java From Hands-On-Reactive-Programming-in-Spring-5 with MIT License | 6 votes |
@Bean public Action<Chain> home() { return chain -> chain.get(ctx -> { FindPublisher<News> databasePublisher = databaseNews().lookupNews(); Observable<News> httpNewsObservable = externalNews().retrieveNews(); TransformablePublisher<News> stream = Streams.merge( databasePublisher, RxReactiveStreams.toPublisher(httpNewsObservable) ); ctx.render( stream.toList() .map(Jackson::json) ); }); }
Example #2
Source File: RatpackParallelismApp.java From tutorials with MIT License | 6 votes |
/** * Try hitting http://localhost:5050/movies to see the application in action. * * @param args * @throws Exception */ public static void main(String[] args) throws Exception { RxRatpack.initialize(); RatpackServer.start(def -> def.registryOf(regSpec -> regSpec.add(MovieObservableService.class, new MovieObservableServiceImpl())) .handlers(chain -> chain.get("movies", ctx -> { MovieObservableService movieSvc = ctx.get(MovieObservableService.class); Observable<Movie> movieObs = movieSvc.getMovies(); Observable<String> upperCasedNames = movieObs.compose(RxRatpack::forkEach) .map(movie -> movie.getName() .toUpperCase()) .serialize(); RxRatpack.promise(upperCasedNames) .then(movie -> { ctx.render(Jackson.json(movie)); }); }))); }
Example #3
Source File: BulkheadChain.java From resilience4j with Apache License 2.0 | 5 votes |
private ServerSentEvents serverSentEvents(Chain chain, Seq<Flux<BulkheadEvent>> eventStreams) { Function<BulkheadEvent, String> data = b -> Jackson.getObjectWriter(chain.getRegistry()) .writeValueAsString(BulkheadEventDTOFactory.createBulkheadEventDTO(b)); return ServerSentEvents.serverSentEvents(Flux.merge(eventStreams), e -> e.id(BulkheadEvent::getBulkheadName).event(c -> c.getEventType().name()) .data(data)); }
Example #4
Source File: Application.java From tutorials with MIT License | 4 votes |
public static void main(String[] args) throws Exception { final Action<HikariConfig> hikariConfigAction = hikariConfig -> { hikariConfig.setDataSourceClassName("org.h2.jdbcx.JdbcDataSource"); hikariConfig.addDataSourceProperty("URL", "jdbc:h2:mem:baeldung;INIT=RUNSCRIPT FROM 'classpath:/DDL.sql'"); }; final Action<BindingsSpec> bindingsSpecAction = bindings -> bindings.module(HikariModule.class, hikariConfigAction); final HttpClient httpClient = HttpClient.of(httpClientSpec -> { httpClientSpec.poolSize(10) .connectTimeout(Duration.of(60, ChronoUnit.SECONDS)) .maxContentLength(ServerConfig.DEFAULT_MAX_CONTENT_LENGTH) .responseMaxChunkSize(16384) .readTimeout(Duration.of(60, ChronoUnit.SECONDS)) .byteBufAllocator(PooledByteBufAllocator.DEFAULT); }); final Function<Registry, Registry> registryFunction = Guice.registry(bindingsSpecAction); final Action<Chain> chainAction = chain -> chain.all(new RequestValidatorFilter()) .get(ctx -> ctx.render("Welcome to baeldung ratpack!!!")) .get("data/employees", ctx -> ctx.render(Jackson.json(createEmpList()))) .get(":name", ctx -> ctx.render("Hello " + ctx.getPathTokens() .get("name") + "!!!")) .post(":amount", ctx -> ctx.render(" Amount $" + ctx.getPathTokens() .get("amount") + " added successfully !!!")); final Action<Chain> routerChainAction = routerChain -> { routerChain.path("redirect", new RedirectHandler()) .prefix("employee", empChain -> { empChain.get(":id", new EmployeeHandler()); }); }; final Action<RatpackServerSpec> ratpackServerSpecAction = serverSpec -> serverSpec.registry(registryFunction) .registryOf(registrySpec -> { registrySpec.add(EmployeeRepository.class, new EmployeeRepositoryImpl()); registrySpec.add(HttpClient.class, httpClient); }) .handlers(chain -> chain.insert(routerChainAction) .insert(chainAction)); RatpackServer.start(ratpackServerSpecAction); }