This is my piece of code:
XMPPTCPConnectionConfiguration.Builder connectionBuilder =
XMPPTCPConnectionConfiguration.builder();
connectionBuilder
.setHost(MY_HOST)
.setServiceName(MY_SERVICE_NAME)
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setDebuggerEnabled(true);
XMPPTCPConnection connection = new XMPPTCPConnection(connectionBuilder.build());
connection.connect();
When running, I get this exception:
W/System.err: org.jivesoftware.smack.SmackException: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Does anyone have any fast solution to overcome this issue? I am not interested in deep understanding of the SSL protocol etc. I also don't care about security on this stage of my project.
I also want to mention that I succeeded connecting to the server using Swift application, so the issue is probably not on the server side. Thanks in advance.
// Create a connection to the jabber.org server.
// Create the configuration for this new connection
InetAddress addr = null;
try {
addr = InetAddress.getByName("192.***.**.**");
} catch (UnknownHostException e) {
e.printStackTrace();
}
HostnameVerifier verifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return false;
}
};
DomainBareJid serviceName = null;
try {
serviceName = JidCreate.domainBareFrom("localhost");
} catch (XmppStringprepException e) {
e.printStackTrace();
}
XMPPTCPConnectionConfiguration config =
XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword(USER_CURRENT_USER, "password")
.setPort(5222)
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setXmppDomain(serviceName)
.setHostnameVerifier(verifier)
.setHostAddress(addr)
.setDebuggerEnabled(true)
.build();
connection = new XMPPTCPConnection(config);
try {
connection.connect();
} catch (SmackException | IOException | InterruptedException | XMPPException e) {
e.printStackTrace();
}
try this and let me know if it worked for you..
检查此链接.. XMPPTCPConnectionConfiguration
您必须将尝试访问的服务器的证书添加到JDK信任库,或禁用主机名的验证,如上所示。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.