Skip to content

zouni88/android-http-server

 
 

Repository files navigation

Android HTTP Server

Small but powerful multithreaded web server written completely in Java SE and then ported to Android.

Build Status codecov Codacy Badge

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.

Key features

  • 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)

Building application

The provided Gradle wrapper should be used to build the application:

./gradlew build

Testing http subproject

The http subproject is independent on Android platform and can be tested in the following way:

./gradlew :http:clean :http:check

Running standalone server (CLI)

./gradlew :cli:bootRun

Sample code

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.

Screens

Admin main activity HTTP back-office login HTTP back-office menu

HTTP back-office drive access HTTP back-office server statistics HTTP back-office SMS inbox

500 error page trace

Servlet error 500

Sample script to send SMS using wget

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

About

Android HTTP server

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 99.6%
  • Other 0.4%