本文整理汇总了Java中org.xmpp.packet.IQ.Type.get方法的典型用法代码示例。如果您正苦于以下问题:Java Type.get方法的具体用法?Java Type.get怎么用?Java Type.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmpp.packet.IQ.Type
的用法示例。
在下文中一共展示了Type.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleDiscoInfo
import org.xmpp.packet.IQ.Type; //导入方法依赖的package包/类
/**
* Creates a response specific to the search plugin to Disco#Info requests.
*
* @param iq
* The IQ stanza that contains the request.
* @return An IQ stanza, formulated as an answer to the received request.
*/
private static IQ handleDiscoInfo(IQ iq) {
if (iq == null) {
throw new IllegalArgumentException("Argument 'iq' cannot be null.");
}
if (!iq.getChildElement().getNamespaceURI().equals(IQDiscoInfoHandler.NAMESPACE_DISCO_INFO) || iq.getType() != Type.get) {
throw new IllegalArgumentException("This is not a valid disco#info request.");
}
final IQ replyPacket = IQ.createResultIQ(iq);
final Element responseElement = replyPacket.setChildElement("query", IQDiscoInfoHandler.NAMESPACE_DISCO_INFO);
responseElement.addElement("identity").addAttribute("category", "directory").addAttribute("type", "user")
.addAttribute("name", "User Search");
responseElement.addElement("feature").addAttribute("var", NAMESPACE_JABBER_IQ_SEARCH);
responseElement.addElement("feature").addAttribute("var", IQDiscoInfoHandler.NAMESPACE_DISCO_INFO);
responseElement.addElement("feature").addAttribute("var", ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT);
return replyPacket;
}
示例2: handleDiscoInfo
import org.xmpp.packet.IQ.Type; //导入方法依赖的package包/类
/**
* Creates a response specific to the search plugin to Disco#Info requests.
*
* @param iq
* The IQ stanza that contains the request.
* @return An IQ stanza, formulated as an answer to the received request.
*/
private static IQ handleDiscoInfo(IQ iq) {
if (iq == null) {
throw new IllegalArgumentException("Argument 'iq' cannot be null.");
}
if (!iq.getChildElement().getNamespaceURI().equals(IQDiscoInfoHandler.NAMESPACE_DISCO_INFO) || iq.getType() != Type.get) {
throw new IllegalArgumentException("This is not a valid disco#info request.");
}
final IQ replyPacket = IQ.createResultIQ(iq);
final Element responseElement = replyPacket.setChildElement("query", IQDiscoInfoHandler.NAMESPACE_DISCO_INFO);
responseElement.addElement("identity").addAttribute("category", "directory").addAttribute("type", "user")
.addAttribute("name", "User Search");
responseElement.addElement("feature").addAttribute("var", NAMESPACE_JABBER_IQ_SEARCH);
responseElement.addElement("feature").addAttribute("var", IQDiscoInfoHandler.NAMESPACE_DISCO_INFO);
responseElement.addElement("feature").addAttribute("var", ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT);
return replyPacket;
}
示例3: consumesOnDifferentThreadTest
import org.xmpp.packet.IQ.Type; //导入方法依赖的package包/类
/**
* The actual work being done by the component (the consumer) should be done
* by a different thread than the thread that feeds the input (the
* producer).
*
* This test uses an AbstractComponent implementation that reports the
* thread name that was used during processing. This name is compared with
* the name of the thread that feeds the component the request packet (the
* producer) to verify that the producer and consumer threads are indeed
* different.
*/
@Test
public void consumesOnDifferentThreadTest() throws Exception {
// setup
final String producerThreadName = Thread.currentThread().getName();
final IQ request = new IQ(Type.get);
request.setChildElement(
SlowRespondingThreadNameComponent.ELEMENTNAME_THREADNAME,
SlowRespondingThreadNameComponent.DEBUG_NAMESPACE);
// do magic
debugComp.processPacket(request);
final IQ response = (IQ) debugComp.getSentPacket();
// verify
final Element elem = response.getChildElement();
final String consumerThreadName = elem.getText();
assertFalse(consumerThreadName.equals(producerThreadName));
}
示例4: consumesAsynchronouslyTest
import org.xmpp.packet.IQ.Type; //导入方法依赖的package包/类
/**
* The producer thread should be released as soon as it delivers work to the
* consumer, regardless of how long the consumer takes to process a packet.
*
* This test uses an AbstractComponent implementation that takes a
* significant time to process a packet. The test verifies that the producer
* thread finishes work before the consumer threads finish. This verifies
* that the workload has been properly offloaded by the producer thread.
*/
@Test
public void consumesAsynchronouslyTest() throws Exception {
// setup
final IQ request = new IQ(Type.get);
request.setChildElement(
SlowRespondingThreadNameComponent.ELEMENTNAME_SLOWRESPONSE,
SlowRespondingThreadNameComponent.DEBUG_NAMESPACE);
// do magic
final long start = System.currentTimeMillis();
debugComp.processPacket(request);
final long end = System.currentTimeMillis();
// verify
final long elapsed = end - start;
assertTrue(elapsed < 4000);
}
示例5: testXmppPing
import org.xmpp.packet.IQ.Type; //导入方法依赖的package包/类
/**
* This test verifies that the abstract component responds to XMPP Ping
* requests correctly.
*
* @see <a
* href="http://www.igniterealtime.org/issues/browse/TINDER-20">Tinder bugtracker: TINDER-20</a>
*/
@Test
public void testXmppPing() throws Exception {
// setup
final DummyAbstractComponent component = new DummyAbstractComponent();
component.initialize(new JID("sub.domain"), null);
final IQ pingRequest = new IQ(Type.get);
pingRequest.setChildElement("ping",
AbstractComponent.NAMESPACE_XMPP_PING);
pingRequest.setFrom("from.address");
pingRequest.setTo(component.jid);
// do magic
component.start();
component.processPacket(pingRequest);
// verify
final IQ result = (IQ) component.getSentPacket();
assertNotNull(result);
assertEquals(Type.result, result.getType());
assertEquals(pingRequest.getID(), result.getID());
assertEquals(pingRequest.getFrom(), result.getTo());
assertEquals(pingRequest.getTo(), result.getFrom());
}
示例6: testIsRestartable
import org.xmpp.packet.IQ.Type; //导入方法依赖的package包/类
/**
* Every component should be functional after it has been shutdown and
* restarted.
*
* This test creates a component, starts, stops and restarts it, and
* verifies that it then responds to XMPP Ping requests.
*
* @see <a
* href="http://www.igniterealtime.org/issues/browse/TINDER-31">Tinder bugtracker: TINDER-31</a>
*/
@Test
public void testIsRestartable() throws Exception {
// setup
final DummyAbstractComponent component = new DummyAbstractComponent();
component.initialize(new JID("sub.domain"), null);
final IQ pingRequest = new IQ(Type.get);
pingRequest.setChildElement("ping",
AbstractComponent.NAMESPACE_XMPP_PING);
pingRequest.setFrom("from.address");
pingRequest.setTo(component.jid);
// do magic
component.start();
component.shutdown();
component.start();
component.processPacket(pingRequest);
// verify
final IQ result = (IQ) component.getSentPacket();
assertNotNull(result);
assertEquals(Type.result, result.getType());
assertEquals(pingRequest.getID(), result.getID());
}
示例7: testExceptionResponse
import org.xmpp.packet.IQ.Type; //导入方法依赖的package包/类
/**
* If an exception is thrown during the processing of an IQ request,
* AbstractComponent should still return a response to the request.
*
* This test uses a AbstractComponent that throws an exception every time it
* processes an IQ get request.
*/
@Test
public void testExceptionResponse() throws Exception {
// setup
final DummyAbstractComponent component = new ThrowExceptionOnGetComponent();
final IQ request = new IQ(Type.get);
request.setChildElement("junit", "test");
request.setFrom("from.address");
request.setTo("to.address");
// do magic
component.start();
component.processPacket(request);
// verify
final IQ result = (IQ) component.getSentPacket();
assertNotNull(result);
assertTrue(result.isResponse());
assertEquals(request.getID(), result.getID());
assertEquals(request.getFrom(), result.getTo());
assertEquals(request.getTo(), result.getFrom());
}
示例8: testLastActivity
import org.xmpp.packet.IQ.Type; //导入方法依赖的package包/类
/**
* This test verifies that the abstract component responds to XMPP Last Activity
* requests correctly.
*
* @see <a
* href="http://www.igniterealtime.org/issues/browse/TINDER-38">Tinder bugtracker: TINDER-38</a>
*/
@Test
public void testLastActivity() throws Exception {
// setup
final DummyAbstractComponent component = new DummyAbstractComponent();
component.initialize(new JID("sub.domain"), null);
final IQ request = new IQ(Type.get);
request.setChildElement("ping",
AbstractComponent.NAMESPACE_LAST_ACTIVITY);
request.setFrom("from.address");
request.setTo(component.jid);
final int wait = 2;
// do magic
component.start();
Thread.sleep(wait*1000);
component.processPacket(request);
// verify
final IQ result = (IQ) component.getSentPacket();
assertNotNull(result);
assertEquals(Type.result, result.getType());
assertEquals(String.valueOf(wait), result.getChildElement().attributeValue("seconds"));
}
示例9: testEntityTime
import org.xmpp.packet.IQ.Type; //导入方法依赖的package包/类
/**
* This test verifies that the abstract component responds to XMPP Entity Time requests.
*/
@Test
public void testEntityTime() throws Exception {
// setup
final DummyAbstractComponent component = new DummyAbstractComponent();
component.initialize(new JID("sub.domain"), null);
final IQ request = new IQ(Type.get);
request.setChildElement("ping",
AbstractComponent.NAMESPACE_ENTITY_TIME);
request.setFrom("from.address");
request.setTo(component.jid);
// do magic
component.start();
component.processPacket(request);
// verify
final IQ result = (IQ) component.getSentPacket();
assertNotNull(result);
assertEquals(Type.result, result.getType());
// TODO although this test verifies that a result is produced, it also needs to verify the correctness of the content of the result.
}
示例10: testSimpleResponse
import org.xmpp.packet.IQ.Type; //导入方法依赖的package包/类
/**
* A normal response is expected if an IQ request is sent that is processed
* by the component.
*/
@Test
public void testSimpleResponse() throws Exception {
// setup
final DummyAbstractComponent component = new DummyAbstractComponent();
final IQ pingRequest = new IQ(Type.get);
pingRequest.setChildElement("ping",
AbstractComponent.NAMESPACE_XMPP_PING);
pingRequest.setFrom("from.address");
pingRequest.setTo("to.address");
// do magic
component.start();
component.processPacket(pingRequest);
// verify
final IQ result = (IQ) component.getSentPacket();
assertNotNull(result);
assertTrue(result.isResponse());
assertEquals(pingRequest.getID(), result.getID());
assertEquals(pingRequest.getFrom(), result.getTo());
assertEquals(pingRequest.getTo(), result.getFrom());
}
示例11: sessionIdle
import org.xmpp.packet.IQ.Type; //导入方法依赖的package包/类
/**
* In addition to the functionality provided by the parent class, this
* method will send XMPP ping requests to the remote entity on every first
* invocation of this method (which will occur after a period of half the
* allowed connection idle time has passed, without any IO).
*
* XMPP entities must respond with either an IQ result or an IQ error
* (feature-unavailable) stanza upon receiving the XMPP ping stanza. Both
* responses will be received by Openfire and will cause the connection idle
* count to be reset.
*
* Entities that do not respond to the IQ Ping stanzas can be considered
* dead, and their connection will be closed by the parent class
* implementation on the second invocation of this method.
*
* Note that whitespace pings that are sent by XMPP entities will also cause
* the connection idle count to be reset.
*
* @see ConnectionHandler#sessionIdle(IoSession, IdleStatus)
*/
@Override
public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
super.sessionIdle(session, status);
final boolean doPing = JiveGlobals.getBooleanProperty(ConnectionSettings.Client.KEEP_ALIVE_PING, true);
if (doPing && session.getIdleCount(status) == 1) {
final ClientStanzaHandler handler = (ClientStanzaHandler) session.getAttribute(HANDLER);
final JID entity = handler.getAddress();
if (entity != null) {
// Ping the connection to see if it is alive.
final IQ pingRequest = new IQ(Type.get);
pingRequest.setChildElement("ping",
IQPingHandler.NAMESPACE);
pingRequest.setFrom( XMPPServer.getInstance().getServerInfo().getXMPPDomain() );
pingRequest.setTo(entity);
// Get the connection for this session
final Connection connection = (Connection) session.getAttribute(CONNECTION);
if (Log.isDebugEnabled()) {
Log.debug("ConnectionHandler: Pinging connection that has been idle: " + connection);
}
connection.deliver(pingRequest);
}
}
}
示例12: sessionIdle
import org.xmpp.packet.IQ.Type; //导入方法依赖的package包/类
/**
* In addition to the functionality provided by the parent class, this
* method will send XMPP ping requests to the remote entity on every first
* invocation of this method (which will occur after a period of half the
* allowed connection idle time has passed, without any IO).
*
* XMPP entities must respond with either an IQ result or an IQ error
* (feature-unavailable) stanza upon receiving the XMPP ping stanza. Both
* responses will be received by Openfire and will cause the connection idle
* count to be reset.
*
* Entities that do not respond to the IQ Ping stanzas can be considered
* dead, and their connection will be closed by the parent class
* implementation on the second invocation of this method.
*
* Note that whitespace pings that are sent by XMPP entities will also cause
* the connection idle count to be reset.
*
* @see ConnectionHandler#sessionIdle(IoSession, IdleStatus)
*/
@Override
public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
super.sessionIdle(session, status);
final boolean doPing = JiveGlobals.getBooleanProperty("xmpp.client.idle.ping", true);
if (doPing && session.getIdleCount(status) == 1) {
final ClientStanzaHandler handler = (ClientStanzaHandler) session.getAttribute(HANDLER);
final JID entity = handler.getAddress();
if (entity != null) {
// Ping the connection to see if it is alive.
final IQ pingRequest = new IQ(Type.get);
pingRequest.setChildElement("ping",
IQPingHandler.NAMESPACE);
pingRequest.setFrom(serverName);
pingRequest.setTo(entity);
// Get the connection for this session
final Connection connection = (Connection) session.getAttribute(CONNECTION);
if (Log.isDebugEnabled()) {
Log.debug("ConnectionHandler: Pinging connection that has been idle: " + connection);
}
connection.deliver(pingRequest);
}
}
}
示例13: handleDiscoInfo
import org.xmpp.packet.IQ.Type; //导入方法依赖的package包/类
/**
* Creates a response specific to the search plugin to Disco#Info requests.
*
* @param iq
* The IQ stanza that contains the request.
* @return An IQ stanza, formulated as an answer to the received request.
*/
private static IQ handleDiscoInfo(IQ iq) {
if (iq == null) {
throw new IllegalArgumentException("Argument 'iq' cannot be null.");
}
if (!iq.getChildElement().getNamespaceURI().equals(
IQDiscoInfoHandler.NAMESPACE_DISCO_INFO)
|| iq.getType() != Type.get) {
throw new IllegalArgumentException(
"This is not a valid disco#info request.");
}
final IQ replyPacket = IQ.createResultIQ(iq);
final Element responseElement = replyPacket.setChildElement("query",
IQDiscoInfoHandler.NAMESPACE_DISCO_INFO);
responseElement.addElement("identity").addAttribute("category",
"directory").addAttribute("type", "user").addAttribute("name",
"User Search");
responseElement.addElement("feature").addAttribute("var",
NAMESPACE_JABBER_IQ_SEARCH);
responseElement.addElement("feature").addAttribute("var",
IQDiscoInfoHandler.NAMESPACE_DISCO_INFO);
responseElement.addElement("feature").addAttribute("var",
ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT);
return replyPacket;
}
示例14: main
import org.xmpp.packet.IQ.Type; //导入方法依赖的package包/类
public static void main(String[] args) throws XMPPException,
ComponentException {
XMPPClient client = new XMPPClient("[email protected]", "password",
"localhost", 5222);
XEP0077 register = new XEP0077();
client.registerPlugin(register);
client.connect();
try {
register.createAccount("[email protected]", "password");
} catch (XMPPException e) {
e.printStackTrace();
}
client.login();
client.process(false);
IQ iq = new IQ(Type.get);
iq.setTo("uppercase.test.com");
iq.getElement().addElement("query", "uppercase").addElement("content")
.setText("hello world");
IQ response = (IQ) client.syncSend(iq);
System.out.println(response.toXML());
client.disconnect();
}
示例15: testDomainOnlyRemoteUser
import org.xmpp.packet.IQ.Type; //导入方法依赖的package包/类
/**
* Verifies that an IQ error is returned if a request is sent from a remote
* entity to be processed by a component that is configured to serve
* entities on the local domain only.
*
* @see <a
* href="http://www.igniterealtime.org/issues/browse/TINDER-21">Tinder bugtracker: TINDER-21</a>
*/
@Test
public void testDomainOnlyRemoteUser() throws Exception {
// setup
final DummyAbstractComponent component = new DummyAbstractComponent() {
@Override
public boolean servesLocalUsersOnly() {
return true;
}
};
component.initialize(new JID("sub.domain"), null);
final IQ pingRequest = new IQ(Type.get);
pingRequest.setChildElement("ping",
AbstractComponent.NAMESPACE_XMPP_PING);
pingRequest.setFrom("[email protected]" + component.getDomain());
pingRequest.setTo(component.jid);
// do magic
component.start();
component.processPacket(pingRequest);
// verify
final IQ response = (IQ) component.getSentPacket();
assertNotNull(response);
assertEquals(Type.error, response.getType());
assertEquals(pingRequest.getID(), response.getID());
}