The Artima Developer Community
Sponsored Link

Java Buzz Forum
It's All So Simple

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Brian McCallister

Posts: 1282
Nickname: frums
Registered: Sep, 2003

Brian McCallister is JustaProgrammer who thinks too much.
It's All So Simple Posted: Apr 23, 2004 6:46 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Brian McCallister.
Original Post: It's All So Simple
Feed Title: Waste of Time
Feed URL: http://kasparov.skife.org/blog/index.rss
Feed Description: A simple waste of time and weblog experiment
Latest Java Buzz Posts
Latest Java Buzz Posts by Brian McCallister
Latest Posts From Waste of Time

Advertisement

Guillaume LaForge of Groovy fame (he keeps adding all the absurdly convenient methods to existing java classes when used from Groovy) pointed me towards Simple, a Java based http server.

The API for writing services for Simple makes the Servlet API look painful to use. I am not kidding.

Oh yeah, as a side benefit, Niall (Simple's creator) has benchmarks demonstrating that it slightly outperforms the Apache Web Server 1.3.X.

Giving it the ten minute test -- it passed. I had an embedded http server up and running fast. The class below implements a full embedded web server. All requests go to the org.skife.simple.HelloService.

package org.skife.simple;

import simple.http.ProtocolHandler;
import simple.http.connect.Connection;
import simple.http.connect.ConnectionFactory;
import simple.http.load.LoaderEngine;
import simple.http.serve.HandlerFactory;

import java.net.ServerSocket;

public class Main
{
    public static void main(String[] args) throws Exception
    {
        LoaderEngine engine = new LoaderEngine();
        engine.load("default", "org.skife.simple.HelloService");
        engine.link("*", "default");
        ProtocolHandler handler = HandlerFactory.getInstance(engine);
        Connection connection = ConnectionFactory.getConnection(handler);
        connection.connect(new ServerSocket(8282));
    }
}

The hello service in turn simple creates a list of things in my src/java blosxom entries directory:

package org.skife.simple;

import simple.http.Request;
import simple.http.Response;
import simple.http.load.BasicService;
import simple.http.serve.Context;

import java.io.File;
import java.io.PrintStream;

public class HelloService extends BasicService
{
    public static final File entry_dir =
            new File("/secret/path/to/blosxom/entries");

    public HelloService(Context context)
    {
        super(context);
    }

    public void process(Request req, Response resp) throws Exception
    {
        PrintStream out = resp.getPrintStream();
        out.println("<html><body><ul>");
        File[] entries = entry_dir.listFiles();
        for (int i = 0; i < entries.length; i++)
        {
            out.println("<li>" + entries[i].getName() + "</li>");
        }
        out.println("</ul></body></html>");
        out.close();
    }
}

And voila. I likes what I have played with so far quite a bit. Cookies, templates (Velocity), etc are all bundled into the main distro. Mamba also exists as a standalone server built on Simple.

Read: It's All So Simple

Topic: 1,840 Previous Topic   Next Topic Topic: Page 23

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use