Jetty ProxyServlet: how to add HTTPS support?

I made a simple proxy using Jetty ProxyServlet. It works for the http protocol. Below is my code (in groovy):

MyproxyServlet

class MyProxyServlet extends ProxyServlet {
    static final Logger logger = LoggerFactory.getLogger( this )

    @Override
    void init( ServletConfig config ) throws ServletException {
        super.init( config )
        logger.info('>>> init done!')
    }

    @Override
    void service( HttpServletRequest request, HttpServletResponse response ) {
        logger.info('>>> got a request')
        super.service( request, response)
        response.addHeader('foo', 'bar')
    }
}

web.xml

<servlet>
    <servlet-name>MyProxyServlet</servlet-name>
    <servlet-class>com.foobar.MyProxyServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    <async-supported>true</async-supported>
</servlet>

<servlet-mapping>
    <servlet-name>MyProxyServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

The code is wrapped in war, root.war and deployed to the Jetty server on my Mac with port 8080. Then I included Web Proxy (HTTP)it Secure Web Proxy (HTTPS)in the System Preferences of my Mac. As stated above, it works for http. However, for HTTPS this does not work. So how can I get it to work with HTTPS?

By the way, according to this example ( Jetty ProxyServlet with SSL support ), it seems to me that I need to add ConnectHandler, but I do not know how to achieve this in web.xml.

Many thanks.

+4

All Articles