All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kilim.ServletHandler Maven / Gradle / Ivy

Go to download

Coroutines, continuations, fibers, actors and message passing for the JVM

There is a newer version: 2.0.2-jdk7
Show newest version
package kilim;

import java.io.IOException;
import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



public class ServletHandler extends HttpServlet {
    Iface handler;
    public ServletHandler(Iface handler) { this.handler = handler; }

    protected void service(final HttpServletRequest req,final HttpServletResponse resp) throws ServletException,IOException {
        final AsyncContext async = req.startAsync();
        new kilim.Task() {
            public void execute() throws Pausable, Exception {
                try {
                    String result = handler.handle(req,resp);
                    if (result != null) resp.getOutputStream().print(result);
                }
                catch (Exception ex) { resp.sendError(500,"the server encountered an error"); }
                async.complete();
            }
        }.start();
    }

    
    public interface Iface {
        String handle(HttpServletRequest req,HttpServletResponse resp) throws Pausable, Exception;
    }

    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy