use of org.jivesoftware.smack.packet.StanzaError in project Smack by igniterealtime.
the class FileTransferNegotiator method selectStreamNegotiator.
/**
* Selects an appropriate stream negotiator after examining the incoming file transfer request.
*
* @param request The related file transfer request.
* @return The file transfer object that handles the transfer
* @throws NoStreamMethodsOfferedException If there are either no stream methods contained in the packet, or
* there is not an appropriate stream method.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws NoAcceptableTransferMechanisms if no acceptable transfer mechanisms are available
* @throws InterruptedException if the calling thread was interrupted.
*/
public StreamNegotiator selectStreamNegotiator(FileTransferRequest request) throws NotConnectedException, NoStreamMethodsOfferedException, NoAcceptableTransferMechanisms, InterruptedException {
StreamInitiation si = request.getStreamInitiation();
ListSingleFormField streamMethodField = getStreamMethodField(si.getFeatureNegotiationForm());
if (streamMethodField == null) {
String errorMessage = "No stream methods contained in stanza.";
StanzaError error = StanzaError.from(StanzaError.Condition.bad_request, errorMessage).build();
IQ iqPacket = IQ.createErrorResponse(si, error);
connection().sendStanza(iqPacket);
throw new FileTransferException.NoStreamMethodsOfferedException();
}
// select the appropriate protocol
StreamNegotiator selectedStreamNegotiator;
try {
selectedStreamNegotiator = getNegotiator(streamMethodField);
} catch (NoAcceptableTransferMechanisms e) {
IQ iqPacket = IQ.createErrorResponse(si, StanzaError.from(StanzaError.Condition.bad_request, "No acceptable transfer mechanism").build());
connection().sendStanza(iqPacket);
throw e;
}
return selectedStreamNegotiator;
}
use of org.jivesoftware.smack.packet.StanzaError in project Smack by igniterealtime.
the class FailureProvider method parse.
@Override
public Failure parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
Failure.CompressFailureError compressFailureError = null;
StanzaError stanzaError = null;
XmlEnvironment failureXmlEnvironment = XmlEnvironment.from(parser, xmlEnvironment);
outerloop: while (true) {
XmlPullParser.Event eventType = parser.next();
switch(eventType) {
case START_ELEMENT:
String name = parser.getName();
String namespace = parser.getNamespace();
switch(namespace) {
case Failure.NAMESPACE:
compressFailureError = Failure.CompressFailureError.valueOf(name.replace("-", "_"));
if (compressFailureError == null) {
LOGGER.warning("Unknown element in " + Failure.NAMESPACE + ": " + name);
}
break;
case StreamOpen.CLIENT_NAMESPACE:
case StreamOpen.SERVER_NAMESPACE:
switch(name) {
case StanzaError.ERROR:
stanzaError = PacketParserUtils.parseError(parser, failureXmlEnvironment);
break;
default:
LOGGER.warning("Unknown element in " + namespace + ": " + name);
break;
}
break;
}
break;
case END_ELEMENT:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
// fall out
default:
}
}
return new Failure(compressFailureError, stanzaError);
}
use of org.jivesoftware.smack.packet.StanzaError in project Smack by igniterealtime.
the class PacketParserUtilsTest method ensureNoNullLangInParsedDescriptiveTexts.
@Test
public void ensureNoNullLangInParsedDescriptiveTexts() throws Exception {
final String text = "Dummy descriptive text";
final String errorXml = XMLBuilder.create(StanzaError.ERROR).a("type", "cancel").up().element("internal-server-error", StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE).up().element("text", StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE).t(text).up().asString();
XmlPullParser parser = TestUtils.getParser(errorXml);
StanzaError error = PacketParserUtils.parseError(parser);
assertEquals(text, error.getDescriptiveText());
}
use of org.jivesoftware.smack.packet.StanzaError in project Smack by igniterealtime.
the class PacketParserUtilsTest method ensureNoEmptyLangInDescriptiveText.
@Test
public void ensureNoEmptyLangInDescriptiveText() throws Exception {
final String text = "Dummy descriptive text";
Map<String, String> texts = new HashMap<>();
texts.put("", text);
StanzaError error = StanzaError.getBuilder(StanzaError.Condition.internal_server_error).setDescriptiveTexts(texts).build();
final String errorXml = XMLBuilder.create(StanzaError.ERROR).a("type", "cancel").up().element("internal-server-error", StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE).up().element("text", StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE).t(text).up().asString();
assertXmlSimilar(errorXml, error.toXML(StreamOpen.CLIENT_NAMESPACE));
}
use of org.jivesoftware.smack.packet.StanzaError in project Smack by igniterealtime.
the class FailureProviderTest method withStanzaErrrorFailureTest.
@Test
public void withStanzaErrrorFailureTest() throws Exception {
final String xml = "<failure xmlns='http://jabber.org/protocol/compress'>" + "<setup-failed/>" + "<error xmlns='jabber:client' type='modify'>" + "<bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" + "</error>" + "</failure>";
final XmlPullParser parser = PacketParserUtils.getParserFor(xml);
final Failure failure = FailureProvider.INSTANCE.parse(parser);
assertEquals(Failure.CompressFailureError.setup_failed, failure.getCompressFailureError());
final StanzaError error = failure.getStanzaError();
assertEquals(Condition.bad_request, error.getCondition());
}
Aggregations