0

我有i代理,每个都有不同的 ip host_i

我想提出请求

<host_i>:4444/content

localhost:9999/content?proxy=<host_i>

我该怎么做呢?到目前为止,这是我尝试使用嵌入式码头服务器(版本:8.1.10.v20130312)的内容,但它不起作用,我无法弄清楚。我从:http ://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/得到这个例子AsyncProxyServer.java?h=jetty-8

    proxyServer = new Server();
    Connector connector = new SelectChannelConnector();
    connector.setPort(4444);
    proxyServer.setConnectors(new Connector[]{connector});

    ServletHandler handler = new ServletHandler();
    proxyServer.setHandler(handler);

    ServletHolder proxy = handler.addServletWithMapping("org.eclipse.jetty.servlets.ProxyServlet", "/");
    proxy.setAsyncSupported(true);

    proxyServer.start();

这是我使用处理请求的简单框架的代码localhost:9999

    websiteContainer = new HttpServer();
    websiteServer = new ContainerServer(websiteContainer);
    websiteConnection = new SocketConnection(websiteServer);
    final SocketAddress websiteAddress = new InetSocketAddress(9999);
    websiteConnection.connect(websiteAddress);

    public class HttpServer implements Container {
    @Override
    public void handle(final Request request, final Response response) {
            // do some stuff here, I have a breakpoint here to test if a request to a proxy made it here
    }
4

1 回答 1

0
@Override
public void handle(final Request request, final Response response) {
// building redirect url localhost:9999/content?proxy=<host_i>

 redirectUrl= "localhost:9999/" + httpRequest.getContextPath() + "? proxy =" + httpRequest.getLocalAddr();            
// do remaing stuff here
}

我希望这将解决您的问题,因为httpRequest.getContextPath()它为您提供了应用程序运行位置的 IP,并httpRequest.getContextPath()为您提供了连接路径 whish 被击中

于 2013-12-23T06:30:06.947 回答