:cherries: Android平台的Web服务器与Web框架。
AndServer 是一个HTTP和反向代理服务器。
它是Android平台的Web服务器和Web框架。它提供了类似SpringMVC的注解,如果你熟悉SpringMVC,你可以很快掌握它。
部署一个Web服务器:
Server server = AndServer.webServer(context)
.port(8080)
.timeout(10, TimeUnit.SECONDS)
.build();
// startup the server.
server.startup();
...
// shutdown the server.
server.shutdown();它还有一些特性,比如 inetAddress(InetAddress)、serverSocketFactory(ServerSocketFactory) 和 sslContext(SSLContext),具体取决于你想要实现的功能。
…上述代码将生成以下两个HTTP API:
POST http://.../user/login
GET http://.../user/uid_001?fields=id,name,age
PUT http://.../user/uid_001获取与客户端的连接信息:
@GetMapping(path = "/connection")
void getConnection(HttpRequest request, ...) {
request.getLocalAddr(); // HostAddress
request.getLocalName(); // HostName
request.getLocalPort(); // server's port
request.getRemoteAddr(); // HostAddress
request.getRemoteHost(); // Especially HostName, second HostAddress
request.getRemotePort(); // client's port
...
}有关文档和更多信息,请参阅网站。
部署反向代理服务器:
Server server = AndServer.proxyServer()
.addProxy("www.example1.com", "http://192.167.1.11:8080")
.addProxy("example2.com", "https://192.167.1.12:9090")
.addProxy("55.66.11.11", "http://www.google.com")
.addProxy("192.168.1.11", "https://github.com:6666")
.port(80)
.timeout(10, TimeUnit.SECONDS)
.build();
// startup the server.
server.startup();
...
// shutdown the server.
server.shutdown();注意:它只是一个反向代理,不具备负载均衡的能力。
将插件添加到您的项目构建脚本中:
buildscript {
repositories {
google()暂无开放 Issues,或尚未同步最近议题。