[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:
8
web-modules/java-lite/README.md
Normal file
8
web-modules/java-lite/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
## JavaLite
|
||||
|
||||
This module contains articles about JavaLite.
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [A Guide to JavaLite – Building a RESTful CRUD application](https://www.baeldung.com/javalite-rest)
|
||||
- [Introduction to ActiveWeb](https://www.baeldung.com/activeweb)
|
||||
97
web-modules/java-lite/pom.xml
Normal file
97
web-modules/java-lite/pom.xml
Normal file
@@ -0,0 +1,97 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.baeldung</groupId>
|
||||
<artifactId>java-lite</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>java-lite</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>web-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.javalite</groupId>
|
||||
<artifactId>activeweb</artifactId>
|
||||
<version>${activeweb.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${mysql.connector.java.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun</groupId>
|
||||
<artifactId>tools</artifactId>
|
||||
<version>${sun.tools.version}</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${java.home}/../lib/tools.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.javalite</groupId>
|
||||
<artifactId>activeweb-testing</artifactId>
|
||||
<version>${activeweb-testing.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/webapp/WEB-INF</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>${jetty.maven.plugin.version}</version>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<systemProperty>
|
||||
<name>activejdbc.log</name>
|
||||
<value></value>
|
||||
</systemProperty>
|
||||
<systemProperty>
|
||||
<name>active_reload</name>
|
||||
<value>true</value>
|
||||
</systemProperty>
|
||||
<systemProperty>
|
||||
<name>activeweb.log.request</name>
|
||||
<value>true</value>
|
||||
</systemProperty>
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.javalite</groupId>
|
||||
<artifactId>activejdbc-instrumentation</artifactId>
|
||||
<version>${activejdbc.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>process-classes</phase>
|
||||
<goals>
|
||||
<goal>instrument</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<jetty.maven.plugin.version>9.4.8.v20171121</jetty.maven.plugin.version>
|
||||
<activejdbc.version>1.4.13</activejdbc.version>
|
||||
<activeweb.version>1.15</activeweb.version>
|
||||
<mysql.connector.java.version>5.1.45</mysql.connector.java.version>
|
||||
<sun.tools.version>1.7.0</sun.tools.version>
|
||||
<activeweb-testing.version>1.15</activeweb-testing.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
11
web-modules/java-lite/src/main/java/app/config/DbConfig.java
Normal file
11
web-modules/java-lite/src/main/java/app/config/DbConfig.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
50
web-modules/java-lite/src/main/java/app/models/Article.java
Normal file
50
web-modules/java-lite/src/main/java/app/models/Article.java
Normal file
@@ -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
|
||||
13
web-modules/java-lite/src/main/resources/logback.xml
Normal file
13
web-modules/java-lite/src/main/resources/logback.xml
Normal file
@@ -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}
|
||||
}
|
||||
29
web-modules/java-lite/src/main/webapp/WEB-INF/web.xml
Normal file
29
web-modules/java-lite/src/main/webapp/WEB-INF/web.xml
Normal file
@@ -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>
|
||||
@@ -0,0 +1,31 @@
|
||||
package app.controllers;
|
||||
|
||||
import org.javalite.activeweb.ControllerSpec;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
|
||||
import app.services.ArticleServiceModule;
|
||||
|
||||
public class ArticleControllerSpec extends ControllerSpec {
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
setInjector(Guice.createInjector(new ArticleServiceModule()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReturnedArticlesThenCorrect() {
|
||||
request().get("index");
|
||||
a(responseContent()).shouldContain("<td>Introduction to Mule</td>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenKeywordWhenFoundArticleThenCorrect() {
|
||||
request().param("key", "Java")
|
||||
.get("search");
|
||||
a(responseContent()).shouldContain("<td>Article with Java</td>");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package app.models;
|
||||
|
||||
import org.javalite.activejdbc.Base;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ProductUnitTest {
|
||||
|
||||
//@Test
|
||||
public void givenSavedProduct_WhenFindFirst_ThenSavedProductIsReturned() {
|
||||
//Open DB connection
|
||||
Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/dbname", "user", "password");
|
||||
|
||||
//Create a product and save it
|
||||
Product toSaveProduct = new Product();
|
||||
toSaveProduct.set("name", "Bread");
|
||||
toSaveProduct.saveIt();
|
||||
|
||||
//Find product
|
||||
Product savedProduct = Product.findFirst("name = ?", "Bread");
|
||||
|
||||
Assert.assertEquals(toSaveProduct.get("name"), savedProduct.get("name"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user