Small but powerful multithreaded web server written completely in Java SE and then ported to Android.
The server implements most of the HTTP 1.1 specification and ses its own specification of Servlets for handling dynamic pages. Servlets support cookies, sessions, file uploads and anything else to build a common web application.
It can be used as a standalone web server for static content or as a remote application back-office engine that can be accessed from web.
- Small footprint, requires no external libraries
- Handles HTTP requests in separate threads
- Supports dynamic pages via Servlets (own specification)
- Support for GET, POST, HEAD methods
- Supports chunked transfer type
Supports KEEP-ALIVE connections- Full support for mime types (uses Apache like mime.type)
- Supports buffered file upload (multipart requests)
- Exposes compact API for handling sessions
- Supports serving partial content (ranges)
The provided Gradle wrapper should be used to build the application:
./gradlew build
The http
subproject is independent on Android platform and can be tested in the following way:
./gradlew :http:clean :http:check
./gradlew :cli:bootRun
Hello World servlet
package example;
import ro.polak.http.servlet.HttpServletRequest;
import ro.polak.http.servlet.HttpServletResponse;
import ro.polak.http.servlet.HttpServlet;
public class HelloWorld extends HttpServlet {
@Override
public void service(HttpServletRequest request, HttpServletResponse response) {
response.getWriter().print("Hello World!");
}
}
More examples can be found in http/src/main/java/example.
If you want to send a real SMS please remove "&test=1" from the POST params.
SERVER_IP=192.168.1.1; SERVER_PORT=8080; echo "Phone number:"; read TO; echo "Message:"; read MESSAGE; wget -qO- --post-data "to=$TO&message=$MESSAGE&test=1" http://$SERVER_IP:$SERVER_PORT/api/SmsSend.dhtml