BAEL-774 (#6234)
* BAEL-774 * BAEL 774 : Refactored methods * BAEL-774 Refactored to new module. * BAEL 774 - CRs * BAEL 774 - Moved code back to ratpack module * Removed modules reactive-modules and ratpack-rxjava * Refactored packages
This commit is contained in:
parent
2634bdc250
commit
053e7c4e98
1
pom.xml
1
pom.xml
@ -570,7 +570,6 @@
|
|||||||
<module>rxjava</module>
|
<module>rxjava</module>
|
||||||
<module>rxjava-2</module>
|
<module>rxjava-2</module>
|
||||||
<module>software-security/sql-injection-samples</module>
|
<module>software-security/sql-injection-samples</module>
|
||||||
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
</profile>
|
</profile>
|
||||||
|
47
ratpack/src/main/java/com/baeldung/model/Movie.java
Normal file
47
ratpack/src/main/java/com/baeldung/model/Movie.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package com.baeldung.model;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*POJO class for Movie object
|
||||||
|
*/
|
||||||
|
public class Movie {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String year;
|
||||||
|
|
||||||
|
private String director;
|
||||||
|
|
||||||
|
private Double rating;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getYear() {
|
||||||
|
return year;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setYear(String year) {
|
||||||
|
this.year = year;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDirector() {
|
||||||
|
return director;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDirector(String director) {
|
||||||
|
this.director = director;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getRating() {
|
||||||
|
return rating;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRating(Double rating) {
|
||||||
|
this.rating = rating;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.baeldung.rxjava;
|
||||||
|
|
||||||
|
import ratpack.error.ServerErrorHandler;
|
||||||
|
import ratpack.rx.RxRatpack;
|
||||||
|
import ratpack.server.RatpackServer;
|
||||||
|
import rx.Observable;
|
||||||
|
|
||||||
|
public class RatpackErrorHandlingApp {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try hitting http://localhost:5050/error to see the error handler in action
|
||||||
|
* @param args
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
RxRatpack.initialize();
|
||||||
|
RatpackServer.start(def -> def.registryOf(regSpec -> regSpec.add(ServerErrorHandler.class, (ctx, throwable) -> {
|
||||||
|
ctx.render("Error caught by handler : " + throwable.getMessage());
|
||||||
|
}))
|
||||||
|
.handlers(chain -> chain.get("error", ctx -> {
|
||||||
|
Observable.<String> error(new Exception("Error from observable"))
|
||||||
|
.subscribe(s -> {
|
||||||
|
});
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package com.baeldung.rxjava;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.baeldung.model.Movie;
|
||||||
|
import com.baeldung.rxjava.service.MoviePromiseService;
|
||||||
|
import com.baeldung.rxjava.service.impl.MoviePromiseServiceImpl;
|
||||||
|
|
||||||
|
import ratpack.exec.Promise;
|
||||||
|
import ratpack.handling.Handler;
|
||||||
|
import ratpack.jackson.Jackson;
|
||||||
|
import ratpack.rx.RxRatpack;
|
||||||
|
import ratpack.server.RatpackServer;
|
||||||
|
|
||||||
|
public class RatpackObserveApp {
|
||||||
|
/**
|
||||||
|
* Try hitting http://localhost:5050/movies or http://localhost:5050/movie to see the application in action.
|
||||||
|
*
|
||||||
|
* @param args
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
RxRatpack.initialize();
|
||||||
|
|
||||||
|
Handler moviePromiseHandler = ctx -> {
|
||||||
|
MoviePromiseService promiseSvc = ctx.get(MoviePromiseService.class);
|
||||||
|
Promise<Movie> moviePromise = promiseSvc.getMovie();
|
||||||
|
RxRatpack.observe(moviePromise)
|
||||||
|
.subscribe(movie -> ctx.render(Jackson.json(movie)));
|
||||||
|
};
|
||||||
|
|
||||||
|
Handler moviesPromiseHandler = ctx -> {
|
||||||
|
MoviePromiseService promiseSvc = ctx.get(MoviePromiseService.class);
|
||||||
|
Promise<List<Movie>> moviePromises = promiseSvc.getMovies();
|
||||||
|
RxRatpack.observeEach(moviePromises)
|
||||||
|
.toList()
|
||||||
|
.subscribe(movie -> ctx.render(Jackson.json(movie)));
|
||||||
|
};
|
||||||
|
|
||||||
|
RatpackServer.start(def -> def.registryOf(regSpec -> regSpec.add(MoviePromiseService.class, new MoviePromiseServiceImpl()))
|
||||||
|
.handlers(chain -> chain.get("movie", moviePromiseHandler)
|
||||||
|
.get("movies", moviesPromiseHandler)));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.baeldung.rxjava;
|
||||||
|
|
||||||
|
import com.baeldung.model.Movie;
|
||||||
|
import com.baeldung.rxjava.service.MovieObservableService;
|
||||||
|
import com.baeldung.rxjava.service.impl.MovieObservableServiceImpl;
|
||||||
|
|
||||||
|
import ratpack.jackson.Jackson;
|
||||||
|
import ratpack.rx.RxRatpack;
|
||||||
|
import ratpack.server.RatpackServer;
|
||||||
|
import rx.Observable;
|
||||||
|
|
||||||
|
public class RatpackParallelismApp {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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));
|
||||||
|
});
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.baeldung.rxjava;
|
||||||
|
|
||||||
|
import com.baeldung.model.Movie;
|
||||||
|
import com.baeldung.rxjava.service.MovieObservableService;
|
||||||
|
import com.baeldung.rxjava.service.impl.MovieObservableServiceImpl;
|
||||||
|
|
||||||
|
import ratpack.handling.Handler;
|
||||||
|
import ratpack.jackson.Jackson;
|
||||||
|
import ratpack.rx.RxRatpack;
|
||||||
|
import ratpack.server.RatpackServer;
|
||||||
|
import rx.Observable;
|
||||||
|
|
||||||
|
public class RatpackPromiseApp {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try hitting http://localhost:5050/movies or http://localhost:5050/movie to see the application in action.
|
||||||
|
*
|
||||||
|
* @param args
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
RxRatpack.initialize();
|
||||||
|
|
||||||
|
Handler movieHandler = (ctx) -> {
|
||||||
|
MovieObservableService movieSvc = ctx.get(MovieObservableService.class);
|
||||||
|
Observable<Movie> movieObs = movieSvc.getMovie();
|
||||||
|
RxRatpack.promiseSingle(movieObs)
|
||||||
|
.then(movie -> ctx.render(Jackson.json(movie)));
|
||||||
|
};
|
||||||
|
|
||||||
|
Handler moviesHandler = (ctx) -> {
|
||||||
|
MovieObservableService movieSvc = ctx.get(MovieObservableService.class);
|
||||||
|
Observable<Movie> movieObs = movieSvc.getMovies();
|
||||||
|
RxRatpack.promise(movieObs)
|
||||||
|
.then(movie -> ctx.render(Jackson.json(movie)));
|
||||||
|
};
|
||||||
|
|
||||||
|
RatpackServer.start(def -> def.registryOf(rSpec -> rSpec.add(MovieObservableService.class, new MovieObservableServiceImpl()))
|
||||||
|
.handlers(chain -> chain.get("movie", movieHandler)
|
||||||
|
.get("movies", moviesHandler)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.baeldung.rxjava.service;
|
||||||
|
|
||||||
|
import com.baeldung.model.Movie;
|
||||||
|
|
||||||
|
import rx.Observable;
|
||||||
|
|
||||||
|
public interface MovieObservableService {
|
||||||
|
|
||||||
|
Observable<Movie> getMovies();
|
||||||
|
|
||||||
|
Observable<Movie> getMovie();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.baeldung.rxjava.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.baeldung.model.Movie;
|
||||||
|
|
||||||
|
import ratpack.exec.Promise;
|
||||||
|
|
||||||
|
public interface MoviePromiseService {
|
||||||
|
|
||||||
|
Promise<List<Movie>> getMovies();
|
||||||
|
|
||||||
|
Promise<Movie> getMovie();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.baeldung.rxjava.service.impl;
|
||||||
|
|
||||||
|
import com.baeldung.model.Movie;
|
||||||
|
import com.baeldung.rxjava.service.MovieObservableService;
|
||||||
|
|
||||||
|
import rx.Observable;
|
||||||
|
|
||||||
|
public class MovieObservableServiceImpl implements MovieObservableService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Observable<Movie> getMovie() {
|
||||||
|
Movie movie = new Movie();
|
||||||
|
movie.setName("The Godfather");
|
||||||
|
movie.setYear("1972");
|
||||||
|
movie.setDirector("Coppola");
|
||||||
|
movie.setRating(9.2);
|
||||||
|
return Observable.just(movie);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Observable<Movie> getMovies() {
|
||||||
|
Movie movie = new Movie();
|
||||||
|
movie.setName("The Godfather");
|
||||||
|
movie.setYear("1972");
|
||||||
|
movie.setDirector("Coppola");
|
||||||
|
movie.setRating(9.2);
|
||||||
|
Movie movie2 = new Movie();
|
||||||
|
movie2.setName("The Godfather Part 2");
|
||||||
|
movie2.setYear("1974");
|
||||||
|
movie2.setDirector("Coppola");
|
||||||
|
movie2.setRating(9.0);
|
||||||
|
return Observable.just(movie, movie2);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package com.baeldung.rxjava.service.impl;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.baeldung.model.Movie;
|
||||||
|
import com.baeldung.rxjava.service.MoviePromiseService;
|
||||||
|
|
||||||
|
import ratpack.exec.Promise;
|
||||||
|
|
||||||
|
public class MoviePromiseServiceImpl implements MoviePromiseService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Promise<Movie> getMovie() {
|
||||||
|
Movie movie = new Movie();
|
||||||
|
movie.setName("The Godfather");
|
||||||
|
movie.setYear("1972");
|
||||||
|
movie.setDirector("Coppola");
|
||||||
|
movie.setRating(9.2);
|
||||||
|
return Promise.value(movie);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Promise<List<Movie>> getMovies() {
|
||||||
|
Movie movie = new Movie();
|
||||||
|
movie.setName("The Godfather");
|
||||||
|
movie.setYear("1972");
|
||||||
|
movie.setDirector("Coppola");
|
||||||
|
movie.setRating(9.2);
|
||||||
|
Movie movie2 = new Movie();
|
||||||
|
movie2.setName("The Godfather Part 2");
|
||||||
|
movie2.setYear("1974");
|
||||||
|
movie2.setDirector("Coppola");
|
||||||
|
movie2.setRating(9.0);
|
||||||
|
List<Movie> movies = new ArrayList<>();
|
||||||
|
movies.add(movie);
|
||||||
|
movies.add(movie2);
|
||||||
|
return Promise.value(movies);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user