本文整理汇总了Java中org.littleshoot.proxy.impl.DefaultHttpProxyServer类的典型用法代码示例。如果您正苦于以下问题:Java DefaultHttpProxyServer类的具体用法?Java DefaultHttpProxyServer怎么用?Java DefaultHttpProxyServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultHttpProxyServer类属于org.littleshoot.proxy.impl包,在下文中一共展示了DefaultHttpProxyServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupDebugChannel
import org.littleshoot.proxy.impl.DefaultHttpProxyServer; //导入依赖的package包/类
public DefaultHttpProxyServer setupDebugChannel(int port) {
try {
LOGGER.info("Proxy Debug Server start up, listening on port: " + port);
DebugHttpFilterSource debugFilterSource = new DebugHttpFilterSource();
DefaultHttpProxyServer debugServer = (DefaultHttpProxyServer) DefaultHttpProxyServer.bootstrap().withPort(port)
.withManInTheMiddle(new ProxyServerMitmManager())
.withFiltersSource(debugFilterSource).start();
debugServer.setIdleConnectionTimeout(0);
Bootstrap clientBootstrap = new Bootstrap();
clientBootstrap.group(group)
.channel(NioSocketChannel.class)
.handler(new DebugNettyClientInitializer());
debugChannel = clientBootstrap.connect("127.0.0.1", port).sync().channel();
debugSslChannel = clientBootstrap.connect("127.0.0.1", port).sync().channel();
return debugServer;
} catch (Exception ex) {
LOGGER.error(ex.getMessage());
}
return null;
}
示例2: testSetupDebugChannel
import org.littleshoot.proxy.impl.DefaultHttpProxyServer; //导入依赖的package包/类
@Test
public void testSetupDebugChannel() {
DefaultHttpProxyServer debugServer = null;
try {
debugServer = debugManager.setupDebugChannel(7099);
Assert.assertNotNull(debugServer);
Assert.assertNotNull(readField(debugManager, "debugChannel"));
Assert.assertNotNull(readField(debugManager, "debugSslChannel"));
} catch (Exception ex) {
Assert.fail(ex.getMessage());
} finally {
debugManager.shutdown();
if (debugServer != null) {
debugServer.stop();
}
}
}
示例3: main
import org.littleshoot.proxy.impl.DefaultHttpProxyServer; //导入依赖的package包/类
public static void main(final String... args) {
File log4jConfigurationFile = new File(
"src/test/resources/log4j.xml");
if (log4jConfigurationFile.exists()) {
DOMConfigurator.configureAndWatch(
log4jConfigurationFile.getAbsolutePath(), 15);
}
try {
final int port = 9090;
System.out.println("About to start server on port: " + port);
HttpProxyServerBootstrap bootstrap = DefaultHttpProxyServer
.bootstrapFromFile("./littleproxy.properties")
.withPort(port).withAllowLocalOnly(false);
bootstrap.withManInTheMiddle(new CertificateSniffingMitmManager());
System.out.println("About to start...");
bootstrap.start();
} catch (Exception e) {
log.error(e.getMessage(), e);
System.exit(1);
}
}
示例4: startProxyServerWithFilterAnsweringStatusCode
import org.littleshoot.proxy.impl.DefaultHttpProxyServer; //导入依赖的package包/类
private void startProxyServerWithFilterAnsweringStatusCode(int statusCode) {
final HttpResponseStatus status = HttpResponseStatus.valueOf(statusCode);
HttpFiltersSource filtersSource = new HttpFiltersSourceAdapter() {
@Override
public HttpFilters filterRequest(HttpRequest originalRequest) {
return new HttpFiltersAdapter(originalRequest) {
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
return new DefaultHttpResponse(HttpVersion.HTTP_1_1, status);
}
};
}
};
proxyServer = DefaultHttpProxyServer.bootstrap()
.withPort(0)
.withFiltersSource(filtersSource)
.start();
}
示例5: testClientIdleBeforeRequestReceived
import org.littleshoot.proxy.impl.DefaultHttpProxyServer; //导入依赖的package包/类
/**
* Verifies that when the client times out sending the initial request, the proxy still returns a Gateway Timeout.
*/
@Test
public void testClientIdleBeforeRequestReceived() throws IOException, InterruptedException {
this.proxyServer = DefaultHttpProxyServer.bootstrap()
.withPort(0)
.withIdleConnectionTimeout(1)
.start();
// connect to the proxy and begin to transmit the request, but don't send the trailing \r\n that indicates the client has completely transmitted the request
String successfulGet = "GET http://localhost:" + mockServerPort + "/success HTTP/1.1";
// using the SocketClientUtil since we want the client to fail to send the entire GET request, which is not possible with
// Apache HTTP client and most other HTTP clients
Socket socket = SocketClientUtil.getSocketToProxyServer(proxyServer);
SocketClientUtil.writeStringToSocket(successfulGet, socket);
// wait a bit to allow the proxy server to respond
Thread.sleep(1500);
// the proxy should return an HTTP 504 due to the timeout
String response = SocketClientUtil.readStringFromSocket(socket);
assertThat("Expected to receive an HTTP 504 Gateway Timeout from the server", response, startsWith("HTTP/1.1 504"));
socket.close();
}
示例6: aWarmUpTest
import org.littleshoot.proxy.impl.DefaultHttpProxyServer; //导入依赖的package包/类
@Test
public void aWarmUpTest() throws IOException {
// a "warm-up" test so the first test's results are not skewed due to classloading, etc. guaranteed to run
// first with the @FixMethodOrder(MethodSorters.NAME_ASCENDING) annotation on the class.
HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap()
.withPort(0)
.withThrottling(0, THROTTLED_WRITE_BYTES_PER_SECOND)
.start();
int proxyPort = proxyServer.getListenAddress().getPort();
HttpGet request = createHttpGet();
DefaultHttpClient httpClient = createHttpClient(proxyPort);
EntityUtils.consumeQuietly(httpClient.execute(new HttpHost("127.0.0.1", writeWebServerPort), request).getEntity());
EntityUtils.consumeQuietly(httpClient.execute(new HttpHost("127.0.0.1", readWebServerPort), request).getEntity());
}
示例7: setup
import org.littleshoot.proxy.impl.DefaultHttpProxyServer; //导入依赖的package包/类
@Before
public void setup() throws Exception {
assumeTrue("Skipping due to non-Unix OS", TestUtils.isUnixManagementCapable());
assumeFalse("Skipping for travis-ci build", "true".equals(System.getenv("TRAVIS")));
webServer = new Server(0);
webServer.start();
webServerPort = TestUtils.findLocalHttpPort(webServer);
proxyServer = DefaultHttpProxyServer.bootstrap()
.withPort(0)
.start();
proxyServer.setIdleConnectionTimeout(10);
}
示例8: aWarmUpTest
import org.littleshoot.proxy.impl.DefaultHttpProxyServer; //导入依赖的package包/类
@Test
public void aWarmUpTest() throws IOException {
// a "warm-up" test so the first test's results are not skewed due to classloading, etc. guaranteed to run
// first with the @FixMethodOrder(MethodSorters.NAME_ASCENDING) annotation on the class.
HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap()
.withPort(0)
.withThrottling(0, THROTTLED_WRITE_BYTES_PER_SECOND)
.start();
int proxyPort = proxyServer.getListenAddress().getPort();
HttpGet request = createHttpGet();
DefaultHttpClient httpClient = createHttpClient(proxyPort);
EntityUtils.consumeQuietly(httpClient.execute(new HttpHost("127.0.0.1", WRITE_WEB_SERVER_PORT), request).getEntity());
EntityUtils.consumeQuietly(httpClient.execute(new HttpHost("127.0.0.1", READ_WEB_SERVER_PORT), request).getEntity());
}
示例9: setUp
import org.littleshoot.proxy.impl.DefaultHttpProxyServer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
adapter.reset();
proxyServer = DefaultHttpProxyServer
.bootstrap()
.withAddress(ALL_INTERFACES_AUTOMATIC_PORT)
.withFiltersSource(adapter)
.start();
final InetSocketAddress proxyAddress = proxyServer.getListenAddress();
proxyPort = Integer.toString(proxyAddress.getPort(), 10);
oldProperties = System.getProperties();
final Properties tempProperties = new Properties(oldProperties);
System.setProperties(tempProperties);
final InetAddress localHostAddress = InetAddress.getLocalHost();
localHostName = localHostAddress.getHostName();
wireMockPort = wireMockRule.port();
}
示例10: start
import org.littleshoot.proxy.impl.DefaultHttpProxyServer; //导入依赖的package包/类
public void start() throws IOException {
HttpProxyServerBootstrap boot = null;
if ("client".equals(mode)) {
boot = DefaultHttpProxyServer.bootstrap()
.withAddress(new InetSocketAddress("localhost", port))
.withChainProxyManager(chainedProxyManager())
.withTransportProtocol(TransportProtocol.TCP);
if (cache) {
boot = boot.withFiltersSource(filter);
}
} else if ("server".equals(mode)) {
SslEngineSource sslEngineSource = new KazeSslEngineSource(
"kserver.jks", "tserver.jks", false, true, "serverkey",
jkspw);
boot = DefaultHttpProxyServer.bootstrap()
.withAddress(new InetSocketAddress("0.0.0.0", port))
.withTransportProtocol(TransportProtocol.TCP)
.withSslEngineSource(sslEngineSource)
.withAuthenticateSslClients(false);
}
boot.start();
System.in.read();
}
示例11: setupProxy
import org.littleshoot.proxy.impl.DefaultHttpProxyServer; //导入依赖的package包/类
@BeforeClass
public static void setupProxy() {
ProxyAuthenticator auth = new ProxyAuthenticator() {
@Override
public boolean authenticate(String username, String password) {
return proxyUsername.equals(username) && proxyPassword.equals(password);
}
@Override
public String getRealm() {
return null;
}
};
server = DefaultHttpProxyServer.bootstrap().withPort(proxyPort).withProxyAuthenticator(auth).start();
setProxySettingForClient();
}
示例12: run
import org.littleshoot.proxy.impl.DefaultHttpProxyServer; //导入依赖的package包/类
@Override
public void run(String... args) throws Exception {
server = DefaultHttpProxyServer.bootstrap()
.withPort(conf.getPort())
.withAllowLocalOnly(false)
.withFiltersSource(new ProxyServerFilterSource())
.withManInTheMiddle(new CertificateSniffingMitmManager())
.start();
}
示例13: start
import org.littleshoot.proxy.impl.DefaultHttpProxyServer; //导入依赖的package包/类
public HttpProxyServer start() {
return DefaultHttpProxyServer.bootstrap()
.withAddress(new InetSocketAddress(host, port))
.withFiltersSource(new HttpFiltersSourceAdapter() {
@Override
public HttpFilters filterRequest(HttpRequest originalRequest) {
return new HttpFiltersAdapter(originalRequest) {
final String mockedAddress = mockServer + ":" + mockPort;
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
final HttpRequest request = (HttpRequest) httpObject;
if (request.getUri().contains("google")) {
request.setUri(mockedAddress);
}
super.clientToProxyRequest(request);
return null;
}
};
}
}).start();
}
示例14: main
import org.littleshoot.proxy.impl.DefaultHttpProxyServer; //导入依赖的package包/类
public static void main(String[] args) throws RootCertificateException {
LOGGER.info("Server Start");
HttpProxyServer server =
DefaultHttpProxyServer.bootstrap()
.withAddress(new InetSocketAddress("0.0.0.0", 8888))
.withManInTheMiddle(new CertificateSniffingMitmManager())
.withFiltersSource(new ResourceFilter())
.start();
}
示例15: start
import org.littleshoot.proxy.impl.DefaultHttpProxyServer; //导入依赖的package包/类
@Override
public void start() {
if (proxy == null) {
proxy = DefaultHttpProxyServer.bootstrap()
.withPort(port)
.withFiltersSource(getFiltersSource())
.start();
}
}