[JAVA-13854] Half list moved (#12598)
* [JAVA-13854] added parent module * [JAVA-13854] moved apache-tapestry(submodule) to web-modules(parent) * [JAVA-13854] moved bootique(submodule) to web-modules(parent) * [JAVA-13854] moved dropwizard(submodule) to web-modules(parent) * [JAVA-13854] moved blade(submodule) to web-modules(parent) * [JAVA-13854] moved java-lite(submodule) to web-modules(parent) * [JAVA-13854] moved jooby(submodule) to web-modules(parent) * [JAVA-13854] moved linkrest(submodule) to web-modules(parent) * [JAVA-13854] moved ninja(submodule) to web-modules(parent) * [JAVA-13854] moved ratpack(submodule) to web-modules(parent) * [JAVA-13854] moved resteasy(submodule) to web-modules(parent) * [JAVA-13854] moved restx(submodule) to web-modules(parent) * [JAVA-13854] moved spark-java(submodule) to web-modules(parent) * [JAVA-13854] moved vraptor(submodule) to web-modules(parent) * [JAVA-13854] delete modules that were moved * [JAVA-13854] * [JAVA-13854] * [JAVA-13854] delete ninja submodule + moved raml(submodule) to web-modules(parent) * [JAVA-13854] moved gwt(submodule) to web-modules(parent) * [JAVA-13854] moved jakarta-ee(submodule) to web-modules(parent) * [JAVA-13854] moved javax-servlets(submodule) to web-modules(parent) * [JAVA-13854] moved javax-servlets-2(submodule) to web-modules(parent) * [JAVA-13854] moved jee-7(submodule) to web-modules(parent) * [JAVA-13854] moved play-framework(not a module) to web-modules * [JAVA-13854] fix failing test * [JAVA-13854] moved struts-2(submodule) to web-modules(parent) * [JAVA-13854] moved wicket(submodule) to web-modules(parent) * [JAVA-13854] deleted modules that were moved to web-modules * JAVA-13854 Removed moved modules from the main pom.xml Co-authored-by: panagiotiskakos <panagiotis.kakos@libra-is.com> Co-authored-by: Dhawal Kapil <dhawalkapil@gmail.com>
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package app.config;
|
||||
|
||||
import org.javalite.activeweb.AppContext;
|
||||
import org.javalite.activeweb.Bootstrap;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import app.services.ArticleServiceModule;
|
||||
|
||||
public class AppBootstrap extends Bootstrap {
|
||||
public void init(AppContext context) {
|
||||
}
|
||||
public Injector getInjector() {
|
||||
return Guice.createInjector(new ArticleServiceModule());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package app.config;
|
||||
|
||||
import app.controllers.ProductsController;
|
||||
import org.javalite.activeweb.AbstractControllerConfig;
|
||||
import org.javalite.activeweb.AppContext;
|
||||
import org.javalite.activeweb.controller_filters.DBConnectionFilter;
|
||||
import org.javalite.activeweb.controller_filters.TimingFilter;
|
||||
|
||||
public class AppControllerConfig extends AbstractControllerConfig {
|
||||
@Override
|
||||
public void init(AppContext appContext) {
|
||||
addGlobalFilters(new TimingFilter());
|
||||
add(new DBConnectionFilter()).to(ProductsController.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package app.config;
|
||||
|
||||
import org.javalite.activeweb.AbstractDBConfig;
|
||||
import org.javalite.activeweb.AppContext;
|
||||
|
||||
public class DbConfig extends AbstractDBConfig {
|
||||
@Override
|
||||
public void init(AppContext appContext) {
|
||||
this.configFile("/database.properties");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package app.controllers;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.javalite.activeweb.AppController;
|
||||
|
||||
import app.services.ArticleService;
|
||||
|
||||
public class ArticleController extends AppController {
|
||||
|
||||
@Inject
|
||||
private ArticleService articleService;
|
||||
|
||||
public void index() {
|
||||
view("articles", articleService.getArticles());
|
||||
}
|
||||
|
||||
public void search() {
|
||||
|
||||
String keyword = param("key");
|
||||
if (null != keyword) {
|
||||
assign("article", articleService.search(keyword));
|
||||
} else {
|
||||
render("/common/error");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package app.controllers;
|
||||
|
||||
import org.javalite.activeweb.AppController;
|
||||
|
||||
public class HomeController extends AppController {
|
||||
|
||||
public void index() {
|
||||
render("index");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package app.controllers;
|
||||
|
||||
import app.models.Product;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.javalite.activeweb.AppController;
|
||||
import org.javalite.activeweb.annotations.RESTful;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RESTful
|
||||
public class ProductsController extends AppController {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
public void index() {
|
||||
try {
|
||||
view("products", Product.findAll());
|
||||
render().contentType("application/json");
|
||||
} catch (Exception e) {
|
||||
view("message", "There was an error.", "code", 200);
|
||||
render("message");
|
||||
}
|
||||
}
|
||||
|
||||
public void create() {
|
||||
try {
|
||||
Map payload = mapper.readValue(getRequestString(), Map.class);
|
||||
Product p = new Product();
|
||||
p.fromMap(payload);
|
||||
p.saveIt();
|
||||
view("message", "Successfully saved product id " + p.get("id"), "code", 200);
|
||||
render("message");
|
||||
} catch (Exception e) {
|
||||
view("message", "There was an error.", "code", 200);
|
||||
render("message");
|
||||
}
|
||||
}
|
||||
|
||||
public void update() {
|
||||
try {
|
||||
Map payload = mapper.readValue(getRequestString(), Map.class);
|
||||
String id = getId();
|
||||
Product p = Product.findById(id);
|
||||
if (p == null) {
|
||||
view("message", "Product id " + id + " not found.", "code", 200);
|
||||
render("message");
|
||||
return;
|
||||
}
|
||||
p.fromMap(payload);
|
||||
p.saveIt();
|
||||
view("message", "Successfully updated product id " + id, "code", 200);
|
||||
render("message");
|
||||
} catch (Exception e) {
|
||||
view("message", "There was an error.", "code", 200);
|
||||
render("message");
|
||||
}
|
||||
}
|
||||
|
||||
public void show() {
|
||||
try {
|
||||
String id = getId();
|
||||
Product p = Product.findById(id);
|
||||
if (p == null) {
|
||||
view("message", "Product id " + id + " not found.", "code", 200);
|
||||
render("message");
|
||||
return;
|
||||
}
|
||||
view("product", p);
|
||||
render("_product");
|
||||
} catch (Exception e) {
|
||||
view("message", "There was an error.", "code", 200);
|
||||
render("message");
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
try {
|
||||
String id = getId();
|
||||
Product p = Product.findById(id);
|
||||
if (p == null) {
|
||||
view("message", "Product id " + id + " not found.", "code", 200);
|
||||
render("message");
|
||||
return;
|
||||
}
|
||||
p.delete();
|
||||
view("message", "Successfully deleted product id " + id, "code", 200);
|
||||
render("message");
|
||||
} catch (Exception e) {
|
||||
view("message", "There was an error.", "code", 200);
|
||||
render("message");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getContentType() {
|
||||
return "application/json";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLayout() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package app.models;
|
||||
|
||||
public class Article {
|
||||
|
||||
private String title;
|
||||
private String author;
|
||||
private String words;
|
||||
private String date;
|
||||
|
||||
public Article(String title, String author, String words, String date) {
|
||||
super();
|
||||
this.title = title;
|
||||
this.author = author;
|
||||
this.words = words;
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public String getWords() {
|
||||
return words;
|
||||
}
|
||||
|
||||
public void setWords(String words) {
|
||||
this.words = words;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(String date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package app.models;
|
||||
|
||||
import org.javalite.activejdbc.Model;
|
||||
|
||||
public class Product extends Model {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package app.services;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import app.models.Article;
|
||||
|
||||
public interface ArticleService {
|
||||
|
||||
List<Article> getArticles();
|
||||
|
||||
Article search(String keyword);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package app.services;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import app.models.Article;
|
||||
|
||||
public class ArticleServiceImpl implements ArticleService {
|
||||
|
||||
public List<Article> getArticles() {
|
||||
return fetchArticles();
|
||||
}
|
||||
|
||||
public Article search(String keyword) {
|
||||
Article ar = new Article("Article with " + keyword, "baeldung", "1250", Instant.now()
|
||||
.toString());
|
||||
return ar;
|
||||
}
|
||||
|
||||
private List<Article> fetchArticles() {
|
||||
Article ar1 = new Article("Introduction to ActiveWeb", "baeldung", "1650", Instant.now()
|
||||
.toString());
|
||||
|
||||
Article ar = new Article("Introduction to Mule", "baeldung", "1650", Instant.now()
|
||||
.toString());
|
||||
List<Article> articles = new ArrayList<Article>();
|
||||
articles.add(ar);
|
||||
articles.add(ar1);
|
||||
return articles;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package app.services;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
|
||||
public class ArticleServiceModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(ArticleService.class).to(ArticleServiceImpl.class)
|
||||
.asEagerSingleton();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
development.driver=com.mysql.jdbc.Driver
|
||||
development.username=user
|
||||
development.password=password
|
||||
development.url=jdbc:mysql://localhost/dbname
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -0,0 +1,18 @@
|
||||
<@content for="title">Articles</@content>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td>Title</td>
|
||||
<td>Author</td>
|
||||
<td>Words #</td>
|
||||
<td>Date Published</td>
|
||||
</tr>
|
||||
<#list articles as article>
|
||||
<tr>
|
||||
<td>${article.title}</td>
|
||||
<td>${article.author}</td>
|
||||
<td>${article.words}</td>
|
||||
<td>${article.date}</td>
|
||||
</tr>
|
||||
</#list>
|
||||
</table>
|
||||
@@ -0,0 +1,17 @@
|
||||
<@content for="title">Search</@content>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td>Title</td>
|
||||
<td>Author</td>
|
||||
<td>Words #</td>
|
||||
<td>Date Published</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>${article.title}</td>
|
||||
<td>${article.author}</td>
|
||||
<td>${article.words}</td>
|
||||
<td>${article.date}</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
@@ -0,0 +1,3 @@
|
||||
<@content for="title">Simple Web App</@content>
|
||||
|
||||
<h2>Application error</h2>
|
||||
@@ -0,0 +1,3 @@
|
||||
<@content for="title">Simple Web App</@content>
|
||||
|
||||
<h2>Baeldung ActiveWeb Demo Application</h2>
|
||||
@@ -0,0 +1,16 @@
|
||||
<#setting url_escaping_charset='ISO-8859-1'>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="main">
|
||||
<#include "header.ftl" >
|
||||
<div class="content">
|
||||
${page_content}
|
||||
</div>
|
||||
<#include "footer.ftl" >
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,3 @@
|
||||
<div class='footer'>
|
||||
<p>2018 Baeldung. No Rights Reserved.</p>
|
||||
</div>
|
||||
@@ -0,0 +1,4 @@
|
||||
<div class="header">
|
||||
<h1><a href="${context_path}">Baeldung ActiveWeb Demo</a></h1>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
,
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"id" : ${product.id},
|
||||
"name" : "${product.name}"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
[<@render partial="product" collection=products spacer="comma"/>]
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"message" : "${message}",
|
||||
"code" : ${code}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
|
||||
|
||||
|
||||
<filter>
|
||||
<filter-name>dispatcher</filter-name>
|
||||
<filter-class>org.javalite.activeweb.RequestDispatcher</filter-class>
|
||||
<init-param>
|
||||
<param-name>root_controller</param-name>
|
||||
<param-value>home</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>exclusions</param-name>
|
||||
<param-value>css,images,js,ico</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>encoding</param-name>
|
||||
<param-value>UTF-8</param-value>
|
||||
</init-param>
|
||||
</filter>
|
||||
|
||||
|
||||
<filter-mapping>
|
||||
<filter-name>dispatcher</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
|
||||
</web-app>
|
||||
Reference in New Issue
Block a user