java epoll 例子_一个基于epoll的Java HTTP-server

Java HTTP-serverserver based on my epollHttpServer server = new HttpServer<>(8080);server.getUrlMapping().append("/", (request, response) -> response.setBody("It's alive!"));server.start();...
摘要由CSDN通过智能技术生成

68747470733a2f2f636972636c6563692e636f6d2f67682f77697a7a6172646f2f7765626572792e7376673f7374796c653d73766768747470733a2f2f636f6465636f762e696f2f67682f77697a7a6172646f2f7765626572792f6272616e63682f6d61737465722f67726170682f62616467652e737667

Java HTTP-server

server based on my epoll

HttpServer server = new HttpServer<>(8080);

server.getUrlMapping()

.append("/", (request, response) -> response.setBody("It's alive!"));

server.start();

Framework

Gradle

build.gradle

apply plugin: 'java'

apply plugin: 'application'

repositories {

jcenter()

mavenCentral()

maven {

url "https://oss.sonatype.org/content/repositories/snapshots/"

}

}

sourceCompatibility = 1.8

targetCompatibility = 1.8

version = '0.1'

mainClassName = "com.example.MyWebApp"

dependencies {

compile 'com.wizzardo:http:0.2+'

}

//create a single Jar with all dependencies

task fatJar(type: Jar) {

manifest {

attributes(

"Main-Class": mainClassName

)

}

baseName = project.name + '-all'

from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }

with jar

}

import com.wizzardo.http.framework.Controller;

import com.wizzardo.http.framework.Environment;

import com.wizzardo.http.framework.WebApplication;

import com.wizzardo.http.framework.template.Renderer;

public class MyWebApp {

static class AppController extends Controller {

public Renderer index() {

return renderString("It's alive!");

}

}

public static void main(String[] args) {

WebApplication application = new WebApplication(args);

application.onSetup(app -> {

app.getUrlMapping()

.append("/", AppController.class, "index");

});

application.start();

}

}

./gradlew fatJar

java -jar build/libs/MyWebApp-all.jar env=prod profiles.active=profile_A,profile_B

Controllers and actions could be mapped to static paths or to something dynamic with variables and wildcards

urlMapping

.append("/index", AppController.class, "index")

.append("/books/$id?", AppController.class, "books") // 'id' - is optional

.append("/optionals/$foo?/$bar?", AppController.class, "optionals") // 'foo' and 'bar' - are optional

.append("/${foo}-${bar}", AppController.class, "fooBar")

.append("/any/*", AppController.class, "any")

.append("*.html", AppController.class, "html")

.append("

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值