4

I made a simple proxy server using the Jetty ProxyServlet. It works for 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 into a war, root.war, and deployed into a Jetty server on my Mac with port 8080. Then I enabled Web Proxy (HTTP) and Secure Web Proxy (HTTPS) in the System Preferences of my Mac. As aforementioned, it works for http. However, for HTTPS, it doesn't work. So, how can I make it work with HTTPS?

BTW, according to this example (Jetty ProxyServlet with SSL support), it seems that I need to add a ConnectHandler, but I don't know how to achieve this in web.xml.

Thank you very much.

Community
  • 1
  • 1
JBT
  • 8,498
  • 18
  • 65
  • 104
  • 1
    If you are writing this new code against Jetty 9 or Servlet 3.1, then it is *strongly advised* that you use `AsyncProxyServlet` (as the normal ProxyServlet is only for migrated code from servlet 2.5) – Joakim Erdfelt Sep 02 '14 at 13:34

0 Answers0