forked from javalin/javalin
-
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.
- Loading branch information
0 parents
commit ad05176
Showing
74 changed files
with
3,693 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,12 @@ | ||
target/ | ||
pom.xml.tag | ||
pom.xml.releaseBackup | ||
pom.xml.versionsBackup | ||
pom.xml.next | ||
release.properties | ||
dependency-reduced-pom.xml | ||
buildNumber.properties | ||
.mvn/timing.properties | ||
|
||
.idea | ||
*.iml |
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,3 @@ | ||
language: java | ||
jdk: | ||
- oraclejdk8 |
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,2 @@ | ||
# javalin | ||
Java/Kotlin micro web framework |
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,176 @@ | ||
<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> | ||
|
||
<parent> | ||
<groupId>org.sonatype.oss</groupId> | ||
<artifactId>oss-parent</artifactId> | ||
<version>7</version> | ||
</parent> | ||
|
||
<groupId>io.javalin</groupId> | ||
<artifactId>javalin</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<name>Javalin</name> | ||
<description>A Java/Kotlin micro web framework</description> | ||
<url>https://javalin.io</url> | ||
<licenses> | ||
<license> | ||
<name>The Apache Software License, Version 2.0</name> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
<scm> | ||
<connection>scm:git:[email protected]:tipsy/javalin.git</connection> | ||
<developerConnection>scm:git:[email protected]:tipsy/javalin.git</developerConnection> | ||
<url>https://github.com/tipsy/javalin.git</url> | ||
<tag>HEAD</tag> | ||
</scm> | ||
<developers> | ||
<developer> | ||
<name>David Åse</name> | ||
</developer> | ||
</developers> | ||
<issueManagement> | ||
<system>GitHub Issue Tracker</system> | ||
<url>https://github.com/tipsy/javalin/issues</url> | ||
</issueManagement> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
<jetty.version>9.4.5.v20170502</jetty.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<!-- Logging --> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>1.7.13</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
<version>1.7.13</version> | ||
<optional>true</optional> | ||
</dependency> | ||
|
||
<!-- Jetty --> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-server</artifactId> | ||
<version>${jetty.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-webapp</artifactId> | ||
<version>${jetty.version}</version> | ||
</dependency> | ||
|
||
<!-- Optional dependencies --> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.6.3</version> | ||
<optional>true</optional> | ||
</dependency> | ||
|
||
<!-- Test dependencies --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-library</artifactId> | ||
<version>1.3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.mashape.unirest</groupId> | ||
<artifactId>unirest-java</artifactId> | ||
<version>1.4.9</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.3</version> | ||
<configuration> | ||
<source>${java.version}</source> | ||
<target>${java.version}</target> | ||
<optimize>true</optimize> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-enforcer-plugin</artifactId> | ||
<version>1.4</version> | ||
<executions> | ||
<execution> | ||
<id>enforce-java</id> | ||
<goals> | ||
<goal>enforce</goal> | ||
</goals> | ||
<configuration> | ||
<rules> | ||
<requireJavaVersion> | ||
<version>[${java.version},)</version> | ||
</requireJavaVersion> | ||
</rules> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<version>2.10.3</version> | ||
<configuration> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<id>sign-artifacts</id> | ||
<activation> | ||
<property> | ||
<name>sign</name> | ||
<value>true</value> | ||
</property> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-gpg-plugin</artifactId> | ||
<version>1.6</version> | ||
<executions> | ||
<execution> | ||
<id>sign-artifacts</id> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>sign</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
</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,135 @@ | ||
// Javalin - https://javalin.io | ||
// Copyright 2017 David Åse | ||
// Licensed under Apache 2.0: https://github.com/tipsy/javalin/blob/master/LICENSE | ||
|
||
package javalin; | ||
|
||
import java.util.ArrayDeque; | ||
import java.util.Deque; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import javalin.security.Role; | ||
|
||
public class ApiBuilder { | ||
|
||
@FunctionalInterface | ||
public interface EndpointGroup { | ||
void addEndpoints(); | ||
} | ||
|
||
static void setStaticJavalin(Javalin javalin) { | ||
staticJavalin = javalin; | ||
} | ||
|
||
static void clearStaticJavalin() { | ||
staticJavalin = null; | ||
} | ||
|
||
private static Javalin staticJavalin; | ||
private static Deque<String> pathDeque = new ArrayDeque<>(); | ||
|
||
public static void path(String path, EndpointGroup endpointGroup) { | ||
pathDeque.addLast(path); | ||
endpointGroup.addEndpoints(); | ||
pathDeque.removeLast(); | ||
} | ||
|
||
private static String prefixPath(String path) { | ||
return pathDeque.stream().collect(Collectors.joining("")) + path; | ||
} | ||
|
||
// Everything below here is copied from the end of Javalin.java | ||
|
||
// HTTP verbs | ||
public static void get(String path, Handler handler) { | ||
staticJavalin.get(prefixPath(path), handler); | ||
} | ||
|
||
public static void post(String path, Handler handler) { | ||
staticJavalin.post(prefixPath(path), handler); | ||
} | ||
|
||
public static void put(String path, Handler handler) { | ||
staticJavalin.put(prefixPath(path), handler); | ||
} | ||
|
||
public static void patch(String path, Handler handler) { | ||
staticJavalin.patch(prefixPath(path), handler); | ||
} | ||
|
||
public static void delete(String path, Handler handler) { | ||
staticJavalin.delete(prefixPath(path), handler); | ||
} | ||
|
||
public static void head(String path, Handler handler) { | ||
staticJavalin.head(prefixPath(path), handler); | ||
} | ||
|
||
public static void trace(String path, Handler handler) { | ||
staticJavalin.trace(prefixPath(path), handler); | ||
} | ||
|
||
public static void connect(String path, Handler handler) { | ||
staticJavalin.connect(prefixPath(path), handler); | ||
} | ||
|
||
public static void options(String path, Handler handler) { | ||
staticJavalin.options(prefixPath(path), handler); | ||
} | ||
|
||
// Secured HTTP verbs | ||
public static void get(String path, Handler handler, List<Role> permittedRoles) { | ||
staticJavalin.get(prefixPath(path), handler, permittedRoles); | ||
} | ||
|
||
public static void post(String path, Handler handler, List<Role> permittedRoles) { | ||
staticJavalin.post(prefixPath(path), handler, permittedRoles); | ||
} | ||
|
||
public static void put(String path, Handler handler, List<Role> permittedRoles) { | ||
staticJavalin.put(prefixPath(path), handler, permittedRoles); | ||
} | ||
|
||
public static void patch(String path, Handler handler, List<Role> permittedRoles) { | ||
staticJavalin.patch(prefixPath(path), handler, permittedRoles); | ||
} | ||
|
||
public static void delete(String path, Handler handler, List<Role> permittedRoles) { | ||
staticJavalin.delete(prefixPath(path), handler, permittedRoles); | ||
} | ||
|
||
public static void head(String path, Handler handler, List<Role> permittedRoles) { | ||
staticJavalin.head(prefixPath(path), handler, permittedRoles); | ||
} | ||
|
||
public static void trace(String path, Handler handler, List<Role> permittedRoles) { | ||
staticJavalin.trace(prefixPath(path), handler, permittedRoles); | ||
} | ||
|
||
public static void connect(String path, Handler handler, List<Role> permittedRoles) { | ||
staticJavalin.connect(prefixPath(path), handler, permittedRoles); | ||
} | ||
|
||
public static void options(String path, Handler handler, List<Role> permittedRoles) { | ||
staticJavalin.options(prefixPath(path), handler, permittedRoles); | ||
} | ||
|
||
// Filters | ||
public static void before(String path, Handler handler) { | ||
staticJavalin.before(prefixPath(path), handler); | ||
} | ||
|
||
public static void before(Handler handler) { | ||
staticJavalin.before(prefixPath("/*"), handler); | ||
} | ||
|
||
public static void after(String path, Handler handler) { | ||
staticJavalin.after(prefixPath(path), handler); | ||
} | ||
|
||
public static void after(Handler handler) { | ||
staticJavalin.after(prefixPath("/*"), handler); | ||
} | ||
|
||
} |
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,11 @@ | ||
// Javalin - https://javalin.io | ||
// Copyright 2017 David Åse | ||
// Licensed under Apache 2.0: https://github.com/tipsy/javalin/blob/master/LICENSE | ||
|
||
package javalin; | ||
|
||
@FunctionalInterface | ||
public interface ErrorHandler { | ||
// very similar to handler, but can't throw exception | ||
void handle(Request request, Response response); | ||
} |
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,10 @@ | ||
// Javalin - https://javalin.io | ||
// Copyright 2017 David Åse | ||
// Licensed under Apache 2.0: https://github.com/tipsy/javalin/blob/master/LICENSE | ||
|
||
package javalin; | ||
|
||
@FunctionalInterface | ||
public interface ExceptionHandler<T extends Exception> { | ||
void handle(T exception, Request request, Response response); | ||
} |
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,29 @@ | ||
// Javalin - https://javalin.io | ||
// Copyright 2017 David Åse | ||
// Licensed under Apache 2.0: https://github.com/tipsy/javalin/blob/master/LICENSE | ||
|
||
package javalin; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
|
||
public class HaltException extends RuntimeException { | ||
public int statusCode = HttpServletResponse.SC_OK; | ||
public String body = "Execution halted"; | ||
|
||
HaltException() { | ||
} | ||
|
||
HaltException(int statusCode) { | ||
this.statusCode = statusCode; | ||
} | ||
|
||
HaltException(String body) { | ||
this.body = body; | ||
} | ||
|
||
public HaltException(int statusCode, String body) { | ||
this.statusCode = statusCode; | ||
this.body = body; | ||
} | ||
|
||
} |
Oops, something went wrong.