Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A simple HTTP library and server written in Java

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.rdoc

MM HTTP

A simple Java HTTP server. Simple. This projects does not pretend to be anything like a full stack web application framework. It's for simple, dynamic HTTP content.

History

This code has been extracted from the FitNesse project. One distinguishing aspect of FitNesse is it's “stand-alone” ability. Back in the day, FitNesse was a web server in a jar file. It has since grown beyond that but the simplicity of a stand alone web server was grand.

MM HTTP offer that ability.

Download

All you'll need is t he jar file.

cloud.github.com/downloads/slagyr/mmhttp/mmhttp-1.1.jar

Usage

Here is program that uses MM HTTP to start a server.

import mmhttp.protocol.*;
import mmhttp.server.*;

public class SampleMain
{
  public static void main(String[] args) throws Exception
  {
    Server server = new Server(8000);
    server.register("hello.*", HelloResponder.class);
    server.start();
  }

  public static class HelloResponder implements Responder
  {
    public Response makeResponse(Server server, Request request) throws Exception
    {
      return new SimpleResponse(200, "<h1>Hello World!</h1>");
    }
  }
}

And here's how you compile and run it.

javac -classpath mmhttp-1.1.jar SampleMain.java
java -classpath mmhttp-1.1.jar SampleMain

Then visit localhost:8000/hello to see it in action.

Documentation

You will find the javadocs for the classes in this framework at:

slagyr.github.com/mmhttp/index.html

Key Concepts

Command Pattern. This framework is built on the Command pattern where Responder is “Command” class. You can create your own implementations of Responder and register them, along with a resource pattern, on the server. When the Server receives a request, it will search through all the registered Responders to find a pattern that matches the requested resource. Once found, the Responder will be instantiated and invoked.

Something went wrong with that request. Please try again.