Created
February 6, 2012 15:46
-
-
Save jponge/1752767 to your computer and use it in GitHub Desktop.
A Jetty-based HTTP proxy. As easy as it can be.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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