GVKun编程网logo

不推荐使用sslcontextbuilder和SSLContexts(ssl不能提供)

17

在这里,我们将给大家分享关于不推荐使用sslcontextbuilder和SSLContexts的知识,让您更了解ssl不能提供的本质,同时也会涉及到如何更有效地2015年12月1日:JDKSSLCo

在这里,我们将给大家分享关于不推荐使用sslcontextbuilder和SSLContexts的知识,让您更了解ssl不能提供的本质,同时也会涉及到如何更有效地2015年12月1日:JDK SSLContext 性能问题、com.squareup.okhttp.internal.SslContextBuilder的实例源码、Context context =getBaseContext (); 我在 Activity 类下面调用。为什么在 onCreate 方法里面再调用 context 就是空了?、Context.getExternalFilesDir()和Context.getExternalCacheDir()方法的内容。

本文目录一览:

不推荐使用sslcontextbuilder和SSLContexts(ssl不能提供)

不推荐使用sslcontextbuilder和SSLContexts(ssl不能提供)

我正在使用JDK Compilance JavaSE-1.7,Eclipse Luna和Apache httpclient 4.4.1的JDK1.8。

我在Eclipse中得到警告, sslcontextbuilder和SSLContexts已被弃用。 什么是这些类的替代品?

PHP没有解释,显示在视图源

如何在eclipse中安装javax和apache插件?

无法创buildCOM对象“X”:未在其他WAMP中注册的类

Apache AXIS在parsing时忽略/跳过其他元素

保持两个MysqL数据库(在不同的位置)同步的策略?

我实际上只是看着这个,看来HttpCLient SSLContexts类正在从org.apache.http.conn.ssl.SSLContexts移动到org.apache.http.ssl.SSLContexts。 我改变了我的进口到这些新的包,现在看来是好的。 不知道你的参考是什么sslcontextbuilder,但我很确定它也有一个替代的实现。 让我知道更多的细节,我可以检查。

总结

以上是小编为你收集整理的不推荐使用sslcontextbuilder和SSLContexts全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

2015年12月1日:JDK SSLContext 性能问题

2015年12月1日:JDK SSLContext 性能问题

2015年12月的第一天,暗无天日

在测试用 Netty 实现的反向代理的过程中发现了一个疑似为 JDK bug 的问题。我们测试出来的现象和这个 bug 所描述的问题很相似,都有 SSLContext.createSSLEngine() 调用缓慢的问题。但是这个 bug 描述提到了会加载很多的证书,这个和我们的情况不同。

但在在一些 Netty 相关的文章中也提到了 JDK SSLContext 的性能问题:

  • Netty Best Practices a.k.a Faster == Better
  • Netty & the JVM meet OpenSSL to speed up connections

目前最有效的解决办法是使用 io.netty.handler.ssl.OpenSslContext。在此之前,先测试看 JDK SSLEngine 的性能问题与连接数的多少有什么样的关系。

Netty 使用 OpenSSL 的例子

com.squareup.okhttp.internal.SslContextBuilder的实例源码

com.squareup.okhttp.internal.SslContextBuilder的实例源码

项目:platform_external_okhttp    文件:OkHttp.java   
@Override public void prepare(Benchmark benchmark) {
  super.prepare(benchmark);
  client = new OkHttpClient();
  client.setProtocols(benchmark.protocols);

  if (benchmark.tls) {
    SSLContext sslContext = SslContextBuilder.localhost();
    SSLSocketFactory socketFactory = sslContext.getSocketFactory();
    HostnameVerifier hostnameVerifier = new HostnameVerifier() {
      @Override public boolean verify(String s,SSLSession session) {
        return true;
      }
    };
    client.setSslSocketFactory(socketFactory);
    client.setHostnameVerifier(hostnameVerifier);
  }
}
项目:platform_external_okhttp    文件:Benchmark.java   
private MockWebServer startServer() throws IOException {
  Logger.getLogger(MockWebServer.class.getName()).setLevel(Level.WARNING);
  MockWebServer server = new MockWebServer();

  if (tls) {
    SSLContext sslContext = SslContextBuilder.localhost();
    server.useHttps(sslContext.getSocketFactory(),false);
    server.setNpnEnabled(true);
    server.setNpnProtocols(protocols);
  }

  final MockResponse response = newResponse();
  server.setdispatcher(new dispatcher() {
    @Override public MockResponse dispatch(RecordedRequest request) {
      return response;
    }
  });

  server.play();
  return server;
}
项目:api-java-client    文件:RestClientTest.java   
public void testConnectionFailsIfSSLConfigurationMissing() throws Exception
{
    server.useHttps(SslContextBuilder.localhost().getSocketFactory(),false);
    server.enqueue(new MockResponse().setResponseCode(204));
    server.start();

    try
    {
        newapiclient().getClient().delete("/");
        fail("SSL handshake should have Failed");
    }
    catch (Exception ex)
    {
        assertTrue(ex.getCause() instanceof SSLHandshakeException);
    }
}
项目:platform_external_okhttp    文件:NettyHttpClient.java   
@Override public void prepare(final Benchmark benchmark) {
  this.concurrencyLevel = benchmark.concurrencyLevel;
  this.targetBacklog = benchmark.targetBacklog;

  ChannelInitializer<SocketChannel> channelInitializer = new ChannelInitializer<SocketChannel>() {
    @Override public void initChannel(SocketChannel channel) throws Exception {
      ChannelPipeline pipeline = channel.pipeline();

      if (benchmark.tls) {
        SSLContext sslContext = SslContextBuilder.localhost();
        SSLEngine engine = sslContext.createSSLEngine();
        engine.setUseClientMode(true);
        pipeline.addLast("ssl",new SslHandler(engine));
      }

      pipeline.addLast("codec",new HttpClientCodec());
      pipeline.addLast("inflater",new HttpContentDecompressor());
      pipeline.addLast("handler",new HttpChannel(channel));
    }
  };

  bootstrap = new Bootstrap();
  bootstrap.group(new NioEventLoopGroup(concurrencyLevel))
      .option(ChannelOption.ALLOCATOR,PooledByteBufAllocator.DEFAULT)
      .channel(NioSocketChannel.class)
      .handler(channelInitializer);
}
项目:platform_external_okhttp    文件:UrlConnection.java   
@Override public void prepare(Benchmark benchmark) {
  super.prepare(benchmark);
  if (benchmark.tls) {
    SSLContext sslContext = SslContextBuilder.localhost();
    SSLSocketFactory socketFactory = sslContext.getSocketFactory();
    HostnameVerifier hostnameVerifier = new HostnameVerifier() {
      @Override public boolean verify(String s,SSLSession session) {
        return true;
      }
    };
    HttpsURLConnectionImpl.setDefaultHostnameVerifier(hostnameVerifier);
    HttpsURLConnectionImpl.setDefaultSSLSocketFactory(socketFactory);
  }
}
项目:platform_external_okhttp    文件:ApacheHttpClient.java   
@Override public void prepare(Benchmark benchmark) {
  super.prepare(benchmark);
  ClientConnectionManager connectionManager = new PoolingClientConnectionManager();
  if (benchmark.tls) {
    SSLContext sslContext = SslContextBuilder.localhost();
    connectionManager.getSchemeRegistry().register(
        new Scheme("https",443,new SSLSocketFactory(sslContext)));
  }
  client = new DefaultHttpClient(connectionManager);
}
项目:platform_external_okhttp    文件:OkHttpAsync.java   
@Override public void prepare(final Benchmark benchmark) {
  concurrencyLevel = benchmark.concurrencyLevel;
  targetBacklog = benchmark.targetBacklog;

  client = new OkHttpClient();
  client.setProtocols(benchmark.protocols);
  client.setdispatcher(new dispatcher(new ThreadPoolExecutor(benchmark.concurrencyLevel,benchmark.concurrencyLevel,60,TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>())));

  if (benchmark.tls) {
    SSLContext sslContext = SslContextBuilder.localhost();
    SSLSocketFactory socketFactory = sslContext.getSocketFactory();
    HostnameVerifier hostnameVerifier = new HostnameVerifier() {
      @Override public boolean verify(String s,SSLSession session) {
        return true;
      }
    };
    client.setSslSocketFactory(socketFactory);
    client.setHostnameVerifier(hostnameVerifier);
  }

  receiver = new Response.Receiver() {
    @Override public void onFailure(Failure failure) {
      System.out.println("Failed: " + failure.exception());
    }

    @Override public boolean onResponse(Response response) throws IOException {
      Response.Body body = response.body();
      long total = SynchronousHttpClient.readAllAndClose(body.byteStream());
      long finish = System.nanoTime();
      if (VERBOSE) {
        long start = (Long) response.request().tag();
        System.out.printf("Transferred % 8d bytes in %4d ms%n",total,TimeUnit.NANOSECONDS.toMillis(finish - start));
      }
      requestsInFlight.decrementAndGet();
      return true;
    }
  };
}
项目:platform_external_okhttp    文件:SpdyServer.java   
public static void main(String... args) throws Exception {
  if (args.length != 1 || args[0].startsWith("-")) {
    System.out.println("Usage: SpdyServer <base directory>");
    return;
  }

  SpdyServer server = new SpdyServer(new File(args[0]));
  server.useHttps(SslContextBuilder.localhost().getSocketFactory());
  server.run();
}
项目:api-java-client    文件:RestClientTest.java   
public void testConnectWithSSL() throws Exception
{
    server.useHttps(SslContextBuilder.localhost().getSocketFactory(),false);
    server.enqueue(new MockResponse().setResponseCode(204));
    server.start();

    newapiclient(new RelaxedSSLConfig()).getClient().delete("/");

    RecordedRequest request = server.takeRequest();
    assertRequest(request,"DELETE","/");
}
项目:mirrored-okhttp    文件:SpdyServer.java   
public static void main(String... args) throws Exception {
  if (args.length != 1 || args[0].startsWith("-")) {
    System.out.println("Usage: SpdyServer <base directory>");
    return;
  }

  SpdyServer server = new SpdyServer(new File(args[0]));
  SSLContext sslContext = new SslContextBuilder(InetAddress.getLocalHost().getHostName()).build();
  server.useHttps(sslContext.getSocketFactory());
  server.run();
}

Context context =getBaseContext (); 我在 Activity 类下面调用。为什么在 onCreate 方法里面再调用 context 就是空了?

Context context =getBaseContext (); 我在 Activity 类下面调用。为什么在 onCreate 方法里面再调用 context 就是空了?

方法一 可以
public class DelCacheActivity extends MessageActivity {
    
    private static String Size = null;
    Context context;
    DelCacheManager dcm = new DelCacheManager();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	init("设置", "设置");	
	setContentView (R.layout.shezhi);
	context = getBaseContext();
	TextView textView = (TextView) this.findViewById(R.id.delcache);
	textView.setOnClickListener(new ButtonClickListener());
    }
}
方法二,方法二为什么不行?
public class DelCacheActivity extends MessageActivity {
    
    private static String Size = null;
    Context context = getBaseContext();;
    DelCacheManager dcm = new DelCacheManager();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	init("设置", "设置");	
	setContentView (R.layout.shezhi);
	
	TextView textView = (TextView) this.findViewById(R.id.delcache);
	textView.setOnClickListener(new ButtonClickListener());
    }
}


Context context =getBaseContext (); 我在 Activity 类下面调用。为什么在 onCreate 方法里面再调用 context 就是空了?

Context.getExternalFilesDir()和Context.getExternalCacheDir()方法

Context.getExternalFilesDir()和Context.getExternalCacheDir()方法

应用程序在运行的过程中如果需要向手机上保存数据,一般是把数据保存在SDcard中的。
大部分应用是直接在SDCard的根目录下创建一个文件夹,然后把数据保存在该文件夹中。
这样当该应用被卸载后,这些数据还保留在SDCard中,留下了垃圾数据。
如果你想让你的应用被卸载后,与该应用相关的数据也清除掉,该怎么办呢?

通过Context.getExternalFilesDir()方法可以获取到 SDCard/Android/data/你的应用的包名/files/ 目录,一般放一些长时间保存的数据
通过Context.getExternalCacheDir()方法可以获取到 SDCard/Android/data/你的应用包名/cache/目录,一般存放临时缓存数据

如果使用上面的方法,当你的应用在被用户卸载后,SDCard/Android/data/你的应用的包名/ 这个目录下的所有文件都会被删除,不会留下垃圾信息。

而且上面二个目录分别对应 设置->应用->应用详情里面的”清除数据“与”清除缓存“选项


如果要保存下载的内容,就不要放在以上目录下

关于不推荐使用sslcontextbuilder和SSLContextsssl不能提供的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于2015年12月1日:JDK SSLContext 性能问题、com.squareup.okhttp.internal.SslContextBuilder的实例源码、Context context =getBaseContext (); 我在 Activity 类下面调用。为什么在 onCreate 方法里面再调用 context 就是空了?、Context.getExternalFilesDir()和Context.getExternalCacheDir()方法等相关内容,可以在本站寻找。

本文标签: