• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java LocalServerTestBase类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.http.localserver.LocalServerTestBase的典型用法代码示例。如果您正苦于以下问题:Java LocalServerTestBase类的具体用法?Java LocalServerTestBase怎么用?Java LocalServerTestBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



LocalServerTestBase类属于org.apache.http.localserver包,在下文中一共展示了LocalServerTestBase类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testBasicSSL

import org.apache.http.localserver.LocalServerTestBase; //导入依赖的package包/类
@Test
public void testBasicSSL() throws Exception {
    this.server = ServerBootstrap.bootstrap()
            .setServerInfo(LocalServerTestBase.ORIGIN)
            .setSslContext(SSLTestContexts.createServerSSLContext())
            .create();
    this.server.start();

    final HttpContext context = new BasicHttpContext();
    final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifier();
    final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
            SSLTestContexts.createClientSSLContext(), hostVerifier);
    final Socket socket = socketFactory.createSocket(context);
    final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
    final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
    final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
    try {
        final SSLSession sslsession = sslSocket.getSession();

        Assert.assertNotNull(sslsession);
        Assert.assertTrue(hostVerifier.isFired());
    } finally {
        sslSocket.close();
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:TestSSLSocketFactory.java


示例2: testBasicDefaultHostnameVerifier

import org.apache.http.localserver.LocalServerTestBase; //导入依赖的package包/类
@Test
public void testBasicDefaultHostnameVerifier() throws Exception {
    this.server = ServerBootstrap.bootstrap()
            .setServerInfo(LocalServerTestBase.ORIGIN)
            .setSslContext(SSLTestContexts.createServerSSLContext())
            .create();
    this.server.start();

    final HttpContext context = new BasicHttpContext();
    final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
            SSLTestContexts.createClientSSLContext(), SSLConnectionSocketFactory.getDefaultHostnameVerifier());
    final Socket socket = socketFactory.createSocket(context);
    final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
    final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
    final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
    try {
        final SSLSession sslsession = sslSocket.getSession();

        Assert.assertNotNull(sslsession);
    } finally {
        sslSocket.close();
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:24,代码来源:TestSSLSocketFactory.java


示例3: testClientAuthSSL

import org.apache.http.localserver.LocalServerTestBase; //导入依赖的package包/类
@Test
public void testClientAuthSSL() throws Exception {
    this.server = ServerBootstrap.bootstrap()
            .setServerInfo(LocalServerTestBase.ORIGIN)
            .setSslContext(SSLTestContexts.createServerSSLContext())
            .create();
    this.server.start();

    final HttpContext context = new BasicHttpContext();
    final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifier();
    final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
            SSLTestContexts.createClientSSLContext(), hostVerifier);
    final Socket socket = socketFactory.createSocket(context);
    final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
    final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
    final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
    try {
        final SSLSession sslsession = sslSocket.getSession();

        Assert.assertNotNull(sslsession);
        Assert.assertTrue(hostVerifier.isFired());
    } finally {
        sslSocket.close();
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:TestSSLSocketFactory.java


示例4: testSSLTrustVerification

import org.apache.http.localserver.LocalServerTestBase; //导入依赖的package包/类
@Test(expected=SSLException.class)
public void testSSLTrustVerification() throws Exception {
    this.server = ServerBootstrap.bootstrap()
            .setServerInfo(LocalServerTestBase.ORIGIN)
            .setSslContext(SSLTestContexts.createServerSSLContext())
            .create();
    this.server.start();

    final HttpContext context = new BasicHttpContext();
    // Use default SSL context
    final SSLContext defaultsslcontext = SSLContexts.createDefault();

    final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(defaultsslcontext,
            NoopHostnameVerifier.INSTANCE);

    final Socket socket = socketFactory.createSocket(context);
    final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
    final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
    final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
    sslSocket.close();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestSSLSocketFactory.java


示例5: LocalTestServer

import org.apache.http.localserver.LocalServerTestBase; //导入依赖的package包/类
public LocalTestServer(HttpRequestHandler handler) {
    try {
        setUp();
        HttpProcessor httpproc = HttpProcessorBuilder.create()
            .add(new ResponseDate())
            .add(new ResponseServer(LocalServerTestBase.ORIGIN))
            .add(new ResponseContent())
            .add(new ResponseConnControl())
            .add(new RequestBasicAuth())
            .add(new ResponseBasicUnauthorized()).build();
        this.serverBootstrap.setHttpProcessor(httpproc);
        this.serverBootstrap.registerHandler("*", handler);
        host = start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:yahoo,项目名称:gondola,代码行数:18,代码来源:LocalTestServer.java


示例6: setUp

import org.apache.http.localserver.LocalServerTestBase; //导入依赖的package包/类
@Before @Override
public void setUp() throws Exception {
    super.setUp();
    final HttpProcessor httpproc = HttpProcessorBuilder.create()
        .add(new ResponseDate())
        .add(new ResponseServer(LocalServerTestBase.ORIGIN))
        .add(new ResponseContent())
        .add(new ResponseConnControl())
        .add(new RequestBasicAuth())
        .add(new ResponseBasicUnauthorized()).build();
    this.serverBootstrap.setHttpProcessor(httpproc);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:13,代码来源:TestClientAuthentication.java


示例7: testBasicAuthenticationSuccessOnNonRepeatablePutExpectContinue

import org.apache.http.localserver.LocalServerTestBase; //导入依赖的package包/类
@Test
public void testBasicAuthenticationSuccessOnNonRepeatablePutExpectContinue() throws Exception {
    final HttpProcessor httpproc = HttpProcessorBuilder.create()
        .add(new ResponseDate())
        .add(new ResponseServer(LocalServerTestBase.ORIGIN))
        .add(new ResponseContent())
        .add(new ResponseConnControl())
        .add(new RequestBasicAuth())
        .add(new ResponseBasicUnauthorized()).build();
    this.serverBootstrap.setHttpProcessor(httpproc)
        .setExpectationVerifier(new AuthExpectationVerifier())
        .registerHandler("*", new AuthHandler());

    final HttpHost target = start();

    final RequestConfig config = RequestConfig.custom()
            .setExpectContinueEnabled(true)
            .build();
    final HttpPut httpput = new HttpPut("/");
    httpput.setConfig(config);
    httpput.setEntity(new InputStreamEntity(
            new ByteArrayInputStream(
                    new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } ),
                    -1));
    final HttpClientContext context = HttpClientContext.create();
    final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
            new UsernamePasswordCredentials("test", "test"));
    context.setCredentialsProvider(credsProvider);

    final HttpResponse response = this.httpclient.execute(target, httpput, context);
    final HttpEntity entity = response.getEntity();
    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    Assert.assertNotNull(entity);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:35,代码来源:TestClientAuthentication.java


示例8: testSSLTrustVerificationOverride

import org.apache.http.localserver.LocalServerTestBase; //导入依赖的package包/类
@Test
public void testSSLTrustVerificationOverride() throws Exception {
    this.server = ServerBootstrap.bootstrap()
            .setServerInfo(LocalServerTestBase.ORIGIN)
            .setSslContext(SSLTestContexts.createServerSSLContext())
            .create();
    this.server.start();

    final HttpContext context = new BasicHttpContext();

    final TrustStrategy trustStrategy = new TrustStrategy() {

        @Override
        public boolean isTrusted(
                final X509Certificate[] chain, final String authType) throws CertificateException {
            return chain.length == 1;
        }

    };
    final SSLContext sslcontext = SSLContexts.custom()
        .loadTrustMaterial(null, trustStrategy)
        .build();
    final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
            sslcontext,
            NoopHostnameVerifier.INSTANCE);

    final Socket socket = socketFactory.createSocket(context);
    final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
    final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
    final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
    sslSocket.close();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:33,代码来源:TestSSLSocketFactory.java


示例9: testKeepAliveHeaderRespected

import org.apache.http.localserver.LocalServerTestBase; //导入依赖的package包/类
@Test
public void testKeepAliveHeaderRespected() throws Exception {
    final HttpProcessor httpproc = HttpProcessorBuilder.create()
        .add(new ResponseDate())
            .add(new ResponseServer(LocalServerTestBase.ORIGIN))
        .add(new ResponseContent())
        .add(new ResponseConnControl())
        .add(new ResponseKeepAlive()).build();

    this.serverBootstrap.setHttpProcessor(httpproc)
            .registerHandler("/random/*", new RandomHandler());

    this.connManager.setMaxTotal(1);
    this.connManager.setDefaultMaxPerRoute(1);

    final HttpHost target = start();

    HttpResponse response = this.httpclient.execute(target, new HttpGet("/random/2000"));
    EntityUtils.consume(response.getEntity());

    Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());

    response = this.httpclient.execute(target, new HttpGet("/random/2000"));
    EntityUtils.consume(response.getEntity());

    Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());

    // Now sleep for 1.1 seconds and let the timeout do its work
    Thread.sleep(1100);
    response = this.httpclient.execute(target, new HttpGet("/random/2000"));
    EntityUtils.consume(response.getEntity());

    Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());

    // Do another request just under the 1 second limit & make
    // sure we reuse that connection.
    Thread.sleep(500);
    response = this.httpclient.execute(target, new HttpGet("/random/2000"));
    EntityUtils.consume(response.getEntity());

    Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:43,代码来源:TestConnectionReuse.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Cookies类代码示例发布时间:2022-05-22
下一篇:
Java OWL2类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap