当前位置: 首页>>代码示例>>Java>>正文


Java HttpProxyServer类代码示例

本文整理汇总了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());
        }
    }
}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:24,代码来源:ServerGroup.java

示例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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:SftpSimpleProduceThroughProxyTest.java

示例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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:SftpSimpleProduceThroughProxyTest.java

示例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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:SftpSimpleProduceThroughProxyTest.java

示例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();
        }
    });
}
 
开发者ID:treasure-data,项目名称:digdag,代码行数:24,代码来源:TestUtils.java

示例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();
    }
 
开发者ID:aerogear,项目名称:push-network-proxies,代码行数:31,代码来源:MockingFCMProxyServer.java

示例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));
    }
 
开发者ID:aerogear,项目名称:push-network-proxies,代码行数:30,代码来源:FCMProxyCommand.java

示例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();
}
 
开发者ID:zh-h,项目名称:pxclawer,代码行数:10,代码来源:ProxyServer.java

示例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);
  }
}
 
开发者ID:phax,项目名称:ph-as4,代码行数:42,代码来源:AS4eSENSCEFOneWayFuncTest.java

示例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;
}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:14,代码来源:DefaultHttpProxyServer.java

示例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);
}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:24,代码来源:HttpClientUtil.java

示例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;
}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:14,代码来源:HttpClientUtil.java

示例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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:33,代码来源:SftpSimpleConsumeThroughProxyTest.java

示例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;
}
 
开发者ID:Elitward,项目名称:LittleProxy,代码行数:14,代码来源:DefaultHttpProxyServer.java

示例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();
}
 
开发者ID:kaklakariada,项目名称:java-http-proxy,代码行数:11,代码来源:Proxy.java


注:本文中的org.littleshoot.proxy.HttpProxyServer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。