本文整理汇总了Java中org.jivesoftware.smack.XMPPConnection类的典型用法代码示例。如果您正苦于以下问题:Java XMPPConnection类的具体用法?Java XMPPConnection怎么用?Java XMPPConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XMPPConnection类属于org.jivesoftware.smack包,在下文中一共展示了XMPPConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: displayGUI
import org.jivesoftware.smack.XMPPConnection; //导入依赖的package包/类
public void displayGUI() throws Throwable {
setSearchPaths();
if (!GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) {
JMeterXMPPConnection te = new JMeterXMPPConnection();
te.setFromMode(XMPPConnection.FromMode.OMITTED.toString());
JMeterXMPPConnectionGui gui = new JMeterXMPPConnectionGui();
gui.configure(te);
JDialog dialog = new JDialog();
dialog.add(gui);
dialog.setPreferredSize(new Dimension(800, 600));
dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
dialog.pack();
dialog.setVisible(true);
while (dialog.isVisible()) {
Thread.sleep(1000);
}
}
}
示例2: perform
import org.jivesoftware.smack.XMPPConnection; //导入依赖的package包/类
@Test
public void perform() throws Exception {
SendMessage action = new SendMessage();
XMPPConnectionMock connection = new XMPPConnectionMock();
action.connected(connection);
Message resp = new Message();
resp.setFrom("[email protected]");
resp.setBody(SendMessage.RESPONSE_MARKER);
action.processPacket(resp);
JMeterXMPPSampler sampler = new JMeterXMPPSamplerMock();
sampler.getXMPPConnection().setFromMode(XMPPConnection.FromMode.USER);
sampler.setProperty(SendMessage.RECIPIENT, "[email protected]");
sampler.setProperty(SendMessage.WAIT_RESPONSE, true);
SampleResult res = new SampleResult();
action.perform(sampler, res);
Assert.assertTrue(res.getResponseDataAsString().contains(SendMessage.RESPONSE_MARKER));
Assert.assertTrue(res.getSamplerData().contains("from"));
}
示例3: searchUsers
import org.jivesoftware.smack.XMPPConnection; //导入依赖的package包/类
/**
* 查询用户
* @param xmppConnection
* @param userName
* @return
* @throws XMPPException
*/
public static List<HashMap<String, String>> searchUsers(XMPPConnection xmppConnection, String userName) {
List<HashMap<String, String>> results = new ArrayList<HashMap<String, String>>();
try {
UserSearchManager usm = new UserSearchManager(xmppConnection);
Form searchForm = usm.getSearchForm(xmppConnection.getServiceName());
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("userAccount", true);
answerForm.setAnswer("userPhote", userName);
ReportedData data = usm.getSearchResults(answerForm, "search" + xmppConnection.getServiceName());
Iterator<ReportedData.Row> it = data.getRows();
while (it.hasNext()) {
HashMap<String, String> user = new HashMap<String, String>();
ReportedData.Row row = it.next();
user.put("userAccount", row.getValues("userAccount").next().toString());
user.put("userPhote", row.getValues("userPhote").next().toString());
results.add(user);
}
} catch (XMPPException e) {
Log.e("searchUsers", e.getMessage());
e.printStackTrace();
}
return results;
}
示例4: removeUser
import org.jivesoftware.smack.XMPPConnection; //导入依赖的package包/类
/**
* 删除好友
* @param xmppConnection
* @param userName
* @return
*/
public static boolean removeUser(XMPPConnection xmppConnection, String userName) {
try {
RosterEntry entry = null;
if (userName.contains("@")) {
entry = xmppConnection.getRoster().getEntry(
userName + "@" + xmppConnection.getServiceName());
} else {
entry = xmppConnection.getRoster().getEntry(
userName + "@" + xmppConnection.getServiceName());
}
if (entry == null) {
entry = xmppConnection.getRoster().getEntry(userName);
}
xmppConnection.getRoster().removeEntry(entry);
return true;
} catch (Exception e) {
Log.e("removeUser", e.getMessage());
e.printStackTrace();
return false;
}
}
示例5: login
import org.jivesoftware.smack.XMPPConnection; //导入依赖的package包/类
/**
* 登录
* @param userName
* @param password
* @return
*/
public static XMPPConnection login(String userName,String password){
XMPPConnection xmppConnection = createXMPPConnection();
if (xmppConnection != null) {
try {
if (!xmppConnection.isConnected()) {
xmppConnection.connect();
}
xmppConnection.login(userName, password);
} catch (XMPPException e) {
e.printStackTrace();
xmppConnection = null;
}
}
return xmppConnection;
}
示例6: removeUser
import org.jivesoftware.smack.XMPPConnection; //导入依赖的package包/类
/**
* 删除好友
* @param xmppConnection
* @param userName
* @return
*/
public static boolean removeUser(XMPPConnection xmppConnection,String userName) {
try {
RosterEntry entry = null;
if (userName.contains("@")){
entry = xmppConnection.getRoster().getEntry(
userName + "@" + xmppConnection.getServiceName());
}else{
entry = xmppConnection.getRoster().getEntry(
userName + "@" + xmppConnection.getServiceName());
}
if (entry == null){
entry = xmppConnection.getRoster().getEntry(userName);
}
xmppConnection.getRoster().removeEntry(entry);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例7: searchUsers
import org.jivesoftware.smack.XMPPConnection; //导入依赖的package包/类
/**
* 查询用户
* @param xmppConnection
* @param userName
* @return
* @throws XMPPException
*/
public static List<HashMap<String, String>> searchUsers(XMPPConnection xmppConnection,String userName) {
List<HashMap<String, String>> results = new ArrayList<HashMap<String, String>>();
try {
UserSearchManager usm = new UserSearchManager(xmppConnection);
Form searchForm = usm.getSearchForm(xmppConnection.getServiceName());
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("userAccount", true);
answerForm.setAnswer("userPhote", userName);
ReportedData data = usm.getSearchResults(answerForm, "search" + xmppConnection.getServiceName());
Iterator<ReportedData.Row> it = data.getRows();
while (it.hasNext()) {
HashMap<String, String> user = new HashMap<String, String>();
ReportedData.Row row = it.next();
user.put("userAccount", row.getValues("userAccount").next().toString());
user.put("userPhote", row.getValues("userPhote").next().toString());
results.add(user);
}
} catch (XMPPException e) {
e.printStackTrace();
}
return results;
}
示例8: joinMultiUserChat
import org.jivesoftware.smack.XMPPConnection; //导入依赖的package包/类
/**
* 加入聊天室
* @param xmppConnection
* @param roomName
* @param password
* @return
*/
public static MultiUserChat joinMultiUserChat(XMPPConnection xmppConnection,String roomName,String password,PacketListener packetListener){
try {
// 使用XMPPConnection创建一个MultiUserChat窗口
MultiUserChat muc = new MultiUserChat(xmppConnection, roomName+ "@conference." + xmppConnection.getServiceName());
// 聊天室服务将会决定要接受的历史记录数量
DiscussionHistory history = new DiscussionHistory();
history.setMaxChars(0);
// 用户加入聊天室
muc.join(xmppConnection.getUser(), password, history, SmackConfiguration.getPacketReplyTimeout());
if(packetListener!=null){
muc.addMessageListener(packetListener);
}
return muc;
} catch (XMPPException e) {
e.printStackTrace();
return null;
}
}
示例9: testRegist
import org.jivesoftware.smack.XMPPConnection; //导入依赖的package包/类
@Test
public void testRegist() {
XMPPConnection xmppConnection=providerConnection();
Map<String, String> attributes=new HashMap<String,String>(){
{
put("name", "Tom");
put("first ", "Cruise");
put("last ", "Tom");
put("email ", "[email protected]");
put("city","Chengdu");
put("text ", "test");
}
};
assertTrue(XMPPUtil.regist(xmppConnection, "Tom0425", "123",attributes));
XMPPUtil.relaseXMPPConnection(xmppConnection);
}
示例10: createXMPPConnection
import org.jivesoftware.smack.XMPPConnection; //导入依赖的package包/类
/**
* 工厂模式获取连接对象 还没有连接服务器
* @param connectionTimeOut 连接超时的时间
* @param reconnectionAllowed 是否准许重连接
* @param isPresence 是否在线
* @param debugEnable 是否调试
* @param securityMode 安全模式
* @param connectionListener 连接监听器
* @return
*/
public static XMPPConnection createXMPPConnection(int connectionTimeOut, boolean reconnectionAllowed, boolean isPresence, boolean debugEnable,
ConnectionConfiguration.SecurityMode securityMode, ConnectionListener connectionListener) {
//设置是否开启DEBUG模式
XMPPConnection.DEBUG_ENABLED = debugEnable;
//设置连接地址、端口
ConnectionConfiguration configuration = new ConnectionConfiguration(SERVERADDRESS, PORT);
//设置服务器名称
configuration.setServiceName(SERVERNAME);
//设置是否需要SAS验证
configuration.setSASLAuthenticationEnabled(false);
//设置安全类型
configuration.setSecurityMode(securityMode);
//设置用户状态
configuration.setSendPresence(isPresence);
//设置是否准许重连接
configuration.setReconnectionAllowed(reconnectionAllowed);
//实例化连接对象
XMPPConnection xmppConnection = new XMPPConnection(configuration);
//添加连接监听器
if (connectionListener != null) {
xmppConnection.addConnectionListener(connectionListener);
}
return xmppConnection;
}
示例11: regist
import org.jivesoftware.smack.XMPPConnection; //导入依赖的package包/类
/**
* 注册用户
* @param xmppConnection
* @param userName
* @param password
* @param attributes
* @return
*/
public static boolean regist(XMPPConnection xmppConnection, String userName, String password, Map<String, String> attributes) {
AccountManager accountManager = xmppConnection.getAccountManager();
try {
if (attributes != null) {
accountManager.createAccount(userName, password, attributes);
} else {
accountManager.createAccount(userName, password);
}
return true;
} catch (XMPPException e) {
Log.e("regist", e.getMessage());
e.printStackTrace();
return false;
}
}
示例12: getFromMode
import org.jivesoftware.smack.XMPPConnection; //导入依赖的package包/类
public XMPPConnection.FromMode getFromMode() {
String str = getPropertyAsString(FROM_MODE, XMPPConnection.FromMode.USER.toString());
if (str.equals(XMPPConnection.FromMode.USER.toString())) {
return XMPPConnection.FromMode.USER;
} else if (str.equals(XMPPConnection.FromMode.UNCHANGED.toString())) {
return XMPPConnection.FromMode.UNCHANGED;
} else if (str.equals(XMPPConnection.FromMode.OMITTED.toString())) {
return XMPPConnection.FromMode.OMITTED;
} else {
throw new IllegalArgumentException("Unhandled value for fromMode: " + str);
}
}
示例13: ReadReceiptManager
import org.jivesoftware.smack.XMPPConnection; //导入依赖的package包/类
private ReadReceiptManager(XMPPConnection connection) {
super(connection);
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
sdm.addFeature(ReadReceipt.NAMESPACE);
connection.addAsyncStanzaListener(packet -> {
ReadReceipt receipt = ReadReceipt.from((Message) packet);
for (ReceiptReceivedListener listener : receiptReceivedListeners) {
listener.onReceiptReceived(packet.getFrom(), packet.getTo(), receipt.getId(), packet);
}
}, MESSAGES_WITH_READ_RECEIPT);
}
示例14: initFields
import org.jivesoftware.smack.XMPPConnection; //导入依赖的package包/类
private void initFields() {
address.setText("localhost");
port.setText("5222");
serviceName.setText("localhost");
timeout.setText("1000");
connectionClass.setSelectedItem(JMeterXMPPConnectionBase.Type.TCP);
fromMode.setSelectedItem(XMPPConnection.FromMode.USER);
}
示例15: perform
import org.jivesoftware.smack.XMPPConnection; //导入依赖的package包/类
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
XMPPConnection conn = sampler.getXMPPConnection();
String loginStr = sampler.getPropertyAsString(LOGIN);
String pwdStr = sampler.getPropertyAsString(PASSWORD);
String resStr = sampler.getPropertyAsString(RESOURCE);
res.setSamplerData("Username: " + loginStr + "\nPassword: " + pwdStr + "\nResource: " + resStr);
AbstractXMPPConnection absConn = (AbstractXMPPConnection) conn;
if (loginStr.isEmpty()) {
absConn.loginAnonymously();
} else {
absConn.login(loginStr, pwdStr, resStr);
}
return res;
}