本文整理汇总了Java中org.jivesoftware.smack.packet.XMPPError类的典型用法代码示例。如果您正苦于以下问题:Java XMPPError类的具体用法?Java XMPPError怎么用?Java XMPPError使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XMPPError类属于org.jivesoftware.smack.packet包,在下文中一共展示了XMPPError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: failed
import org.jivesoftware.smack.packet.XMPPError; //导入依赖的package包/类
public static Failed failed(XmlPullParser parser) throws XmlPullParserException, IOException {
ParserUtils.assertAtStartTag(parser);
String name;
XMPPError.Condition condition = null;
outerloop:
while(true) {
int event = parser.next();
switch (event) {
case XmlPullParser.START_TAG:
name = parser.getName();
String namespace = parser.getNamespace();
if (XMPPError.NAMESPACE.equals(namespace)) {
condition = XMPPError.Condition.fromString(name);
}
break;
case XmlPullParser.END_TAG:
name = parser.getName();
if (Failed.ELEMENT.equals(name)) {
break outerloop;
}
break;
}
}
ParserUtils.assertAtEndTag(parser);
return new Failed(condition);
}
示例2: testParseFailedError
import org.jivesoftware.smack.packet.XMPPError; //导入依赖的package包/类
@Test
public void testParseFailedError() throws Exception {
XMPPError.Condition errorCondition = XMPPError.Condition.unexpected_request;
String failedStanza = XMLBuilder.create("failed")
.a("xmlns", "urn:xmpp:sm:3")
.element(errorCondition.toString(), XMPPError.NAMESPACE)
.asString(outputProperties);
System.err.println(failedStanza);
StreamManagement.Failed failedPacket = ParseStreamManagement.failed(
PacketParserUtils.getParserFor(failedStanza));
assertThat(failedPacket, is(notNullValue()));
assertTrue(failedPacket.getXMPPErrorCondition() == errorCondition);
}
示例3: test404
import org.jivesoftware.smack.packet.XMPPError; //导入依赖的package包/类
/**
* Check the parser with an xml with the 404 error.
*/
public void test404() {
// Make the XML to test
String xml = "<error code='404' type='cancel'>" +
"<item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
"</error></iq>";
try {
// Create the xml parser
XmlPullParser parser = getParserFromXML(xml);
// Create a packet from the xml
XMPPError packet = parseError(parser);
assertNotNull(packet);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
示例4: testCancel
import org.jivesoftware.smack.packet.XMPPError; //导入依赖的package包/类
/**
* Check the parser with an xml with the 404 error.
*/
public void testCancel() {
// Make the XML to test
String xml = "<error type='cancel'>" +
"<conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
"</error>";
try {
// Create the xml parser
XmlPullParser parser = getParserFromXML(xml);
// Create a packet from the xml
XMPPError error = parseError(parser);
assertNotNull(error);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
示例5: testMessageAndApplicationDefinedError
import org.jivesoftware.smack.packet.XMPPError; //导入依赖的package包/类
public void testMessageAndApplicationDefinedError() {
String xml = "<error type='modify' code='404'>" +
"<undefined-condition xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
"<text xml:lang='en' xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>" +
"Some special application diagnostic information..." +
"</text>" +
"<special-application-condition xmlns='application-ns'/>" +
"</error>";
try {
// Create the xml parser
XmlPullParser parser = getParserFromXML(xml);
// Create a packet from the xml
XMPPError error = parseError(parser);
String sendingXML = error.toXML();
assertNotNull(error);
assertNotNull(sendingXML);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
示例6: testCancelWithMessage
import org.jivesoftware.smack.packet.XMPPError; //导入依赖的package包/类
/**
* Check the parser with an xml with the 404 error.
*/
public void testCancelWithMessage() {
// Make the XML to test
String xml = "<error type='cancel'>" +
"<conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
"<text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas' xml:lang='langcode'>" +
"Some special application diagnostic information!" +
"</text>" +
"</error>";
try {
// Create the xml parser
XmlPullParser parser = getParserFromXML(xml);
// Create a packet from the xml
XMPPError error = parseError(parser);
assertNotNull(error);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
示例7: testCancelWithMessageAndApplicationError
import org.jivesoftware.smack.packet.XMPPError; //导入依赖的package包/类
/**
* Check the parser with an xml with the 404 error.
*/
public void testCancelWithMessageAndApplicationError() {
// Make the XML to test
String xml = "<error type='cancel' code='10'>" +
"<conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
"<text xml:lang='en' xmlns='urn:ietf:params:xml:ns:xmpp-streams'>" +
"Some special application diagnostic information!" +
"</text>" +
"<application-defined-error xmlns='application-ns'/>" +
"</error>";
try {
// Create the xml parser
XmlPullParser parser = getParserFromXML(xml);
// Create a packet from the xml
XMPPError error = parseError(parser);
assertNotNull(error);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
示例8: EntityTimeManager
import org.jivesoftware.smack.packet.XMPPError; //导入依赖的package包/类
private EntityTimeManager(XMPPConnection connection) {
super(connection);
if (autoEnable)
enable();
connection.registerIQRequestHandler(new AbstractIqRequestHandler(Time.ELEMENT, Time.NAMESPACE, Type.get,
Mode.async) {
@Override
public IQ handleIQRequest(IQ iqRequest) {
if (enabled) {
return Time.createResponse(iqRequest);
}
else {
return IQ.createErrorResponse(iqRequest, new XMPPError(Condition.not_acceptable));
}
}
});
}
示例9: handleXMPPException
import org.jivesoftware.smack.packet.XMPPError; //导入依赖的package包/类
private void handleXMPPException(XMPPErrorException e) {
XMPPError error = e.getXMPPError();
if (error != null) {
switch (error.getCondition()) {
case forbidden:
setStatus(Status.refused);
return;
case bad_request:
setStatus(Status.error);
setError(Error.not_acceptable);
break;
default:
setStatus(FileTransfer.Status.error);
}
}
setException(e);
}
示例10: VersionManager
import org.jivesoftware.smack.packet.XMPPError; //导入依赖的package包/类
private VersionManager(final XMPPConnection connection) {
super(connection);
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
sdm.addFeature(Version.NAMESPACE);
connection.registerIQRequestHandler(new AbstractIqRequestHandler(Version.ELEMENT, Version.NAMESPACE, IQ.Type.get,
Mode.async) {
@Override
public IQ handleIQRequest(IQ iqRequest) {
if (ourVersion == null) {
return IQ.createErrorResponse(iqRequest, new XMPPError(Condition.not_acceptable));
}
return Version.createResultFor(iqRequest, ourVersion);
}
});
}
示例11: testGetItemsWithMultiSubscription
import org.jivesoftware.smack.packet.XMPPError; //导入依赖的package包/类
public void testGetItemsWithMultiSubscription() throws XMPPException
{
LeafNode node = getRandomPubnode(getManager(0), true, false);
node.send((Item)null);
node.send((Item)null);
node.send((Item)null);
node.send((Item)null);
node.send((Item)null);
LeafNode user2Node = (LeafNode) getManager(1).getNode(node.getId());
Subscription sub1 = user2Node.subscribe(getBareJID(1));
Subscription sub2 = user2Node.subscribe(getBareJID(1));
try
{
user2Node.getItems();
}
catch (XMPPException exc)
{
assertEquals("bad-request", exc.getXMPPError().getCondition());
assertEquals(XMPPError.Type.MODIFY, exc.getXMPPError().getType());
}
List<Item> items = user2Node.getItems(sub1.getId());
assertTrue(items.size() == 5);
}
示例12: testRespondWithErrorOnInBandBytestreamRequest
import org.jivesoftware.smack.packet.XMPPError; //导入依赖的package包/类
/**
* Target should respond with not-acceptable error if no listeners for incoming In-Band
* Bytestream requests are registered.
*
* @throws XMPPException should not happen
*/
public void testRespondWithErrorOnInBandBytestreamRequest() throws XMPPException {
XMPPConnection targetConnection = getConnection(0);
XMPPConnection initiatorConnection = getConnection(1);
Open open = new Open("sessionID", 1024);
open.setFrom(initiatorConnection.getUser());
open.setTo(targetConnection.getUser());
PacketCollector collector = initiatorConnection.createPacketCollector(new PacketIDFilter(
open.getStanzaId()));
initiatorConnection.sendStanza(open);
Packet result = collector.nextResult();
assertNotNull(result.getError());
assertEquals(XMPPError.Condition.no_acceptable.toString(), result.getError().getCondition());
}
示例13: testRespondWithErrorOnSocks5BytestreamRequest
import org.jivesoftware.smack.packet.XMPPError; //导入依赖的package包/类
/**
* Target should respond with not-acceptable error if no listeners for incoming Socks5
* bytestream requests are registered.
*
* @throws XMPPException should not happen
*/
public void testRespondWithErrorOnSocks5BytestreamRequest() throws XMPPException {
XMPPConnection targetConnection = getConnection(0);
XMPPConnection initiatorConnection = getConnection(1);
Bytestream bytestreamInitiation = Socks5PacketUtils.createBytestreamInitiation(
initiatorConnection.getUser(), targetConnection.getUser(), "session_id");
bytestreamInitiation.addStreamHost("proxy.localhost", "127.0.0.1", 7777);
PacketCollector collector = initiatorConnection.createPacketCollector(new PacketIDFilter(
bytestreamInitiation.getStanzaId()));
initiatorConnection.sendStanza(bytestreamInitiation);
Packet result = collector.nextResult();
assertNotNull(result.getError());
assertEquals(XMPPError.Condition.no_acceptable.toString(), result.getError().getCondition());
}
示例14: getConfigFormWithInsufficientPriviliges
import org.jivesoftware.smack.packet.XMPPError; //导入依赖的package包/类
@Test
public void getConfigFormWithInsufficientPriviliges() throws XMPPException, SmackException, IOException
{
ThreadedDummyConnection con = ThreadedDummyConnection.newInstance();
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");
PubSub errorIq = new PubSub();
XMPPError error = new XMPPError(Condition.forbidden);
errorIq.setError(error);
con.addIQReply(errorIq);
try
{
node.getNodeConfiguration();
}
catch (XMPPErrorException e)
{
Assert.assertEquals(XMPPError.Type.AUTH, e.getXMPPError().getType());
}
}
示例15: shouldRespondWithError
import org.jivesoftware.smack.packet.XMPPError; //导入依赖的package包/类
/**
* If no listeners are registered for incoming In-Band Bytestream requests, all request should
* be rejected with an error.
*
* @throws Exception should not happen
*/
@Test
public void shouldRespondWithError() throws Exception {
// run the listener with the initiation packet
initiationListener.handleIQRequest(initBytestream);
// wait because packet is processed in an extra thread
Thread.sleep(200);
// capture reply to the In-Band Bytestream open request
ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class);
verify(connection).sendStanza(argument.capture());
// assert that reply is the correct error packet
assertEquals(initiatorJID, argument.getValue().getTo());
assertEquals(IQ.Type.error, argument.getValue().getType());
assertEquals(XMPPError.Condition.not_acceptable,
argument.getValue().getError().getCondition());
}