I am using Jetty's ProxyServlet as a HTTP proxy.
After I start the server and add the socks proxy in firefox I can access websites through the proxy without any problems.
The problem is that when I try to access a HTTPs website through the proxy. Firefox displays a "Server not found" error and during debugging I don't see anything happening in my Java code.
Am I missing something here to add SSL support to Jetty?
Here's part of the code:
Server httpProxy = new Server(8087);
ServletHandler servletHandler = new ServletHandler();
servletHandler.addServletWithMapping(new ServletHolder(new TunnelProxyServlet()), "/*");
httpProxy.setHandler(servletHandler);
try {
httpProxy.start();
} catch (Exception ex) {
Logger.getLogger(HttpProxy.class.getName()).log(Level.SEVERE, null, ex);
}
public class TunnelProxyServlet 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);
}
}
If you are using a central-to-remote configuration, configure your system to use HTTPS between servers in Central Server mode. JAVA_OPTIONS="-Djetty.home=$JETTY_HOME -Djetty.log=$JETTY_LOG -Djava.protocol.handler.pkgs=com.ibm.net.ssl.www2.protocol -Xms128m -Xmx512m -server $JAVA_OPTIONS"
In the jetty-ssl.xml file, locate the lines that are similar to these lines, and then paste these lines into the jetty.xml file. <New id="sslContextFactory" class="org.eclipse.jetty.http.ssl.SslContextFactory"> <Set name="KeyStore"><Property name="jetty.home" default="."
Further Jetty is the best choice for local development either embedded or using jetty-maven-plugin. In this case it does not make sense to replicate the entire environment locally, instead those urls can be proxied in local environment such that /someotherapp/style.css would be proxied to http://devhost:3000/someotherapp/style.css
We use https for secure communication over the computer network. Technically, https is not a protocol in and of itself; rather, it is the result of simply layering the Hypertext Transfer Protocol (HTTP) on top of the SSL/TLS protocol, thus adding the security capabilities of SSL/TLS to standard HTTP communications.
ZmK's answer is simply a copy of the example from Jetty repositories and does not even work.
Jetty by default does not have an HTTPS Proxy. The AsyncProxyServlet and ProxyServlet classes only do HTTP proxy. In order for you to do an HTTPS proxy, do the following:
Here is the code example in detail: https://github.com/k2k2e6/jettyHttpsProxy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With