Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 2 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,17 @@

# avaje-jex

Java cut down version of https://javalin.io
Javalin style Wrapper over the JDK's `jdk.httpserver` server.

```java
var app = Jex.create()
.routing(routing -> routing
.get("/", ctx -> ctx.text("hello"))
.get("/one/{id}", ctx -> ctx.text("one-" + ctx.pathParam("id")))
)
.staticFiles().addClasspath("/static", "content")
.staticFiles().addExternal("/other", "/external")
.port(8080)
.start();

```

### Goals / intention

- Help progress converting Javalin internals from Kotlin to Java
- Convert bits of Javalin internals to Java
- Maybe get feedback from David if there is design impact
- Prepare small PR's to Javalin (this is going to take time)

- Another goal is to explore some options for Javalin along the lines of
- matching routes (making use of path segment count)
- organisation of internals to reduce some statics (JavalinJson)
- modularisation of internals using ServiceLoader (for templating implementation, websockets and sse - make these all optional dependencies keeping core small)

### Design Notes (different to Javalin):
- Context is an interface
- Routing, ErrorHandling, StaticFileConfig are interfaces
- PathParser - Has segment count which we use with RouteIndex
- RouteIndex - matching paths by method + number of segments
- Immutable routes on startup - no adding/removing routes after start()
- Context json() - call through to "ServiceManager" which has the JsonService (no static JavalinJson)

### Differences to Javalin
- Uses `{}` rather than `:` for defining path parameters
- Supports use of regex in path segments e.g `{id:[0-9]+}` (provides tighter path matching)
- Added ctx.text(...) for plain text response
- Method name change to use ctx.write(...) rather than ctx.result(...)

### TODO
- cookie store
- app attributes
- basicAuthCredentials/basicAuthCredentialsExist
- plugin api
- render in progress - FreeMarker and Mustache done
- web sockets
- sse

### Intentionally excluded features
-


### To Review
- Javalin uses int getContentLength() rather than long getContentLengthLong()
- Javalin removeCookie should set null path to "/"
- endpointHandlerPath()
- bodyValidator
- static file configuration
15 changes: 0 additions & 15 deletions avaje-jex/src/main/java/io/avaje/jex/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,21 +361,6 @@ default Context render(String name) {
*/
String protocol();

/**
* Return the first UploadedFile for the specified name or null.
*/
UploadedFile uploadedFile(String name);

/**
* Return a list of UploadedFiles for the specified name, or empty list.
*/
List<UploadedFile> uploadedFiles(String name);

/**
* Return a list of all UploadedFiles.
*/
List<UploadedFile> uploadedFiles();

class Cookie {
private static final ZonedDateTime EXPIRED = ZonedDateTime.of(LocalDateTime.of(2000, 1, 1, 0, 0, 0), ZoneId.of("GMT"));
private static final DateTimeFormatter RFC_1123_DATE_TIME = DateTimeFormatter.RFC_1123_DATE_TIME;
Expand Down
10 changes: 0 additions & 10 deletions avaje-jex/src/main/java/io/avaje/jex/DJex.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@ final class DJex implements Jex {

private final Routing routing = new DefaultRouting();
private final AppLifecycle lifecycle = new DefaultLifecycle();
private final StaticFileConfig staticFiles;
private final Map<Class<?>, Object> attributes = new HashMap<>();
private final DJexConfig config = new DJexConfig();

DJex() {
this.staticFiles = new DefaultStaticFileConfig(this);
}

@Override
public DJexConfig config() {
return config;
Expand Down Expand Up @@ -105,11 +100,6 @@ public Jex context(String contextPath) {
return this;
}

@Override
public StaticFileConfig staticFiles() {
return staticFiles;
}

@Override
public Jex register(TemplateRender renderer, String... extensions) {
for (String extension : extensions) {
Expand Down
24 changes: 0 additions & 24 deletions avaje-jex/src/main/java/io/avaje/jex/DJexConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ final class DJexConfig implements JexConfig {

private boolean preCompressStaticFiles;
private JsonService jsonService;
private UploadConfig multipartConfig;
private int multipartFileThreshold = 8 * 1024;
private final Map<String, TemplateRender> renderers = new HashMap<>();
private SSLContext sslContext;

Expand Down Expand Up @@ -67,18 +65,6 @@ public JexConfig jsonService(JsonService jsonService) {
return this;
}

@Override
public JexConfig multipartConfig(UploadConfig multipartConfig) {
this.multipartConfig = multipartConfig;
return this;
}

@Override
public JexConfig multipartFileThreshold(int multipartFileThreshold) {
this.multipartFileThreshold = multipartFileThreshold;
return this;
}

@Override
public JexConfig renderer(String extension, TemplateRender renderer) {
renderers.put(extension, renderer);
Expand Down Expand Up @@ -137,16 +123,6 @@ public JsonService jsonService() {
return jsonService;
}

@Override
public UploadConfig multipartConfig() {
return multipartConfig;
}

@Override
public int multipartFileThreshold() {
return multipartFileThreshold;
}

@Override
public Map<String, TemplateRender> renderers() {
return renderers;
Expand Down
42 changes: 0 additions & 42 deletions avaje-jex/src/main/java/io/avaje/jex/DefaultStaticFileConfig.java

This file was deleted.

5 changes: 0 additions & 5 deletions avaje-jex/src/main/java/io/avaje/jex/Jex.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ static Jex create() {
*/
Jex context(String contextPath);

/**
* Return the static file configuration.
*/
StaticFileConfig staticFiles();

/**
* Explicitly register a template renderer.
* <p>
Expand Down
20 changes: 0 additions & 20 deletions avaje-jex/src/main/java/io/avaje/jex/JexConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,6 @@ public sealed interface JexConfig permits DJexConfig {
*/
JexConfig jsonService(JsonService jsonService);

/**
* Set the upload configuration.
*/
JexConfig multipartConfig(UploadConfig multipartConfig);

/**
* Set the multipartFileThreshold.
*/
JexConfig multipartFileThreshold(int multipartFileThreshold);

/**
* Register a template renderer explicitly.
*
Expand Down Expand Up @@ -118,16 +108,6 @@ public sealed interface JexConfig permits DJexConfig {
/** Enable https with the provided SSLContext. */
JexConfig sslContext(SSLContext ssl);

/**
* Return the multipartConfig.
*/
UploadConfig multipartConfig();

/**
* Return the multipartFileThreshold.
*/
int multipartFileThreshold();

/**
* Return the template renderers registered by extension.
*/
Expand Down
16 changes: 0 additions & 16 deletions avaje-jex/src/main/java/io/avaje/jex/StaticFileConfig.java

This file was deleted.

9 changes: 0 additions & 9 deletions avaje-jex/src/main/java/io/avaje/jex/StaticFileSource.java

This file was deleted.

5 changes: 0 additions & 5 deletions avaje-jex/src/main/java/io/avaje/jex/UploadConfig.java

This file was deleted.

36 changes: 0 additions & 36 deletions avaje-jex/src/main/java/io/avaje/jex/UploadedFile.java

This file was deleted.

16 changes: 0 additions & 16 deletions avaje-jex/src/main/java/io/avaje/jex/jdk/JdkContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import io.avaje.jex.Context;
import io.avaje.jex.Routing;
import io.avaje.jex.UploadedFile;
import io.avaje.jex.http.ErrorCode;
import io.avaje.jex.http.HttpResponseException;
import io.avaje.jex.security.BasicAuthCredentials;
Expand Down Expand Up @@ -441,21 +440,6 @@ public String protocol() {
return exchange.getProtocol();
}

@Override
public UploadedFile uploadedFile(String name) {
throw new UnsupportedOperationException();
}

@Override
public List<UploadedFile> uploadedFiles(String name) {
throw new UnsupportedOperationException();
}

@Override
public List<UploadedFile> uploadedFiles() {
throw new UnsupportedOperationException();
}

@Override
public OutputStream outputStream() {
return mgr.createOutputStream(this);
Expand Down