當前位置: 首頁>>代碼示例>>Java>>正文


Java SmackConfiguration類代碼示例

本文整理匯總了Java中org.jivesoftware.smack.SmackConfiguration的典型用法代碼示例。如果您正苦於以下問題:Java SmackConfiguration類的具體用法?Java SmackConfiguration怎麽用?Java SmackConfiguration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SmackConfiguration類屬於org.jivesoftware.smack包,在下文中一共展示了SmackConfiguration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: XMPPConnector

import org.jivesoftware.smack.SmackConfiguration; //導入依賴的package包/類
/**
 * The constructor for the XMPP bot.
 *
 * @param host
 *            The server the bot should login.
 * @param port
 *            The hosts port.
 * @param login
 *            The bots login name.
 * @param password
 *            The bots login password.
 * @param resource
 *            The bots resource (i.e. Work or Home). Can be null.
 * @throws IllegalArgumentException
 *             Throws an {@link IllegalArgumentException} if some of the parameters are in an
 *             invalid format.
 */
public XMPPConnector(String host, String port, String login, String password, String resource)
        throws IllegalArgumentException {
    checkParameters(host, port, login, password, resource);
    int numericalPort = port == null ? DEFAULT_XMPP_PORT : Integer.parseInt(port);
    this.sender = login + "@" + host + "/" + resource;
    SmackConfiguration.DEBUG_ENABLED = Boolean.parseBoolean(ApplicationPropertyXmpp.DEBUG
            .getValue());
    ProviderManager.addExtensionProvider(AliasPacketExtension.ALIAS_ELEMENT_NAME,
            AliasPacketExtension.ALIAS_NAMESPACE, AliasPacketExtension.class);
    ConnectionConfiguration config = new ConnectionConfiguration(host, numericalPort);
    connection = new XMPPTCPConnection(config);
    connect(login, password, resource);
    sendPriorityPresence();
    if (connection.isConnected()) {
        LOG.info(ResourceBundleManager.instance().getText("xmpp.connection.started",
                Locale.ENGLISH));
        connection.addConnectionListener(new XMPPConnectionStatusLogger());
    } else {
        LOG.info("The XMPP connection wasn't established.");
    }
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:39,代碼來源:XMPPConnector.java

示例2: joinMultiUserChat

import org.jivesoftware.smack.SmackConfiguration; //導入依賴的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;
    }
}
 
開發者ID:FanHuaRan,項目名稱:SmackStudy,代碼行數:26,代碼來源:XMPPUtil.java

示例3: joinMultiUserChat

import org.jivesoftware.smack.SmackConfiguration; //導入依賴的package包/類
/**
 * 加入聊天室
 * @param xmppConnection
 * @param roomName
 * @param password
 * @param packetListener 消息監聽器
 * @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);
        // history.setSince(new Date());
        // 用戶加入聊天室
        muc.join(xmppConnection.getUser(), password, history, SmackConfiguration.getPacketReplyTimeout());
        Log.i("MultiUserChat", "會議室【"+roomName+"】加入成功........");
        if(packetListener!=null){
            muc.addMessageListener(packetListener);
        }
        return muc;
    } catch (XMPPException e) {
        Log.e("MultiUserChat", "會議室【"+roomName+"】加入失敗........");
        e.printStackTrace();
        return null;
    }
}
 
開發者ID:FanHuaRan,項目名稱:SmackStudy,代碼行數:30,代碼來源:XMPPUtil.java

示例4: testSend

import org.jivesoftware.smack.SmackConfiguration; //導入依賴的package包/類
@SuppressWarnings("nls")
@Ignore
@Test
public void testSend() throws NotificationException {
  LoggingUtilities.initialize("DEBUG");
  SmackConfiguration.setPacketReplyTimeout(5000);
  final MessageSenderBuilder builder = new MessageSenderBuilder("www.host.de", "foo", "foo");
  // builder.setServiceName("xabber.de");
  builder
      .setSASLAuthenticationEnabled(true)
      .setSendPresence(false)
      .setSecurityMode(SecurityMode.ENABLE)
      // .addSASLAuthenticationType("PLAIN");
      // .addSASLAuthenticationType("DIGEST-MD5")
      .addReceiver("[email protected]");
  builder.build().send(Message.create("Hallo Welt", null, MessageType.INFO));
}
 
開發者ID:AndreasWBartels,項目名稱:libraries,代碼行數:18,代碼來源:MessageSenderTest.java

示例5: initialize

import org.jivesoftware.smack.SmackConfiguration; //導入依賴的package包/類
@Override
public List<Exception> initialize() {
    if (SystemUtil.onAndroid()) {
        // @formatter:off
        throw new RuntimeException(
                        "You need to remove the smack-java7 dependency/jar from your build, " +
                        "as it does not run on Android. " +
                        "Use smack-android instead.");
        // @formatter:on
    }
    SmackConfiguration.setDefaultHostnameVerifier(new Java7HostnameVerifier());
    Base64.setEncoder(Java7Base64Encoder.getInstance());
    Base64UrlSafeEncoder.setEncoder(Java7Base64UrlSafeEncoder.getInstance());
    DNSUtil.setIdnaTransformer(new StringTransformer() {
        @Override
        public String transform(String string) {
            return java.net.IDN.toASCII(string);
        }
    });
    return null;
}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:22,代碼來源:Java7SmackInitializer.java

示例6: getConfigFormWithTimeout

import org.jivesoftware.smack.SmackConfiguration; //導入依賴的package包/類
@Test (expected=SmackException.class)
public void getConfigFormWithTimeout() throws XMPPException, SmackException
{
	ThreadedDummyConnection con = new ThreadedDummyConnection();
	PubSubManager mgr = new PubSubManager(con);
	DiscoverInfo info = new DiscoverInfo();
	Identity ident = new Identity("pubsub", null, "leaf");
	info.addIdentity(ident);
	con.addIQReply(info);
	
	Node node = mgr.getNode("princely_musings");
	
	SmackConfiguration.setDefaultPacketReplyTimeout(100);
	con.setTimeout();
	
	node.getNodeConfiguration();
}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:18,代碼來源:ConfigureFormTest.java

示例7: getConfigurationForm

import org.jivesoftware.smack.SmackConfiguration; //導入依賴的package包/類
/**
 * Returns the room's configuration form that the room's owner can use or <tt>null</tt> if
 * no configuration is possible. The configuration form allows to set the room's language,
 * enable logging, specify room's type, etc..
 *
 * @return the Form that contains the fields to complete together with the instrucions or
 * <tt>null</tt> if no configuration is possible.
 * @throws XMPPException if an error occurs asking the configuration form for the room.
 */
public Form getConfigurationForm() throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.GET);

    // Filter packets looking for an answer from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Request the configuration form to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
    return Form.getFormFrom(answer);
}
 
開發者ID:ice-coffee,項目名稱:EIM,代碼行數:33,代碼來源:MultiUserChat.java

示例8: sendConfigurationForm

import org.jivesoftware.smack.SmackConfiguration; //導入依賴的package包/類
/**
 * Sends the completed configuration form to the server. The room will be configured
 * with the new settings defined in the form. If the form is empty then the server
 * will create an instant room (will use default configuration).
 *
 * @param form the form with the new settings.
 * @throws XMPPException if an error occurs setting the new rooms' configuration.
 */
public void sendConfigurationForm(Form form) throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    iq.addExtension(form.getDataFormToSend());

    // Filter packets looking for an answer from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the completed configuration form to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
}
 
開發者ID:ice-coffee,項目名稱:EIM,代碼行數:32,代碼來源:MultiUserChat.java

示例9: getRegistrationForm

import org.jivesoftware.smack.SmackConfiguration; //導入依賴的package包/類
/**
 * Returns the room's registration form that an unaffiliated user, can use to become a member
 * of the room or <tt>null</tt> if no registration is possible. Some rooms may restrict the
 * privilege to register members and allow only room admins to add new members.<p>
 *
 * If the user requesting registration requirements is not allowed to register with the room
 * (e.g. because that privilege has been restricted), the room will return a "Not Allowed"
 * error to the user (error code 405).
 *
 * @return the registration Form that contains the fields to complete together with the
 * instrucions or <tt>null</tt> if no registration is possible.
 * @throws XMPPException if an error occurs asking the registration form for the room or a
 * 405 error if the user is not allowed to register with the room.
 */
public Form getRegistrationForm() throws XMPPException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.GET);
    reg.setTo(room);

    PacketFilter filter =
        new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
    return Form.getFormFrom(result);
}
 
開發者ID:ice-coffee,項目名稱:EIM,代碼行數:34,代碼來源:MultiUserChat.java

示例10: sendRegistrationForm

import org.jivesoftware.smack.SmackConfiguration; //導入依賴的package包/類
/**
 * Sends the completed registration form to the server. After the user successfully submits
 * the form, the room may queue the request for review by the room admins or may immediately
 * add the user to the member list by changing the user's affiliation from "none" to "member.<p>
 *
 * If the desired room nickname is already reserved for that room, the room will return a
 * "Conflict" error to the user (error code 409). If the room does not support registration,
 * it will return a "Service Unavailable" error to the user (error code 503).
 *
 * @param form the completed registration form.
 * @throws XMPPException if an error occurs submitting the registration form. In particular, a
 *      409 error can occur if the desired room nickname is already reserved for that room;
 *      or a 503 error can occur if the room does not support registration.
 */
public void sendRegistrationForm(Form form) throws XMPPException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(room);
    reg.addExtension(form.getDataFormToSend());

    PacketFilter filter =
        new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    }
    else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
}
 
開發者ID:ice-coffee,項目名稱:EIM,代碼行數:34,代碼來源:MultiUserChat.java

示例11: changeAffiliationByOwner

import org.jivesoftware.smack.SmackConfiguration; //導入依賴的package包/類
private void changeAffiliationByOwner(String jid, String affiliation) throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    // Set the new affiliation.
    MUCOwner.Item item = new MUCOwner.Item(affiliation);
    item.setJid(jid);
    iq.addItem(item);

    // Wait for a response packet back from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the change request to the server.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (answer == null) {
        throw new XMPPException("No response from server.");
    }
    else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
}
 
開發者ID:ice-coffee,項目名稱:EIM,代碼行數:27,代碼來源:MultiUserChat.java

示例12: getSharedGroups

import org.jivesoftware.smack.SmackConfiguration; //導入依賴的package包/類
/**
 * Returns the collection that will contain the name of the shared groups where the user
 * logged in with the specified session belongs.
 *
 * @param connection connection to use to get the user's shared groups.
 * @return collection with the shared groups' name of the logged user.
 */
public static List getSharedGroups(Connection connection) throws XMPPException {
    // Discover the shared groups of the logged user
    SharedGroupsInfo info = new SharedGroupsInfo();
    info.setType(IQ.Type.GET);

    // Create a packet collector to listen for a response.
    PacketCollector collector =
        connection.createPacketCollector(new PacketIDFilter(info.getPacketID()));

    connection.sendPacket(info);

    // Wait up to 5 seconds for a result.
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from the server.");
    }
    if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
    return ((SharedGroupsInfo) result).getGroups();
}
 
開發者ID:ice-coffee,項目名稱:EIM,代碼行數:31,代碼來源:SharedGroupManager.java

示例13: getWorkgroups

import org.jivesoftware.smack.SmackConfiguration; //導入依賴的package包/類
public static Collection<String> getWorkgroups(String serviceJID, String agentJID, Connection connection) throws XMPPException {
    AgentWorkgroups request = new AgentWorkgroups(agentJID);
    request.setTo(serviceJID);
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
    // Send the request
    connection.sendPacket(request);

    AgentWorkgroups response = (AgentWorkgroups)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return response.getWorkgroups();
}
 
開發者ID:ice-coffee,項目名稱:EIM,代碼行數:20,代碼來源:Agent.java

示例14: getName

import org.jivesoftware.smack.SmackConfiguration; //導入依賴的package包/類
/**
 * Return the agents name.
 *
 * @return - the agents name.
 */
public String getName() throws XMPPException {
    AgentInfo agentInfo = new AgentInfo();
    agentInfo.setType(IQ.Type.GET);
    agentInfo.setTo(workgroupJID);
    agentInfo.setFrom(getUser());
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(agentInfo.getPacketID()));
    // Send the request
    connection.sendPacket(agentInfo);

    AgentInfo response = (AgentInfo)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return response.getName();
}
 
開發者ID:ice-coffee,項目名稱:EIM,代碼行數:27,代碼來源:Agent.java

示例15: setName

import org.jivesoftware.smack.SmackConfiguration; //導入依賴的package包/類
/**
 * Changes the name of the agent in the server. The server may have this functionality
 * disabled for all the agents or for this agent in particular. If the agent is not
 * allowed to change his name then an exception will be thrown with a service_unavailable
 * error code.
 *
 * @param newName the new name of the agent.
 * @throws XMPPException if the agent is not allowed to change his name or no response was
 *                       obtained from the server.
 */
public void setName(String newName) throws XMPPException {
    AgentInfo agentInfo = new AgentInfo();
    agentInfo.setType(IQ.Type.SET);
    agentInfo.setTo(workgroupJID);
    agentInfo.setFrom(getUser());
    agentInfo.setName(newName);
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(agentInfo.getPacketID()));
    // Send the request
    connection.sendPacket(agentInfo);

    IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return;
}
 
開發者ID:ice-coffee,項目名稱:EIM,代碼行數:33,代碼來源:Agent.java


注:本文中的org.jivesoftware.smack.SmackConfiguration類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。