The amaya-server implementation is based on jetty-server.
To install it, you will need:
- Java 11+
- Maven/Gradle
- Full implementation of amaya-server
- Convenient interfaces for http request handling
- Full access to jetty configuration
dependencies {
implementation group: 'com.github.romanqed', name: 'amaya-jetty', version: '1.0.0'
}
<dependency>
<groupId>io.github.amayaframework</groupId>
<artifactId>amaya-jetty</artifactId>
<version>1.0.0</version>
</dependency>
import io.github.amayaframework.jetty.JettyServerFactory;
public class Main {
public static void main(String[] args) throws Throwable {
var factory = new JettyServerFactory();
var server = factory.create();
server.setHandler(ctx -> {
var req = ctx.getRequest();
var rsp = ctx.getResponse();
rsp.getWriter().write("Hello, " + req.getQueryParameter("user"));
});
server.bind(8080);
server.start();
}
}
import io.github.amayaframework.jetty.JettyServerFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import java.util.concurrent.Executors;
public class Main {
public static void main(String[] args) throws Throwable {
var factory = new JettyServerFactory(() -> {
var ret = new QueuedThreadPool();
ret.setVirtualThreadsExecutor(Executors.newVirtualThreadPerTaskExecutor());
return ret;
});
var server = factory.create();
server.setHandler(ctx -> {
var req = ctx.getRequest();
var rsp = ctx.getResponse();
rsp.getWriter().write("Hello, " + req.getQueryParameter("user"));
});
server.bind(8080);
server.start();
}
}
import io.github.amayaframework.jetty.JettyFactory;
import io.github.amayaframework.jetty.JettyServerFactory;
import io.github.amayaframework.options.OptionSet;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.session.SessionHandler;
public class Main {
public static void main(String[] args) throws Throwable {
var factory = new JettyServerFactory(new MyServerFactory());
var server = factory.create();
server.setHandler(ctx -> {
var req = ctx.getRequest();
var rsp = ctx.getResponse();
rsp.getWriter().write("Hello, " + req.getQueryParameter("user"));
});
server.bind(8080);
server.start();
}
}
final class MyServerFactory implements JettyFactory {
@Override
public Server create(Handler handler, OptionSet options) {
// Just ignore options for example
return create(handler);
}
@Override
public Server create(Handler handler) {
var ret = new Server();
var sessionHandler = new SessionHandler();
sessionHandler.setHandler(handler);
ret.setHandler(sessionHandler);
return ret;
}
}
- Gradle - Dependency management
- Jetty 11 - Http server implementation
- jfunc - Basic functional interfaces
- amaya-context - Universal http context api
- amaya-server - Universal server api
- RomanQed - Main work
See also the list of contributors who participated in this project.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details