java 设置默认的 SocketFactory
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/803511/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting the default SocketFactory
提问by jconlin
I recently migrated my web services from Axis to CXF (2.1). It appears that while Axis needed the "axis.socketSecureFactory" set, CXF grabs the default. How do I set the default SocketFactory in Java to my own implementation (such as a property)?
我最近将我的 Web 服务从 Axis 迁移到了 CXF (2.1)。看起来虽然 Axis 需要“axis.socketSecureFactory”集,但 CXF 获取默认值。如何将 Java 中的默认 SocketFactory 设置为我自己的实现(例如属性)?
What I am notlooking to do is to set the default SocketFactory properties like setting the property for my truststore, keystore and passwords.
什么我不希望做的是设置默认的SocketFactory属性,如设置该属性对我的信任,密钥库和密码。
采纳答案by Powerlord
According to the OpenJDK7 source code for javax.net.SocketFactory, the Sun JVM is hard coded to return a javax.net.DefaultSocketFactoryfor getDefault();
根据 OpenJDK7 源代码 for javax.net.SocketFactory,Sun JVM 被硬编码为返回一个javax.net.DefaultSocketFactoryforgetDefault();
Edit: However, the default SSLSocketFactory can be set by the security property ssl.SocketFactory.provider
编辑:但是,默认 SSLSocketFactory 可以由安全属性设置 ssl.SocketFactory.provider
回答by Nuoji
If we are talking about the standard sockets then Socket.setSocketImplFactory(SocketImplFactory)is used to change factory for ordinary sockets and ServerSocket.setSocketFactory(SocketImplFactory)for server sockets.
如果我们谈论的是标准套接字,则Socket.setSocketImplFactory(SocketImplFactory)用于更改普通套接字和ServerSocket.setSocketFactory(SocketImplFactory)服务器套接字的工厂。
If you are using these, then take note of the fact that you can only set these factories once.
如果您正在使用这些,请注意您只能设置这些工厂一次的事实。
Note the java socket implementation defaults to using SocksSocketImpl (a package visible class in java.net) if the it discovers that the factory is nullin case you want a factory that can switch pack to the standard java implementation.
请注意,java 套接字实现默认使用 SocksSocketImpl(java.net 中的一个包可见类),如果它发现工厂是null在你想要一个可以将包切换到标准 java 实现的工厂的情况下。

