forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* BAEL-2294 * BAEL-2294 * live tests... * formatting * Live Tests! But not parent pom. Yet.
- Loading branch information
1 parent
effde80
commit 4c7ef02
Showing
35 changed files
with
1,004 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
### Relevant Articles: | ||
|
||
- [Blade - A Complete GuideBook](http://www.baeldung.com/blade) | ||
|
||
Run Integration Tests with `mvn integration-test` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
<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/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>blade</artifactId> | ||
<name>blade</name> | ||
|
||
<!-- WITH THIS mvn integration-test DOES WORK --> | ||
<groupId>com.baeldung</groupId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
|
||
<!-- WITH THIS mvn integration-test DOESN'T WORK --> | ||
<!-- <parent> --> | ||
<!-- <groupId>com.baeldung</groupId> --> | ||
<!-- <artifactId>parent-modules</artifactId> --> | ||
<!-- <version>1.0.0-SNAPSHOT</version> --> | ||
<!-- </parent> --> | ||
|
||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.bladejava</groupId> | ||
<artifactId>blade-mvc</artifactId> | ||
<version>2.0.14.RELEASE</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.webjars</groupId> | ||
<artifactId>bootstrap</artifactId> | ||
<version>4.2.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>3.8.1</version> | ||
</dependency> | ||
|
||
<!-- PROVIDED --> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.4</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- TEST --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<version>3.11.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
<version>4.5.6</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpmime</artifactId> | ||
<version>4.5.6</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpcore</artifactId> | ||
<version>4.4.10</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<finalName>sample-blade-app</finalName> | ||
<plugins> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<forkCount>3</forkCount> | ||
<reuseForks>true</reuseForks> | ||
<excludes> | ||
<exclude>**/*LiveTest.java</exclude> | ||
</excludes> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<version>3.0.0-M3</version> | ||
<configuration> | ||
<includes> | ||
<include>**/*LiveTest.java</include> | ||
</includes> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>integration-test</goal> | ||
<goal>verify</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>com.bazaarvoice.maven.plugins</groupId> | ||
<artifactId>process-exec-maven-plugin</artifactId> | ||
<version>0.7</version> | ||
<executions> | ||
<!--Start Blade --> | ||
<execution> | ||
<id>blade-process</id> | ||
<phase>pre-integration-test</phase> | ||
<goals> | ||
<goal>start</goal> | ||
</goals> | ||
<configuration> | ||
<name>Blade</name> | ||
<waitForInterrupt>false</waitForInterrupt> | ||
<arguments> | ||
<argument>java</argument> | ||
<argument>-jar</argument> | ||
<argument>sample-blade-app.jar</argument> | ||
</arguments> | ||
</configuration> | ||
</execution> | ||
|
||
<!--Stop all processes in reverse order --> | ||
<execution> | ||
<id>stop-all</id> | ||
<phase>post-integration-test</phase> | ||
<goals> | ||
<goal>stop-all</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
|
||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<version>3.1.0</version> | ||
<configuration> | ||
<finalName>${project.build.finalName}</finalName> | ||
<appendAssemblyId>false</appendAssemblyId> | ||
<archive> | ||
<manifest> | ||
<mainClass>com.baeldung.blade.sample.App</mainClass> | ||
</manifest> | ||
</archive> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>make-assembly</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
<encoding>UTF-8</encoding> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.baeldung.blade.sample; | ||
|
||
import com.baeldung.blade.sample.interceptors.BaeldungMiddleware; | ||
import com.blade.Blade; | ||
import com.blade.event.EventType; | ||
import com.blade.mvc.WebContext; | ||
import com.blade.mvc.http.Session; | ||
|
||
public class App { | ||
|
||
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(App.class); | ||
|
||
public static void main(String[] args) { | ||
|
||
Blade.of() | ||
.get("/", ctx -> ctx.render("index.html")) | ||
.get("/basic-route-example", ctx -> ctx.text("GET called")) | ||
.post("/basic-route-example", ctx -> ctx.text("POST called")) | ||
.put("/basic-route-example", ctx -> ctx.text("PUT called")) | ||
.delete("/basic-route-example", ctx -> ctx.text("DELETE called")) | ||
.addStatics("/custom-static") | ||
// .showFileList(true) | ||
.enableCors(true) | ||
.before("/user/*", ctx -> log.info("[NarrowedHook] Before '/user/*', URL called: " + ctx.uri())) | ||
.on(EventType.SERVER_STARTED, e -> { | ||
String version = WebContext.blade() | ||
.env("app.version") | ||
.orElse("N/D"); | ||
log.info("[Event::serverStarted] Loading 'app.version' from configuration, value: " + version); | ||
}) | ||
.on(EventType.SESSION_CREATED, e -> { | ||
Session session = (Session) e.attribute("session"); | ||
session.attribute("mySessionValue", "Baeldung"); | ||
}) | ||
.use(new BaeldungMiddleware()) | ||
.start(App.class, args); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
blade/src/main/java/com/baeldung/blade/sample/AttributesExampleController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.baeldung.blade.sample; | ||
|
||
import com.blade.mvc.annotation.GetRoute; | ||
import com.blade.mvc.annotation.Path; | ||
import com.blade.mvc.http.Request; | ||
import com.blade.mvc.http.Response; | ||
import com.blade.mvc.http.Session; | ||
|
||
@Path | ||
public class AttributesExampleController { | ||
|
||
public final static String REQUEST_VALUE = "Some Request value"; | ||
public final static String SESSION_VALUE = "1337"; | ||
public final static String HEADER = "Some Header"; | ||
|
||
@GetRoute("/request-attribute-example") | ||
public void getRequestAttribute(Request request, Response response) { | ||
request.attribute("request-val", REQUEST_VALUE); | ||
String requestVal = request.attribute("request-val"); | ||
response.text(requestVal); | ||
} | ||
|
||
@GetRoute("/session-attribute-example") | ||
public void getSessionAttribute(Request request, Response response) { | ||
Session session = request.session(); | ||
session.attribute("session-val", SESSION_VALUE); | ||
String sessionVal = session.attribute("session-val"); | ||
response.text(sessionVal); | ||
} | ||
|
||
@GetRoute("/header-example") | ||
public void getHeader(Request request, Response response) { | ||
String headerVal = request.header("a-header", HEADER); | ||
response.header("a-header", headerVal); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
blade/src/main/java/com/baeldung/blade/sample/LogExampleController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.baeldung.blade.sample; | ||
|
||
import com.blade.mvc.annotation.Path; | ||
import com.blade.mvc.annotation.Route; | ||
import com.blade.mvc.http.Response; | ||
|
||
@Path | ||
public class LogExampleController { | ||
|
||
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LogExampleController.class); | ||
|
||
@Route(value = "/test-logs") | ||
public void testLogs(Response response) { | ||
log.trace("This is a TRACE Message"); | ||
log.debug("This is a DEBUG Message"); | ||
log.info("This is an INFO Message"); | ||
log.warn("This is a WARN Message"); | ||
log.error("This is an ERROR Message"); | ||
response.text("Check in ./logs"); | ||
} | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
blade/src/main/java/com/baeldung/blade/sample/ParameterInjectionExampleController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.baeldung.blade.sample; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.StandardOpenOption; | ||
|
||
import com.baeldung.blade.sample.vo.User; | ||
import com.blade.mvc.annotation.CookieParam; | ||
import com.blade.mvc.annotation.GetRoute; | ||
import com.blade.mvc.annotation.HeaderParam; | ||
import com.blade.mvc.annotation.JSON; | ||
import com.blade.mvc.annotation.MultipartParam; | ||
import com.blade.mvc.annotation.Param; | ||
import com.blade.mvc.annotation.Path; | ||
import com.blade.mvc.annotation.PathParam; | ||
import com.blade.mvc.annotation.PostRoute; | ||
import com.blade.mvc.http.Response; | ||
import com.blade.mvc.multipart.FileItem; | ||
import com.blade.mvc.ui.RestResponse; | ||
|
||
@Path | ||
public class ParameterInjectionExampleController { | ||
|
||
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ParameterInjectionExampleController.class); | ||
|
||
@GetRoute("/params/form") | ||
public void formParam(@Param String name, Response response) { | ||
log.info("name: " + name); | ||
response.text(name); | ||
} | ||
|
||
@GetRoute("/params/path/:uid") | ||
public void restfulParam(@PathParam Integer uid, Response response) { | ||
log.info("uid: " + uid); | ||
response.text(String.valueOf(uid)); | ||
} | ||
|
||
@PostRoute("/params-file") // DO NOT USE A SLASH WITHIN THE ROUTE OR IT WILL BREAK (?) | ||
@JSON | ||
public RestResponse<?> fileParam(@MultipartParam FileItem fileItem) throws Exception { | ||
try { | ||
byte[] fileContent = fileItem.getData(); | ||
|
||
log.debug("Saving the uploaded file"); | ||
java.nio.file.Path tempFile = Files.createTempFile("baeldung_tempfiles", ".tmp"); | ||
Files.write(tempFile, fileContent, StandardOpenOption.WRITE); | ||
|
||
return RestResponse.ok(); | ||
} catch (Exception e) { | ||
log.error(e.getMessage(), e); | ||
return RestResponse.fail(e.getMessage()); | ||
} | ||
} | ||
|
||
@GetRoute("/params/header") | ||
public void headerParam(@HeaderParam String customheader, Response response) { | ||
log.info("Custom header: " + customheader); | ||
response.text(customheader); | ||
} | ||
|
||
@GetRoute("/params/cookie") | ||
public void cookieParam(@CookieParam(defaultValue = "default value") String myCookie, Response response) { | ||
log.info("myCookie: " + myCookie); | ||
response.text(myCookie); | ||
} | ||
|
||
@PostRoute("/params/vo") | ||
public void voParam(@Param User user, Response response) { | ||
log.info("user as voParam: " + user.toString()); | ||
response.html(user.toString() + "<br/><br/><a href='/'>Back</a>"); | ||
} | ||
} |
Oops, something went wrong.