本文整理汇总了Java中org.littleshoot.proxy.HttpProxyServer类的典型用法代码示例。如果您正苦于以下问题:Java HttpProxyServer类的具体用法?Java HttpProxyServer怎么用?Java HttpProxyServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpProxyServer类属于org.littleshoot.proxy包,在下文中一共展示了HttpProxyServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unregisterProxyServer
import org.littleshoot.proxy.HttpProxyServer; //导入依赖的package包/类
/**
* Unregisters the specified proxy server from this server group. If this was the last registered proxy server, the
* server group will be shut down.
*
* @param proxyServer proxy server instance to unregister
* @param graceful when true, the server group shutdown (if necessary) will be graceful
*/
public void unregisterProxyServer(HttpProxyServer proxyServer, boolean graceful) {
synchronized (SERVER_REGISTRATION_LOCK) {
boolean wasRegistered = registeredServers.remove(proxyServer);
if (!wasRegistered) {
log.warn("Attempted to unregister proxy server from ServerGroup that it was not registered with. Was the proxy unregistered twice?");
}
if (registeredServers.isEmpty()) {
log.debug("Proxy server unregistered from ServerGroup. No proxy servers remain registered, so shutting down ServerGroup.");
shutdown(graceful);
} else {
log.debug("Proxy server unregistered from ServerGroup. Not shutting down ServerGroup ({} proxy servers remain registered).", registeredServers.size());
}
}
}
示例2: testSftpSimpleProduceThroughProxy
import org.littleshoot.proxy.HttpProxyServer; //导入依赖的package包/类
@Test
public void testSftpSimpleProduceThroughProxy() throws Exception {
if (!canTest()) {
return;
}
// start http proxy
HttpProxyServer proxyServer = new DefaultHttpProxyServer(proxyPort);
proxyServer.addProxyAuthenticationHandler(new ProxyAuthorizationHandler() {
@Override
public boolean authenticate(String userName, String password) {
return "user".equals(userName) && "password".equals(password);
}
});
proxyServer.start();
template.sendBodyAndHeader("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR + "?username=admin&password=admin&proxy=#proxy", "Hello World", Exchange.FILE_NAME, "hello.txt");
File file = new File(FTP_ROOT_DIR + "/hello.txt");
assertTrue("File should exist: " + file, file.exists());
assertEquals("Hello World", context.getTypeConverter().convertTo(String.class, file));
proxyServer.stop();
}
示例3: testSftpSimpleSubPathProduceThroughProxy
import org.littleshoot.proxy.HttpProxyServer; //导入依赖的package包/类
@Test
public void testSftpSimpleSubPathProduceThroughProxy() throws Exception {
if (!canTest()) {
return;
}
// start http proxy
HttpProxyServer proxyServer = new DefaultHttpProxyServer(proxyPort);
proxyServer.addProxyAuthenticationHandler(new ProxyAuthorizationHandler() {
@Override
public boolean authenticate(String userName, String password) {
return "user".equals(userName) && "password".equals(password);
}
});
proxyServer.start();
template.sendBodyAndHeader("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR + "/mysub?username=admin&password=admin&proxy=#proxy", "Bye World", Exchange.FILE_NAME, "bye.txt");
File file = new File(FTP_ROOT_DIR + "/mysub/bye.txt");
assertTrue("File should exist: " + file, file.exists());
assertEquals("Bye World", context.getTypeConverter().convertTo(String.class, file));
proxyServer.stop();
}
示例4: testSftpSimpleTwoSubPathProduceThroughProxy
import org.littleshoot.proxy.HttpProxyServer; //导入依赖的package包/类
@Test
public void testSftpSimpleTwoSubPathProduceThroughProxy() throws Exception {
if (!canTest()) {
return;
}
// start http proxy
HttpProxyServer proxyServer = new DefaultHttpProxyServer(proxyPort);
proxyServer.addProxyAuthenticationHandler(new ProxyAuthorizationHandler() {
@Override
public boolean authenticate(String userName, String password) {
return "user".equals(userName) && "password".equals(password);
}
});
proxyServer.start();
template.sendBodyAndHeader("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR + "/mysub/myother?username=admin&password=admin&proxy=#proxy", "Farewell World", Exchange.FILE_NAME,
"farewell.txt");
File file = new File(FTP_ROOT_DIR + "/mysub/myother/farewell.txt");
assertTrue("File should exist: " + file, file.exists());
assertEquals("Farewell World", context.getTypeConverter().convertTo(String.class, file));
proxyServer.stop();
}
示例5: startRequestFailingProxy
import org.littleshoot.proxy.HttpProxyServer; //导入依赖的package包/类
/**
* Starts a proxy that fails all requests except every {@code failures}'th request per unique (method, uri) pair.
*/
public static HttpProxyServer startRequestFailingProxy(int defaultFailures, ConcurrentMap<String, List<FullHttpRequest>> requests, HttpResponseStatus error,
BiFunction<FullHttpRequest, Integer, Optional<Boolean>> customFailDecider)
{
return startRequestFailingProxy(request -> {
String key = request.getMethod() + " " + request.getUri();
List<FullHttpRequest> keyedRequests = requests.computeIfAbsent(key, k -> new ArrayList<>());
int n;
synchronized (keyedRequests) {
keyedRequests.add(request.copy());
n = keyedRequests.size();
}
boolean fail = customFailDecider.apply(request, n).or(() -> n % defaultFailures != 0);
if (fail) {
return Optional.of(error);
}
else {
return Optional.absent();
}
});
}
示例6: start
import org.littleshoot.proxy.HttpProxyServer; //导入依赖的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();
}
示例7: run
import org.littleshoot.proxy.HttpProxyServer; //导入依赖的package包/类
public void run() {
validate();
startNotificationRegisterEndpoint(notificationEndpointHost, notificationEndpointPort);
MockingFCMServerBackgroundThread backgroundThread =
new MockingFCMServerBackgroundThread(
fcmMockServerHost,
fcmMockServerPort,
new File(fcmCertificate),
new File(fcmCertificateKey));
backgroundThread.start();
logger.log(Level.INFO, "Background thread started in FCMProxyCommand");
HttpProxyServer server = new MockingFCMProxyServer.Builder()
.withHost(httpProxyHost)
.withPort(httpProxyPort)
.withMockServerHost(fcmMockServerHost)
.withMockServerPort(fcmMockServerPort)
.build()
.start();
logger.log(Level.INFO, "Proxy server started in FCMProxyCommand");
Runtime.getRuntime().addShutdownHook(new ServerCleanupThread(server, backgroundThread, this));
}
示例8: main
import org.littleshoot.proxy.HttpProxyServer; //导入依赖的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();
}
示例9: eSENS_TA10
import org.littleshoot.proxy.HttpProxyServer; //导入依赖的package包/类
/**
* Prerequisite:<br>
* SMSH and RMSH are configured to exchange AS4 messages according to the
* e-SENS profile (One-Way/Push MEP). Simulate the RMSH to not send receipts
* (can be done by intercepting the receipts). SMSH tries to send an AS4 User
* Message to the RMSH.<br>
* <br>
* Predicate: <br>
* The SMSH retries to send the AS4 User Message (at least once).
*
* @throws Exception
* In case of error
*/
@Test
public void eSENS_TA10 () throws Exception
{
final ICommonsMap <String, Object> aOldSettings = m_aSettings.getClone ();
final int nProxyPort = 8001;
m_aSettings.putIn (SETTINGS_SERVER_PROXY_ENABLED, true);
m_aSettings.putIn (SETTINGS_SERVER_PROXY_ADDRESS, "localhost");
m_aSettings.putIn (SETTINGS_SERVER_PROXY_PORT, nProxyPort);
final HttpProxyServer aProxyServer = _startProxyServer (nProxyPort);
try
{
// send message
final MimeMessage aMsg = MimeMessageCreator.generateMimeMessage (m_eSOAPVersion,
testSignedUserMessage (m_eSOAPVersion,
m_aPayload,
null,
new AS4ResourceManager ()),
null);
sendMimeMessage (new HttpMimeMessageEntity (aMsg), false, EEbmsError.EBMS_OTHER.getErrorCode ());
}
finally
{
aProxyServer.stop ();
// Restore original properties
m_aSettings.setAll (aOldSettings);
}
}
示例10: start
import org.littleshoot.proxy.HttpProxyServer; //导入依赖的package包/类
private HttpProxyServer start() {
if (!serverGroup.isStopped()) {
LOG.info("Starting proxy at address: " + this.requestedAddress);
serverGroup.registerProxyServer(this);
doStart();
} else {
throw new IllegalStateException("Attempted to start proxy, but proxy's server group is already stopped");
}
return this;
}
示例11: performHttpPost
import org.littleshoot.proxy.HttpProxyServer; //导入依赖的package包/类
/**
* Creates a new HTTP client that uses the specified LittleProxy instance to perform a POST of the specified size to
* to the URL. The POST body will consist of a meaningless UTF-8-encoded String (currently, the letter 'q'). The
* HTTP client is closed and discarded after the request is completed.
*
* @param url URL to post to
* @param postSizeInBytes size of the POST body
* @param proxyServer LittleProxy instance through which the POST will be proxied
* @return the HttpResponse from the server
*/
public static org.apache.http.HttpResponse performHttpPost(String url, int postSizeInBytes, HttpProxyServer proxyServer) {
CloseableHttpClient httpClient = buildHttpClient(proxyServer);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < postSizeInBytes; i++) {
sb.append('q');
}
HttpPost post = new HttpPost(url);
post.setEntity(new StringEntity(sb.toString(), Charset.forName("UTF-8")));
return performHttpRequest(httpClient, post);
}
示例12: buildHttpClient
import org.littleshoot.proxy.HttpProxyServer; //导入依赖的package包/类
/**
* Returns a new HttpClient that is configured to use the specified LittleProxy instance.
*
* @param proxyServer LittleProxy instance through which requests will be proxied
* @return new HttpClient
*/
private static CloseableHttpClient buildHttpClient(HttpProxyServer proxyServer) {
CloseableHttpClient httpClient = HttpClients.custom()
.setProxy(new HttpHost("127.0.0.1", proxyServer.getListenAddress().getPort()))
.build();
return httpClient;
}
示例13: testSftpSimpleConsumeThroughProxy
import org.littleshoot.proxy.HttpProxyServer; //导入依赖的package包/类
@Test
public void testSftpSimpleConsumeThroughProxy() throws Exception {
if (!canTest()) {
return;
}
// start http proxy
HttpProxyServer proxyServer = new DefaultHttpProxyServer(proxyPort);
proxyServer.addProxyAuthenticationHandler(new ProxyAuthorizationHandler() {
@Override
public boolean authenticate(String userName, String password) {
return "user".equals(userName) && "password".equals(password);
}
});
proxyServer.start();
String expected = "Hello World";
// create file using regular file
template.sendBodyAndHeader("file://" + FTP_ROOT_DIR, expected, Exchange.FILE_NAME, "hello.txt");
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
mock.expectedHeaderReceived(Exchange.FILE_NAME, "hello.txt");
mock.expectedBodiesReceived(expected);
context.startRoute("foo");
assertMockEndpointsSatisfied();
proxyServer.stop();
}
示例14: start
import org.littleshoot.proxy.HttpProxyServer; //导入依赖的package包/类
private HttpProxyServer start() {
LOG.info("Starting proxy at address: " + this.requestedAddress);
synchronized (serverGroup) {
if (!serverGroup.stopped) {
doStart();
} else {
throw new Error("Already stopped");
}
}
return this;
}
示例15: main
import org.littleshoot.proxy.HttpProxyServer; //导入依赖的package包/类
public static void main(String[] args) {
LOG.info("Starting...");
final InetSocketAddress listeningAddress = getInterfaceAddress("eth0", 8888, Inet4Address.class);
final InetSocketAddress outgoingAddress = getInterfaceAddress("wlan0", 0, Inet6Address.class);
final HttpProxyServer server = DefaultHttpProxyServer.bootstrap() //
.withAddress(listeningAddress) //
.withNetworkInterface(outgoingAddress) //
.start();
}