Skip to content

Instantly share code, notes, and snippets.

@jponge
Created February 6, 2012 15:46
Show Gist options
  • Save jponge/1752767 to your computer and use it in GitHub Desktop.
Save jponge/1752767 to your computer and use it in GitHub Desktop.
A Jetty-based HTTP proxy. As easy as it can be.
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlets.ProxyServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
public class Main {
public static class MyProxyServlet extends ProxyServlet {
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
System.out.println(">> init done !");
}
@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
System.out.println(">>> got a request !");
super.service(req, res);
}
}
public static void main(String... args) throws Exception {
Server server = new Server(8080);
ServletHandler servletHandler = new ServletHandler();
servletHandler.addServletWithMapping(MyProxyServlet.class, "/*");
server.setHandler(servletHandler);
server.start();
server.join();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment