本文整理匯總了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;
}