本文整理汇总了Java中org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration类的典型用法代码示例。如果您正苦于以下问题:Java XMPPTCPConnectionConfiguration类的具体用法?Java XMPPTCPConnectionConfiguration怎么用?Java XMPPTCPConnectionConfiguration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XMPPTCPConnectionConfiguration类属于org.jivesoftware.smack.tcp包,在下文中一共展示了XMPPTCPConnectionConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConnectionConfigBuilder
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; //导入依赖的package包/类
public XMPPTCPConnectionConfiguration.Builder getConnectionConfigBuilder() {
if (!isBasicConfigurationDone()) return null;
if (confBuilderCache == null) {
XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();
String password = getPassword();
builder.setUsernameAndPassword(getMyJid().getLocalpart(), password);
builder.setXmppDomain(getMyJid().asDomainBareJid());
builder.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
SSLContext sc;
try {
sc = SSLContext.getInstance("TLS");
sc.init(null, new X509TrustManager[] { mMemorizingTrustManager }, new java.security.SecureRandom());
} catch (KeyManagementException | NoSuchAlgorithmException e) {
throw new IllegalStateException(e);
}
builder.setCustomSSLContext(sc);
confBuilderCache = builder;
}
return confBuilderCache;
}
示例2: configKeyStore
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; //导入依赖的package包/类
private KeyStore configKeyStore(XMPPTCPConnectionConfiguration.Builder builder) throws KeyStoreException {
KeyStore keyStore;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
builder.setKeystorePath(null);
builder.setKeystoreType("AndroidCAStore");
keyStore = KeyStore.getInstance("AndroidCAStore");
} else {
builder.setKeystoreType("BKS");
keyStore = KeyStore.getInstance("BKS");
String path = System.getProperty("javax.net.ssl.trustStore");
if (path == null)
path = System.getProperty("java.home") + File.separator + "etc"
+ File.separator + "security" + File.separator
+ "cacerts.bks";
builder.setKeystorePath(path);
}
return keyStore;
}
示例3: connect
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; //导入依赖的package包/类
@Override
public void connect(XmppURI uri, String password) throws IOException, XMPPException, SmackException {
this.disconnect();
XMPPTCPConnectionConfiguration configuration = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword(uri.getNode(), password)
.setServiceName(uri.getDomain())
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setDebuggerEnabled(true)
.build();
AbstractXMPPConnection connection = new XMPPTCPConnection(configuration);
connection.connect();
connection.login();
// keep connection alive
// when connection is idle it will run into timeout
PingManager pingManager = PingManager.getInstanceFor(connection);
pingManager.setPingInterval(60);
pingManager.pingMyServer();
this.connection = connection;
}
示例4: newConnectionConfiguration
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; //导入依赖的package包/类
private XMPPTCPConnectionConfiguration newConnectionConfiguration(final BindingConfiguration configuration){
XMPPTCPConnectionConfiguration.Builder configurationBuilder = XMPPTCPConnectionConfiguration.builder();
configurationBuilder.setHost(configuration.getUrl())
.setPort(configuration.getPort())
.setServiceName(configuration.getServerName())
.setUsernameAndPassword(configuration.getUsername(),configuration.getPassword())
.setResource(configuration.getIdentifier())
.setDebuggerEnabled(configuration.isDebug());
if(allowSelfSigned){
try {
configurationBuilder.setCustomSSLContext(SSLHelper.newAllTrustingSslContext());
} catch (KeyManagementException | NoSuchAlgorithmException e) {
logger.error("Error registering custom ssl context",e);
}
}
return configurationBuilder.build();
}
示例5: connect
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; //导入依赖的package包/类
public void connect(String hostname, int port, String username, String password) throws Exception {
purgeTask("reconnect");
this.hostname = hostname;
this.serviceName = hostname;
this.port = port;
this.username = username;
this.password = password;
Builder builder = XMPPTCPConnectionConfiguration.builder();
builder.setUsernameAndPassword(username, password);
builder.setServiceName(serviceName);
builder.setServiceName(hostname);
builder.setPort(port);
builder.setSecurityMode(SecurityMode.disabled);
builder.setDebuggerEnabled(true);
XMPPTCPConnectionConfiguration config = builder.build();
connection = new XMPPTCPConnection(config);
connection.connect().login();
roster = Roster.getInstanceFor(connection);
chatManager = ChatManager.getInstanceFor(connection);
roster.addRosterListener(this);
isConnected = true;
// not worth it - always empty right after connect
// getContactList();
broadcastState();
}
示例6: setUp
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(XMPPIntegrationTest.class.getResourceAsStream("/server.jks"), "secret".toCharArray());
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagerFactory.getTrustManagers(), new SecureRandom());
String port = AvailablePortFinder.readServerData("xmpp-port");
ConnectionConfiguration connectionConfig = XMPPTCPConnectionConfiguration.builder()
.setXmppDomain(JidCreate.domainBareFrom("apache.camel"))
.setHostAddress(InetAddress.getLocalHost())
.setPort(Integer.parseInt(port))
.setCustomSSLContext(sslContext)
.setHostnameVerifier((hostname, session) -> true)
.build();
context.bind("customConnectionConfig", connectionConfig);
}
示例7: initPrivateConnection
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; //导入依赖的package包/类
private void initPrivateConnection() {
long currentUserId = CurrentUser.getInstance().getCurrentUserId();
String currentUserPassword = CurrentUser.getInstance().getCurrentPassword();
String userName = currentUserId + "-" + ApiConstants.APP_ID;
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setUsernameAndPassword(userName, currentUserPassword);
configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
configBuilder.setServiceName(ApiConstants.CHAT_END_POINT);
configBuilder.setHost(ApiConstants.CHAT_END_POINT);
configBuilder.setDebuggerEnabled(true);
privateChatConnection = new XMPPTCPConnection(configBuilder.build());
privateChatConnection.addConnectionListener(this);
ReconnectionManager manager = ReconnectionManager.getInstanceFor(privateChatConnection);
manager.enableAutomaticReconnection();
manager.setReconnectionPolicy(ReconnectionManager.ReconnectionPolicy.FIXED_DELAY);
manager.setFixedDelay(15);
ProviderManager.addExtensionProvider(Displayed.ELEMENT, Displayed.NAMESPACE, new Displayed.Provider());
DisplayedManager.getInstanceFor(privateChatConnection).addDisplayedListener(
(fromJid, toJid, receiptId, receipt) -> {
messageService.get().processDisplayed(fromJid, toJid, receiptId, receipt);
});
ProviderManager.addExtensionProvider(Received.ELEMENT, Received.NAMESPACE, new Received.Provider());
ReceivedManager.getInstanceFor(privateChatConnection).addReceivedListener(
(fromJid, toJid, receiptId, receipt) -> {
messageService.get().processReceived(fromJid, toJid, receiptId, receipt);
});
}
示例8: createManagedConnection
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; //导入依赖的package包/类
public XMPPTCPConnection createManagedConnection(XMPPTCPConnectionConfiguration configuration) {
XMPPTCPConnection connection = new XMPPTCPConnection(configuration);
ManagedXmppConnection managedConnection = new ManagedXmppConnection(connection);
for (NewManagedConnectionListener newManagedConnectionListener : mNewConnectionListeners) {
newManagedConnectionListener.newConnection(managedConnection);
}
synchronized (managedConnection) {
mManagedConnections.put(connection, managedConnection);
}
return connection;
}
示例9: configSSLContext
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; //导入依赖的package包/类
private void configSSLContext(XMPPTCPConnectionConfiguration.Builder builder, KeyStore keyStore) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
TrustManagerFactory trustManagerFactory = TrustManagerFactory
.getInstance(KeyManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagerFactory.getTrustManagers(), new SecureRandom());
builder.setCustomSSLContext(sslContext);
}
示例10: buildConfiguration
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; //导入依赖的package包/类
private XMPPTCPConnectionConfiguration buildConfiguration() throws XmppStringprepException {
XMPPTCPConnectionConfiguration.Builder builder =
XMPPTCPConnectionConfiguration.builder();
builder.setHost(HOST1);
builder.setPort(PORT);
builder.setCompressionEnabled(false);
builder.setDebuggerEnabled(true);
builder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
builder.setSendPresence(true);
if (Build.VERSION.SDK_INT >= 14) {
builder.setKeystoreType("AndroidCAStore");
// config.setTruststorePassword(null);
builder.setKeystorePath(null);
} else {
builder.setKeystoreType("BKS");
String str = System.getProperty("javax.net.ssl.trustStore");
if (str == null) {
str = System.getProperty("java.home") + File.separator + "etc" + File.separator + "security"
+ File.separator + "cacerts.bks";
}
builder.setKeystorePath(str);
}
DomainBareJid serviceName = JidCreate.domainBareFrom(HOST);
builder.setServiceName(serviceName);
return builder.build();
}
示例11: getConnection
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; //导入依赖的package包/类
public static AbstractXMPPConnection getConnection() {
if ( XMPPConnectionManager.isConfigured == false ) {
Log.w(LOGTAG, "Instating unconfigured connection" );
return null;
}
if ( XMPPConnectionManager.isConnected == false ) {
// Send the configuration
// TODO: Yes I know, this is restrictive, DNS must be working
XMPPTCPConnectionConfiguration.Builder configBuilder =
XMPPTCPConnectionConfiguration.builder();
configBuilder.setUsernameAndPassword(
XMPPConnectionManager.xmppUserName,
XMPPConnectionManager.xmppPassword);
configBuilder.setServiceName( XMPPConnectionManager.xmppUserDomain );
configBuilder.setResource( "FlowsManager" );
XMPPConnectionManager.connection = new XMPPTCPConnection(configBuilder.build());
try {
// Create a connection to the XMPP server.
XMPPConnectionManager.connection.connect();
// Log into the server
XMPPConnectionManager.connection.login();
} catch (Exception ex) {
Log.w(LOGTAG, "XMPP Connection error " + ex);
return null ;
}
XMPPConnectionManager.isConnected = true ;
}
return XMPPConnectionManager.connection ;
}
示例12: createConnection
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; //导入依赖的package包/类
private void createConnection() {
Logger.debug(TAG, "creating new connection to " + mAccount.getHost() + ":" + mAccount.getPort());
XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder()
.setServiceName(mAccount.getServiceName())
.setResource(mAccount.getResourceName())
.setHost(mAccount.getHost())
.setPort(mAccount.getPort())
.setUsernameAndPassword(mAccount.getXmppJid(), mAccount.getPassword())
.setConnectTimeout(XmppService.CONNECT_TIMEOUT);
if (XmppService.CUSTOM_SSL_CONTEXT != null) {
Logger.debug(TAG, "setting custom SSL context");
builder.setCustomSSLContext(XmppService.CUSTOM_SSL_CONTEXT);
}
if (XmppService.CUSTOM_HOSTNAME_VERIFIER != null) {
Logger.debug(TAG, "setting custom hostname verifier");
builder.setHostnameVerifier(XmppService.CUSTOM_HOSTNAME_VERIFIER);
}
mConnection = new XMPPTCPConnection(builder.build());
mConnection.setUseStreamManagement(XmppService.USE_STREAM_MANAGEMENT);
mConnection.setUseStreamManagementResumption(XmppService.USE_STREAM_MANAGEMENT);
mConnection.setPreferredResumptionTime(XmppService.STREAM_MANAGEMENT_RESUMPTION_TIME);
mConnection.addConnectionListener(this);
}
示例13: setup
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; //导入依赖的package包/类
public void setup() {
this.configBuilder = XMPPTCPConnectionConfiguration.builder();
this.configBuilder.setUsernameAndPassword(XMPPConnectionHandler.username, XMPPConnectionHandler.password);
this.configBuilder.setResource(XMPPConnectionHandler.resource);
this.configBuilder.setServiceName(XMPPConnectionHandler.service);
this.configBuilder.setHost(XMPPConnectionHandler.host);
this.configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
this.connection = new XMPPTCPConnection(this.configBuilder.build());
}
示例14: XMPPTCPConnection
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; //导入依赖的package包/类
/**
* Creates a new XMPP connection over TCP (optionally using proxies).
* <p>
* Note that XMPPTCPConnection constructors do not establish a connection to the server
* and you must call {@link #connect()}.
* </p>
*
* @param config the connection configuration.
*/
public XMPPTCPConnection(XMPPTCPConnectionConfiguration config) {
super(config);
this.config = config;
addConnectionListener(new AbstractConnectionListener() {
@Override
public void connectionClosedOnError(Exception e) {
if (e instanceof XMPPException.StreamErrorException || e instanceof StreamManagementException) {
dropSmState();
}
}
});
}
示例15: login
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; //导入依赖的package包/类
private XMPPConnection login(final Configuration config) throws IOException, XMPPException, SmackException, KeyManagementException, NoSuchAlgorithmException {
final String serviceName = isNullOrEmpty(config.getString(CK_SERVICE_NAME))
? config.getString(CK_HOSTNAME) : config.getString(CK_SERVICE_NAME);
final XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder()
.setHost(config.getString(CK_HOSTNAME))
.setPort(config.getInt(CK_PORT))
.setServiceName(serviceName)
.setSendPresence(false);
if (config.getBoolean(CK_ACCEPT_SELFSIGNED)) {
TLSUtils.acceptAllCertificates(configBuilder);
}
final boolean requireSecurity = config.getBoolean(CK_REQUIRE_SECURITY);
configBuilder.setSecurityMode(requireSecurity ?
ConnectionConfiguration.SecurityMode.required : ConnectionConfiguration.SecurityMode.ifpossible);
final XMPPTCPConnectionConfiguration connectionConfiguration = configBuilder.build();
if (LOG.isDebugEnabled()) {
LOG.debug("Supported SASL authentications: {}", SASLAuthentication.getRegisterdSASLMechanisms());
LOG.debug("require_security: {}", requireSecurity);
LOG.debug("Security mode: {}", connectionConfiguration.getSecurityMode());
LOG.debug("Socket factory: {}", connectionConfiguration.getSocketFactory());
LOG.debug("Keystore: {}", connectionConfiguration.getKeystorePath());
LOG.debug("Keystore type: {}", connectionConfiguration.getKeystoreType());
}
final XMPPTCPConnection xmppConnection = new XMPPTCPConnection(connectionConfiguration);
xmppConnection.connect();
xmppConnection.login(config.getString(CK_USERNAME), config.getString(CK_PASSWORD));
return xmppConnection;
}