ProxyClassic proxyClassic = new ProxyClassic("http://test:80/", "/old"); environment.servlets().addServlet("ProxyClassic", proxyClassic).addMapping("/old/*");public class ProxyClassic extends ProxyServlet {
public ProxyClassic(String proxyTo, String proxyPrefix) { delegate._proxyTo = proxyTo; delegate._prefix = proxyPrefix; } private final TransparentDelegate delegate = new TransparentDelegate(this);
@Override public void init(ServletConfig config) throws ServletException { super.init(config); delegate.init(config); }
protected static class TransparentDelegate { private final ProxyServlet proxyServlet; private String _proxyTo; private String _prefix;
protected TransparentDelegate(ProxyServlet proxyServlet) { this.proxyServlet = proxyServlet; }
protected void init(ServletConfig config) throws ServletException { // Adjust prefix value to account for context path String contextPath = config.getServletContext().getContextPath(); _prefix = _prefix == null ? contextPath : (contextPath + _prefix); } }
<dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-proxy</artifactId> <version>9.3.9.v20160517</version> <scope>compile</scope> </dependency>You can use jetty Transparent servlet (the same as your ProxyClassic):
final ServletRegistration.Dynamic proxy = environment.servlets().addServlet("proxy", ProxyServlet.Transparent.class);
proxy.setInitParameter("proxyTo", "http://test:80/");
proxy.setInitParameter("prefix", "/old");
proxy.addMapping("/old/*");