Spark graphx moved to a new project due to a incompatibility of scala compiler

This commit is contained in:
Norberto Ritzmann Jr
2019-10-06 21:57:54 +02:00
parent db85c8f275
commit 45be61376e
20299 changed files with 1635696 additions and 0 deletions
@@ -0,0 +1,81 @@
package com.baeldung;
import com.baeldung.filter.RequestValidatorFilter;
import com.baeldung.handler.EmployeeHandler;
import com.baeldung.handler.RedirectHandler;
import com.baeldung.model.Employee;
import com.baeldung.repository.EmployeeRepository;
import com.baeldung.repository.EmployeeRepositoryImpl;
import com.zaxxer.hikari.HikariConfig;
import io.netty.buffer.PooledByteBufAllocator;
import ratpack.func.Action;
import ratpack.func.Function;
import ratpack.guice.BindingsSpec;
import ratpack.guice.Guice;
import ratpack.handling.Chain;
import ratpack.hikari.HikariModule;
import ratpack.http.client.HttpClient;
import ratpack.jackson.Jackson;
import ratpack.registry.Registry;
import ratpack.server.RatpackServer;
import ratpack.server.RatpackServerSpec;
import ratpack.server.ServerConfig;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
public class Application {
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);
}
private static List<Employee> createEmpList() {
List<Employee> employees = new ArrayList<>();
employees.add(new Employee(1L, "Mr", "John Doe"));
employees.add(new Employee(2L, "Mr", "White Snow"));
return employees;
}
}
@@ -0,0 +1,16 @@
package com.baeldung.filter;
import ratpack.handling.Context;
import ratpack.handling.Handler;
import ratpack.http.MutableHeaders;
public class RequestValidatorFilter implements Handler {
@Override
public void handle(Context ctx) throws Exception {
MutableHeaders headers = ctx.getResponse().getHeaders();
headers.set("Access-Control-Allow-Origin", "*");
ctx.next();
}
}
@@ -0,0 +1,32 @@
package com.baeldung.guice;
import com.baeldung.guice.config.DependencyModule;
import com.baeldung.guice.service.DataPumpService;
import com.baeldung.guice.service.ServiceFactory;
import com.baeldung.guice.service.impl.DataPumpServiceImpl;
import ratpack.guice.Guice;
import ratpack.server.RatpackServer;
public class Application {
public static void main(String[] args) throws Exception {
RatpackServer
.start(server -> server.registry(Guice.registry(bindings -> bindings.module(DependencyModule.class)))
.handlers(chain -> chain.get("randomString", ctx -> {
DataPumpService dataPumpService = ctx.get(DataPumpService.class);
ctx.render(dataPumpService.generate());
}).get("factory", ctx -> ctx.render(ServiceFactory.getInstance().generate()))));
// RatpackServer.start(server -> server
// .registry(Guice
// .registry(bindings -> bindings.bindInstance(DataPumpService.class, new DataPumpServiceImpl())))
// .handlers(chain -> chain.get("randomString", ctx -> {
// DataPumpService dataPumpService = ctx.get(DataPumpService.class);
// ctx.render(dataPumpService.generate());
// }).get("factory", ctx -> ctx.render(ServiceFactory.getInstance().generate()))));
}
}
@@ -0,0 +1,16 @@
package com.baeldung.guice.config;
import com.baeldung.guice.service.DataPumpService;
import com.baeldung.guice.service.impl.DataPumpServiceImpl;
import com.google.inject.AbstractModule;
import com.google.inject.Scopes;
public class DependencyModule extends AbstractModule {
@Override
protected void configure() {
bind(DataPumpService.class).to(DataPumpServiceImpl.class)
.in(Scopes.SINGLETON);
}
}
@@ -0,0 +1,7 @@
package com.baeldung.guice.service;
public interface DataPumpService {
String generate();
}
@@ -0,0 +1,20 @@
package com.baeldung.guice.service;
import com.baeldung.guice.service.impl.DataPumpServiceImpl;
public class ServiceFactory {
private static DataPumpService instance;
public static void setInstance(DataPumpService dataPumpService) {
instance = dataPumpService;
}
public static DataPumpService getInstance() {
if (instance == null) {
return new DataPumpServiceImpl();
}
return instance;
}
}
@@ -0,0 +1,14 @@
package com.baeldung.guice.service.impl;
import java.util.UUID;
import com.baeldung.guice.service.DataPumpService;
public class DataPumpServiceImpl implements DataPumpService {
@Override
public String generate() {
return UUID.randomUUID().toString();
}
}
@@ -0,0 +1,20 @@
package com.baeldung.handler;
import com.baeldung.repository.EmployeeRepository;
import com.baeldung.model.Employee;
import ratpack.exec.Promise;
import ratpack.handling.Context;
import ratpack.handling.Handler;
public class EmployeeHandler implements Handler {
@Override
public void handle(Context ctx) throws Exception {
EmployeeRepository repository = ctx.get(EmployeeRepository.class);
Long id = Long.valueOf(ctx.getPathTokens()
.get("id"));
Promise<Employee> employeePromise = repository.findEmployeeById(id);
employeePromise.map(employee -> employee.getName())
.then(name -> ctx.getResponse()
.send(name));
}
}
@@ -0,0 +1,12 @@
package com.baeldung.handler;
import ratpack.handling.Context;
import ratpack.handling.Handler;
public class FooHandler implements Handler {
@Override
public void handle(Context ctx) throws Exception {
ctx.getResponse()
.send("Hello Foo!");
}
}
@@ -0,0 +1,23 @@
package com.baeldung.handler;
import ratpack.exec.Promise;
import ratpack.handling.Context;
import ratpack.handling.Handler;
import ratpack.http.client.HttpClient;
import ratpack.http.client.ReceivedResponse;
import java.net.URI;
public class RedirectHandler implements Handler {
@Override
public void handle(Context ctx) throws Exception {
HttpClient client = ctx.get(HttpClient.class);
URI uri = URI.create("http://localhost:5050/employee/1");
Promise<ReceivedResponse> responsePromise = client.get(uri);
responsePromise.map(response -> response.getBody()
.getText()
.toUpperCase())
.then(responseText -> ctx.getResponse()
.send(responseText));
}
}
@@ -0,0 +1,54 @@
package com.baeldung.hystrix;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandProperties;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;
import java.net.URI;
import java.util.Collections;
/**
* @author aiet
*/
public class HystrixAsyncHttpCommand extends HystrixCommand<String> {
private URI uri;
private RequestConfig requestConfig;
HystrixAsyncHttpCommand(URI uri, int timeoutMillis) {
super(Setter
.withGroupKey(HystrixCommandGroupKey.Factory.asKey("hystrix-ratpack-async"))
.andCommandPropertiesDefaults(HystrixCommandProperties
.Setter()
.withExecutionTimeoutInMilliseconds(timeoutMillis)));
requestConfig = RequestConfig
.custom()
.setSocketTimeout(timeoutMillis)
.setConnectTimeout(timeoutMillis)
.setConnectionRequestTimeout(timeoutMillis)
.build();
this.uri = uri;
}
@Override
protected String run() throws Exception {
return EntityUtils.toString(HttpClientBuilder
.create()
.setDefaultRequestConfig(requestConfig)
.setDefaultHeaders(Collections.singleton(new BasicHeader("User-Agent", "Baeldung Blocking HttpClient")))
.build()
.execute(new HttpGet(uri))
.getEntity());
}
@Override
protected String getFallback() {
return "eugenp's async fallback profile";
}
}
@@ -0,0 +1,44 @@
package com.baeldung.hystrix;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandProperties;
import com.netflix.hystrix.HystrixObservableCommand;
import ratpack.http.client.HttpClient;
import ratpack.rx.RxRatpack;
import rx.Observable;
import java.net.URI;
/**
* @author aiet
*/
public class HystrixReactiveHttpCommand extends HystrixObservableCommand<String> {
private HttpClient httpClient;
private URI uri;
HystrixReactiveHttpCommand(HttpClient httpClient, URI uri, int timeoutMillis) {
super(Setter
.withGroupKey(HystrixCommandGroupKey.Factory.asKey("hystrix-ratpack-reactive"))
.andCommandPropertiesDefaults(HystrixCommandProperties
.Setter()
.withExecutionTimeoutInMilliseconds(timeoutMillis)));
this.httpClient = httpClient;
this.uri = uri;
}
@Override
protected Observable<String> construct() {
return RxRatpack.observe(httpClient
.get(uri, requestSpec -> requestSpec.headers(mutableHeaders -> mutableHeaders.add("User-Agent", "Baeldung HttpClient")))
.map(receivedResponse -> receivedResponse
.getBody()
.getText()));
}
@Override
protected Observable<String> resumeWithFallback() {
return Observable.just("eugenp's reactive fallback profile");
}
}
@@ -0,0 +1,55 @@
package com.baeldung.hystrix;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandProperties;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;
import java.net.URI;
import java.util.Collections;
/**
* @author aiet
*/
public class HystrixSyncHttpCommand extends HystrixCommand<String> {
private URI uri;
private RequestConfig requestConfig;
HystrixSyncHttpCommand(URI uri, int timeoutMillis) {
super(Setter
.withGroupKey(HystrixCommandGroupKey.Factory.asKey("hystrix-ratpack-sync"))
.andCommandPropertiesDefaults(HystrixCommandProperties
.Setter()
.withExecutionTimeoutInMilliseconds(timeoutMillis)));
requestConfig = RequestConfig
.custom()
.setSocketTimeout(timeoutMillis)
.setConnectTimeout(timeoutMillis)
.setConnectionRequestTimeout(timeoutMillis)
.build();
this.uri = uri;
}
@Override
protected String run() throws Exception {
HttpGet request = new HttpGet(uri);
return EntityUtils.toString(HttpClientBuilder
.create()
.setDefaultRequestConfig(requestConfig)
.setDefaultHeaders(Collections.singleton(new BasicHeader("User-Agent", "Baeldung Blocking HttpClient")))
.build()
.execute(request)
.getEntity());
}
@Override
protected String getFallback() {
return "eugenp's sync fallback profile";
}
}
@@ -0,0 +1,30 @@
package com.baeldung.hystrix;
import ratpack.guice.Guice;
import ratpack.http.client.HttpClient;
import ratpack.hystrix.HystrixMetricsEventStreamHandler;
import ratpack.hystrix.HystrixModule;
import ratpack.server.RatpackServer;
import java.net.URI;
public class RatpackHystrixApp {
public static void main(String[] args) throws Exception {
final int timeout = Integer.valueOf(System.getProperty("ratpack.hystrix.timeout"));
final URI eugenGithubProfileUri = new URI("https://api.github.com/users/eugenp");
RatpackServer.start(server -> server
.registry(Guice.registry(bindingsSpec -> bindingsSpec.module(new HystrixModule().sse())))
.handlers(chain -> chain
.get("rx", ctx -> new HystrixReactiveHttpCommand(ctx.get(HttpClient.class), eugenGithubProfileUri, timeout)
.toObservable()
.subscribe(ctx::render))
.get("async", ctx -> ctx.render(new HystrixAsyncHttpCommand(eugenGithubProfileUri, timeout)
.queue()
.get()))
.get("sync", ctx -> ctx.render(new HystrixSyncHttpCommand(eugenGithubProfileUri, timeout).execute()))
.get("hystrix", new HystrixMetricsEventStreamHandler())));
}
}
@@ -0,0 +1,44 @@
package com.baeldung.model;
import java.io.Serializable;
public class Employee implements Serializable {
private static final long serialVersionUID = 3077867088762010705L;
private Long id;
private String title;
private String name;
public Employee(Long id, String title, String name) {
super();
this.id = id;
this.title = title;
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@@ -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,10 @@
package com.baeldung.repository;
import com.baeldung.model.Employee;
import ratpack.exec.Promise;
public interface EmployeeRepository {
Promise<Employee> findEmployeeById(Long id) throws Exception;
}
@@ -0,0 +1,25 @@
package com.baeldung.repository;
import com.baeldung.model.Employee;
import ratpack.exec.Promise;
import java.util.HashMap;
import java.util.Map;
public class EmployeeRepositoryImpl implements EmployeeRepository {
private static final Map<Long, Employee> EMPLOYEE_MAP = new HashMap<>();
public EmployeeRepositoryImpl() {
EMPLOYEE_MAP.put(1L, new Employee(1L, "Ms", "Jane Doe"));
EMPLOYEE_MAP.put(2L, new Employee(2L, "Mr", "NY"));
}
@Override
public Promise<Employee> findEmployeeById(Long id) throws Exception {
return Promise.async(downstream -> {
Thread.sleep(500);
downstream.success(EMPLOYEE_MAP.get(id));
});
}
}
@@ -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);
}
}
@@ -0,0 +1,11 @@
package com.baeldung.spring;
import java.util.List;
/**
* @author aiet
*/
public interface ArticleList {
List<String> articles();
}
@@ -0,0 +1,24 @@
package com.baeldung.spring;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Arrays;
/**
* @author aiet
*/
@Configuration
public class Config {
@Bean
public Content content() {
return () -> "hello baeldung!";
}
@Bean
public ArticleList articles() {
return () -> Arrays.asList("Introduction to Ratpack", "Ratpack Google Guice Integration", "Ratpack Spring Boot Integration");
}
}
@@ -0,0 +1,10 @@
package com.baeldung.spring;
/**
* @author aiet
*/
public interface Content {
String body();
}
@@ -0,0 +1,46 @@
package com.baeldung.spring;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import ratpack.func.Action;
import ratpack.handling.Chain;
import ratpack.server.ServerConfig;
import ratpack.spring.config.EnableRatpack;
/**
* @author aiet
*/
@SpringBootApplication
@EnableRatpack
public class EmbedRatpackApp {
@Autowired private Content content;
@Autowired private ArticleList list;
@Bean
public Action<Chain> hello() {
return chain -> chain.get("hello", ctx -> ctx.render(content.body()));
}
@Bean
public Action<Chain> list() {
return chain -> chain.get("list", ctx -> ctx.render(list
.articles()
.toString()));
}
@Bean
public ServerConfig ratpackServerConfig() {
return ServerConfig
.builder()
.findBaseDir("public")
.build();
}
public static void main(String[] args) {
SpringApplication.run(EmbedRatpackApp.class, args);
}
}
@@ -0,0 +1,19 @@
package com.baeldung.spring;
import ratpack.server.RatpackServer;
import static ratpack.spring.Spring.spring;
public class EmbedSpringBootApp {
public static void main(String[] args) throws Exception {
RatpackServer.start(server -> server
.registry(spring(Config.class))
.handlers(chain -> chain.get(ctx -> ctx.render(ctx
.get(Content.class)
.body()))));
}
}