use of org.eclipse.jetty.proxy.ConnectHandler in project jetty.project by eclipse.
the class ProxyServer method main.
public static void main(String[] args) throws Exception {
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(8888);
server.addConnector(connector);
// Setup proxy handler to handle CONNECT methods
ConnectHandler proxy = new ConnectHandler();
server.setHandler(proxy);
// Setup proxy servlet
ServletContextHandler context = new ServletContextHandler(proxy, "/", ServletContextHandler.SESSIONS);
ServletHolder proxyServlet = new ServletHolder(ProxyServlet.class);
proxyServlet.setInitParameter("blackList", "www.eclipse.org");
context.addServlet(proxyServlet, "/*");
server.start();
}
use of org.eclipse.jetty.proxy.ConnectHandler in project async-http-client by AsyncHttpClient.
the class BasicHttpProxyToHttpsTest method setUpGlobal.
@BeforeClass(alwaysRun = true)
public void setUpGlobal() throws Exception {
// HTTP server
httpServer = new Server();
ServerConnector connector1 = addHttpsConnector(httpServer);
httpServer.setHandler(new EchoHandler());
httpServer.start();
httpPort = connector1.getLocalPort();
// proxy
proxy = new Server();
ServerConnector connector2 = addHttpConnector(proxy);
ConnectHandler connectHandler = new ConnectHandler() {
@Override
protected boolean handleAuthentication(HttpServletRequest request, HttpServletResponse response, String address) {
String authorization = request.getHeader(PROXY_AUTHORIZATION.toString());
if (authorization == null) {
response.setStatus(HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED);
response.setHeader(PROXY_AUTHENTICATE.toString(), "Basic realm=\"Fake Realm\"");
return false;
} else if (authorization.equals("Basic am9obmRvZTpwYXNz")) {
return true;
}
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return false;
}
};
proxy.setHandler(connectHandler);
proxy.start();
proxyPort = connector2.getLocalPort();
LOGGER.info("Local HTTP Server (" + httpPort + "), Proxy (" + proxyPort + ") started successfully");
}
use of org.eclipse.jetty.proxy.ConnectHandler in project camel by apache.
the class HttpProxyMojoIntegrationTest method setupServer.
@BeforeClass
public static void setupServer() throws Exception {
// start a local HTTP proxy using Jetty server
server = new Server();
/*
final SSLContextParameters contextParameters = new SSLContextParameters();
final SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setSslContext(contextParameters.createSSLContext());
ServerConnector connector = new ServerConnector(server, sslContextFactory);
*/
ServerConnector connector = new ServerConnector(server);
connector.setHost(HTTP_PROXY_HOST);
server.addConnector(connector);
final String authenticationString = "Basic " + B64Code.encode(HTTP_PROXY_USER_NAME + ":" + HTTP_PROXY_PASSWORD, StringUtil.__ISO_8859_1);
ConnectHandler connectHandler = new ConnectHandler() {
@Override
protected boolean handleAuthentication(HttpServletRequest request, HttpServletResponse response, String address) {
// validate proxy-authentication header
final String header = request.getHeader(PROXY_AUTHORIZATION.toString());
if (!authenticationString.equals(header)) {
LOG.warn("Missing header " + PROXY_AUTHORIZATION);
// ask for authentication header
response.setHeader(PROXY_AUTHENTICATE.toString(), String.format("Basic realm=\"%s\"", HTTP_PROXY_REALM));
return false;
}
LOG.info("Request contains required header " + PROXY_AUTHORIZATION);
return true;
}
};
server.setHandler(connectHandler);
LOG.info("Starting proxy server...");
server.start();
httpProxyPort = connector.getLocalPort();
LOG.info("Started proxy server on port {}", httpProxyPort);
}
use of org.eclipse.jetty.proxy.ConnectHandler in project camel by apache.
the class HttpProxyIntegrationTest method setupServer.
@BeforeClass
public static void setupServer() throws Exception {
// start a local HTTP proxy using Jetty server
server = new Server();
/*
final SSLContextParameters contextParameters = new SSLContextParameters();
final SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setSslContext(contextParameters.createSSLContext());
ServerConnector connector = new ServerConnector(server, sslContextFactory);
*/
ServerConnector connector = new ServerConnector(server);
connector.setHost(HTTP_PROXY_HOST);
server.addConnector(connector);
final String authenticationString = "Basic " + B64Code.encode(HTTP_PROXY_USER_NAME + ":" + HTTP_PROXY_PASSWORD, StringUtil.__ISO_8859_1);
ConnectHandler connectHandler = new ConnectHandler() {
@Override
protected boolean handleAuthentication(HttpServletRequest request, HttpServletResponse response, String address) {
// validate proxy-authentication header
final String header = request.getHeader(PROXY_AUTHORIZATION.toString());
if (!authenticationString.equals(header)) {
LOG.warn("Missing header " + PROXY_AUTHORIZATION);
// ask for authentication header
response.setHeader(PROXY_AUTHENTICATE.toString(), String.format("Basic realm=\"%s\"", HTTP_PROXY_REALM));
return false;
}
LOG.info("Request contains required header " + PROXY_AUTHORIZATION);
return true;
}
};
server.setHandler(connectHandler);
LOG.info("Starting proxy server...");
server.start();
httpProxyPort = connector.getLocalPort();
LOG.info("Started proxy server on port {}", httpProxyPort);
}
use of org.eclipse.jetty.proxy.ConnectHandler in project async-http-client by AsyncHttpClient.
the class ProxyTunnellingTest method setUpServers.
private void setUpServers(boolean targetHttps) throws Exception {
server = new Server();
ServerConnector connector = addHttpConnector(server);
server.setHandler(new ConnectHandler());
server.start();
port1 = connector.getLocalPort();
server2 = new Server();
@SuppressWarnings("resource") ServerConnector connector2 = targetHttps ? addHttpsConnector(server2) : addHttpConnector(server2);
server2.setHandler(configureHandler());
server2.start();
port2 = connector2.getLocalPort();
logger.info("Local HTTP server started successfully");
}
Aggregations