mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-25 07:42:06 +01:00
Improve parsing. Add method for de-serializing Strings
Move some duplicate code from XMPP(TCP|BOSH)Connection to PacketParserUtils. Remove TestUtils as the method now part of Smack's public API in PacketParserUtils.
This commit is contained in:
parent
beecb8a675
commit
3647a7fce5
24 changed files with 215 additions and 291 deletions
|
@ -19,6 +19,7 @@ package org.jivesoftware.smack.bosh;
|
||||||
|
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.sasl.SASLMechanism.Challenge;
|
import org.jivesoftware.smack.sasl.SASLMechanism.Challenge;
|
||||||
import org.jivesoftware.smack.sasl.SASLMechanism.SASLFailure;
|
import org.jivesoftware.smack.sasl.SASLMechanism.SASLFailure;
|
||||||
import org.jivesoftware.smack.sasl.SASLMechanism.Success;
|
import org.jivesoftware.smack.sasl.SASLMechanism.Success;
|
||||||
|
@ -75,14 +76,9 @@ public class BOSHPacketReader implements BOSHClientResponseListener {
|
||||||
do {
|
do {
|
||||||
eventType = parser.next();
|
eventType = parser.next();
|
||||||
if (eventType == XmlPullParser.START_TAG) {
|
if (eventType == XmlPullParser.START_TAG) {
|
||||||
if (parser.getName().equals("body")) {
|
Packet packet = PacketParserUtils.parseStanza(parser, connection);
|
||||||
// ignore the container root element
|
if (packet != null) {
|
||||||
} else if (parser.getName().equals("message")) {
|
connection.processPacket(packet);
|
||||||
connection.processPacket(PacketParserUtils.parseMessage(parser));
|
|
||||||
} else if (parser.getName().equals("iq")) {
|
|
||||||
connection.processPacket(PacketParserUtils.parseIQ(parser, connection));
|
|
||||||
} else if (parser.getName().equals("presence")) {
|
|
||||||
connection.processPacket(PacketParserUtils.parsePresence(parser));
|
|
||||||
} else if (parser.getName().equals("challenge")) {
|
} else if (parser.getName().equals("challenge")) {
|
||||||
// The server is challenging the SASL authentication
|
// The server is challenging the SASL authentication
|
||||||
// made by the client
|
// made by the client
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
package org.jivesoftware.smack.util;
|
package org.jivesoftware.smack.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -44,6 +47,7 @@ import org.jivesoftware.smack.provider.ProviderManager;
|
||||||
import org.jivesoftware.smack.sasl.SASLMechanism.SASLFailure;
|
import org.jivesoftware.smack.sasl.SASLMechanism.SASLFailure;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
import org.xmlpull.v1.XmlPullParserFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class that helps to parse packets. Any parsing packets method that must be shared
|
* Utility class that helps to parse packets. Any parsing packets method that must be shared
|
||||||
|
@ -54,6 +58,82 @@ import org.xmlpull.v1.XmlPullParserException;
|
||||||
public class PacketParserUtils {
|
public class PacketParserUtils {
|
||||||
private static final Logger LOGGER = Logger.getLogger(PacketParserUtils.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(PacketParserUtils.class.getName());
|
||||||
|
|
||||||
|
public static XmlPullParser getParserFor(String stanza) throws XmlPullParserException, IOException {
|
||||||
|
return getParserFor(new StringReader(stanza));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static XmlPullParser getParserFor(Reader reader) throws XmlPullParserException, IOException {
|
||||||
|
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||||
|
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||||
|
parser.setInput(reader);
|
||||||
|
|
||||||
|
// Wind the parser forward to the first start tag
|
||||||
|
int event = parser.getEventType();
|
||||||
|
while (event != XmlPullParser.START_TAG) {
|
||||||
|
if (event == XmlPullParser.END_DOCUMENT) {
|
||||||
|
throw new IllegalArgumentException("Document contains no start tag");
|
||||||
|
}
|
||||||
|
event = parser.next();
|
||||||
|
}
|
||||||
|
return parser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static XmlPullParser getParserFor(String stanza, String startTag)
|
||||||
|
throws XmlPullParserException, IOException {
|
||||||
|
XmlPullParser parser = getParserFor(stanza);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
int event = parser.getEventType();
|
||||||
|
String name = parser.getName();
|
||||||
|
if (event == XmlPullParser.START_TAG && name.equals(startTag)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (event == XmlPullParser.END_DOCUMENT) {
|
||||||
|
throw new IllegalArgumentException("Could not find start tag '" + startTag
|
||||||
|
+ "' in stanza: " + stanza);
|
||||||
|
}
|
||||||
|
parser.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
return parser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Packet parseStanza(String stanza) throws Exception {
|
||||||
|
return parseStanza(getParserFor(stanza));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Packet parseStanza(XmlPullParser parser) throws Exception {
|
||||||
|
return parseStanza(parser, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to parse and return either a Message, IQ or Presence stanza.
|
||||||
|
*
|
||||||
|
* connection is optional and is used to return feature-not-implemented errors for unknown IQ stanzas.
|
||||||
|
*
|
||||||
|
* @param parser
|
||||||
|
* @param connection
|
||||||
|
* @return a packet which is either a Message, IQ or Presence.
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static Packet parseStanza(XmlPullParser parser, XMPPConnection connection) throws Exception {
|
||||||
|
final int eventType = parser.getEventType();
|
||||||
|
if (eventType != XmlPullParser.START_TAG) {
|
||||||
|
throw new IllegalArgumentException("Parser not at start tag");
|
||||||
|
}
|
||||||
|
final String name = parser.getName();
|
||||||
|
switch (name) {
|
||||||
|
case "message":
|
||||||
|
return parseMessage(parser);
|
||||||
|
case "iq":
|
||||||
|
return parseIQ(parser, connection);
|
||||||
|
case "presence":
|
||||||
|
return parsePresence(parser);
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a message packet.
|
* Parses a message packet.
|
||||||
*
|
*
|
||||||
|
@ -253,6 +333,7 @@ public class PacketParserUtils {
|
||||||
* Parses an IQ packet.
|
* Parses an IQ packet.
|
||||||
*
|
*
|
||||||
* @param parser the XML parser, positioned at the start of an IQ packet.
|
* @param parser the XML parser, positioned at the start of an IQ packet.
|
||||||
|
* @param connection the optional XMPPConnection used to send feature-not-implemented replies.
|
||||||
* @return an IQ object.
|
* @return an IQ object.
|
||||||
* @throws Exception if an exception occurs while parsing the packet.
|
* @throws Exception if an exception occurs while parsing the packet.
|
||||||
*/
|
*/
|
||||||
|
@ -315,7 +396,7 @@ public class PacketParserUtils {
|
||||||
}
|
}
|
||||||
// Decide what to do when an IQ packet was not understood
|
// Decide what to do when an IQ packet was not understood
|
||||||
if (iqPacket == null) {
|
if (iqPacket == null) {
|
||||||
if (IQ.Type.GET == type || IQ.Type.SET == type ) {
|
if (connection != null && (IQ.Type.GET == type || IQ.Type.SET == type)) {
|
||||||
// If the IQ stanza is of type "get" or "set" containing a child element qualified
|
// If the IQ stanza is of type "get" or "set" containing a child element qualified
|
||||||
// by a namespace with no registered Smack provider, then answer an IQ of type
|
// by a namespace with no registered Smack provider, then answer an IQ of type
|
||||||
// "error" with code 501 ("feature-not-implemented")
|
// "error" with code 501 ("feature-not-implemented")
|
||||||
|
@ -655,11 +736,10 @@ public class PacketParserUtils {
|
||||||
* @param namespace the XML namespace of the packet extension.
|
* @param namespace the XML namespace of the packet extension.
|
||||||
* @param parser the XML parser, positioned at the starting element of the extension.
|
* @param parser the XML parser, positioned at the starting element of the extension.
|
||||||
* @return a PacketExtension.
|
* @return a PacketExtension.
|
||||||
* @throws Exception if a parsing error occurs.
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static PacketExtension parsePacketExtension(String elementName, String namespace, XmlPullParser parser)
|
public static PacketExtension parsePacketExtension(String elementName, String namespace,
|
||||||
throws Exception
|
XmlPullParser parser) throws Exception {
|
||||||
{
|
|
||||||
// See if a provider is registered to handle the extension.
|
// See if a provider is registered to handle the extension.
|
||||||
Object provider = ProviderManager.getExtensionProvider(elementName, namespace);
|
Object provider = ProviderManager.getExtensionProvider(elementName, namespace);
|
||||||
if (provider != null) {
|
if (provider != null) {
|
||||||
|
@ -712,9 +792,11 @@ public class PacketParserUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object parseWithIntrospection(String elementName,
|
public static Object parseWithIntrospection(String elementName, Class<?> objectClass,
|
||||||
Class<?> objectClass, XmlPullParser parser) throws Exception
|
XmlPullParser parser) throws NoSuchMethodException, SecurityException,
|
||||||
{
|
InstantiationException, IllegalAccessException, XmlPullParserException,
|
||||||
|
IOException, IllegalArgumentException, InvocationTargetException,
|
||||||
|
ClassNotFoundException {
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
Object object = objectClass.newInstance();
|
Object object = objectClass.newInstance();
|
||||||
while (!done) {
|
while (!done) {
|
||||||
|
@ -748,9 +830,9 @@ public class PacketParserUtils {
|
||||||
* @param type the type of the property.
|
* @param type the type of the property.
|
||||||
* @param value the encode String value to decode.
|
* @param value the encode String value to decode.
|
||||||
* @return the String value decoded into the specified type.
|
* @return the String value decoded into the specified type.
|
||||||
* @throws Exception If decoding failed due to an error.
|
* @throws ClassNotFoundException
|
||||||
*/
|
*/
|
||||||
private static Object decode(Class<?> type, String value) throws Exception {
|
private static Object decode(Class<?> type, String value) throws ClassNotFoundException {
|
||||||
if (type.getName().equals("java.lang.String")) {
|
if (type.getName().equals("java.lang.String")) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ package org.jivesoftware.smack.packet;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.StreamError;
|
import org.jivesoftware.smack.packet.StreamError;
|
||||||
import org.jivesoftware.smack.test.util.TestUtils;
|
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
@ -38,7 +37,7 @@ public class StreamErrorTest {
|
||||||
"</stream:error>" +
|
"</stream:error>" +
|
||||||
"</stream:stream>";
|
"</stream:stream>";
|
||||||
try {
|
try {
|
||||||
XmlPullParser parser = TestUtils.getParser(xml, "error");
|
XmlPullParser parser = PacketParserUtils.getParserFor(xml, "error");
|
||||||
error = PacketParserUtils.parseStreamError(parser);
|
error = PacketParserUtils.parseStreamError(parser);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail(e.getMessage());
|
fail(e.getMessage());
|
||||||
|
@ -62,7 +61,7 @@ public class StreamErrorTest {
|
||||||
"</stream:error>" +
|
"</stream:error>" +
|
||||||
"</stream:stream>";
|
"</stream:stream>";
|
||||||
try {
|
try {
|
||||||
XmlPullParser parser = TestUtils.getParser(xml, "error");
|
XmlPullParser parser = PacketParserUtils.getParserFor(xml, "error");
|
||||||
error = PacketParserUtils.parseStreamError(parser);
|
error = PacketParserUtils.parseStreamError(parser);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail(e.getMessage());
|
fail(e.getMessage());
|
||||||
|
@ -90,7 +89,7 @@ public class StreamErrorTest {
|
||||||
"</stream:error>" +
|
"</stream:error>" +
|
||||||
"</stream:stream>";
|
"</stream:stream>";
|
||||||
try {
|
try {
|
||||||
XmlPullParser parser = TestUtils.getParser(xml, "error");
|
XmlPullParser parser = PacketParserUtils.getParserFor(xml, "error");
|
||||||
error = PacketParserUtils.parseStreamError(parser);
|
error = PacketParserUtils.parseStreamError(parser);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail(e.getMessage());
|
fail(e.getMessage());
|
||||||
|
|
|
@ -23,7 +23,6 @@ import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.packet.PacketExtension;
|
import org.jivesoftware.smack.packet.PacketExtension;
|
||||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||||
import org.jivesoftware.smack.provider.ProviderManager;
|
import org.jivesoftware.smack.provider.ProviderManager;
|
||||||
import org.jivesoftware.smack.test.util.TestUtils;
|
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -52,7 +51,7 @@ public class ParsingExceptionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void consumeUnparsedInput() throws Exception {
|
public void consumeUnparsedInput() throws Exception {
|
||||||
XmlPullParser parser = TestUtils.getMessageParser(
|
XmlPullParser parser = PacketParserUtils.getParserFor(
|
||||||
"<message from='user@server.example' to='francisco@denmark.lit' id='foo'>" +
|
"<message from='user@server.example' to='francisco@denmark.lit' id='foo'>" +
|
||||||
"<" + ThrowException.ELEMENT + " xmlns='" + ThrowException.NAMESPACE + "'>" +
|
"<" + ThrowException.ELEMENT + " xmlns='" + ThrowException.NAMESPACE + "'>" +
|
||||||
"<nothingInHere>" +
|
"<nothingInHere>" +
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright 2013 Robin Collier
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.jivesoftware.smack.test.util;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringReader;
|
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParserFactory;
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
|
||||||
|
|
||||||
final public class TestUtils {
|
|
||||||
private TestUtils() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static XmlPullParser getIQParser(String stanza) {
|
|
||||||
return getParser(stanza, "iq");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static XmlPullParser getMessageParser(String stanza) {
|
|
||||||
return getParser(stanza, "message");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static XmlPullParser getPresenceParser(String stanza) {
|
|
||||||
return getParser(stanza, "presence");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static XmlPullParser getParser(String stanza, String startTag) {
|
|
||||||
XmlPullParser parser;
|
|
||||||
try {
|
|
||||||
parser = XmlPullParserFactory.newInstance().newPullParser();
|
|
||||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
|
||||||
parser.setInput(new StringReader(stanza));
|
|
||||||
boolean found = false;
|
|
||||||
|
|
||||||
while (!found) {
|
|
||||||
if ((parser.next() == XmlPullParser.START_TAG) && parser.getName().equals(startTag))
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found)
|
|
||||||
throw new IllegalArgumentException("Cannot parse start tag [" + startTag + "] from stanza [" + stanza
|
|
||||||
+ "]");
|
|
||||||
} catch (XmlPullParserException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
return parser;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -33,7 +33,6 @@ import org.custommonkey.xmlunit.examples.RecursiveElementNameAndTextQualifier;
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.packet.Presence;
|
import org.jivesoftware.smack.packet.Presence;
|
||||||
import org.jivesoftware.smack.test.util.TestUtils;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
@ -69,7 +68,7 @@ public class PacketParserUtilsTest {
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
Message message = (Message) PacketParserUtils
|
Message message = (Message) PacketParserUtils
|
||||||
.parseMessage(TestUtils.getMessageParser(control));
|
.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(defaultLanguage, message.getBody());
|
assertEquals(defaultLanguage, message.getBody());
|
||||||
assertTrue(message.getBodyLanguages().isEmpty());
|
assertTrue(message.getBodyLanguages().isEmpty());
|
||||||
|
@ -88,7 +87,7 @@ public class PacketParserUtilsTest {
|
||||||
.t(otherLanguage)
|
.t(otherLanguage)
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils.parseMessage(TestUtils.getMessageParser(control));
|
message = (Message) PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(otherLanguage, message.getBody());
|
assertEquals(otherLanguage, message.getBody());
|
||||||
assertTrue(message.getBodyLanguages().isEmpty());
|
assertTrue(message.getBodyLanguages().isEmpty());
|
||||||
|
@ -106,7 +105,7 @@ public class PacketParserUtilsTest {
|
||||||
.t(defaultLanguage)
|
.t(defaultLanguage)
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils.parseMessage(TestUtils.getMessageParser(control));
|
message = (Message) PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(defaultLanguage, message.getBody());
|
assertEquals(defaultLanguage, message.getBody());
|
||||||
assertTrue(message.getBodyLanguages().isEmpty());
|
assertTrue(message.getBodyLanguages().isEmpty());
|
||||||
|
@ -125,7 +124,7 @@ public class PacketParserUtilsTest {
|
||||||
.t(defaultLanguage)
|
.t(defaultLanguage)
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils.parseMessage(TestUtils.getMessageParser(control));
|
message = (Message) PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(defaultLanguage, message.getBody());
|
assertEquals(defaultLanguage, message.getBody());
|
||||||
assertTrue(message.getBodyLanguages().isEmpty());
|
assertTrue(message.getBodyLanguages().isEmpty());
|
||||||
|
@ -146,7 +145,7 @@ public class PacketParserUtilsTest {
|
||||||
.t(otherLanguage)
|
.t(otherLanguage)
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils.parseMessage(TestUtils.getMessageParser(control));
|
message = (Message) PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertNull(message.getBody());
|
assertNull(message.getBody());
|
||||||
assertFalse(message.getBodyLanguages().isEmpty());
|
assertFalse(message.getBodyLanguages().isEmpty());
|
||||||
|
@ -167,7 +166,7 @@ public class PacketParserUtilsTest {
|
||||||
.t(otherLanguage)
|
.t(otherLanguage)
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils.parseMessage(TestUtils.getMessageParser(control));
|
message = (Message) PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertNull(message.getBody());
|
assertNull(message.getBody());
|
||||||
assertFalse(message.getBodyLanguages().isEmpty());
|
assertFalse(message.getBodyLanguages().isEmpty());
|
||||||
|
@ -188,7 +187,7 @@ public class PacketParserUtilsTest {
|
||||||
.t(defaultLanguage)
|
.t(defaultLanguage)
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils.parseMessage(TestUtils.getMessageParser(control));
|
message = (Message) PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertNull(message.getBody());
|
assertNull(message.getBody());
|
||||||
assertFalse(message.getBodyLanguages().isEmpty());
|
assertFalse(message.getBodyLanguages().isEmpty());
|
||||||
|
@ -218,7 +217,7 @@ public class PacketParserUtilsTest {
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
Message message = (Message) PacketParserUtils
|
Message message = (Message) PacketParserUtils
|
||||||
.parseMessage(TestUtils.getMessageParser(control));
|
.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(defaultLanguage, message.getSubject());
|
assertEquals(defaultLanguage, message.getSubject());
|
||||||
assertTrue(message.getSubjectLanguages().isEmpty());
|
assertTrue(message.getSubjectLanguages().isEmpty());
|
||||||
|
@ -237,7 +236,7 @@ public class PacketParserUtilsTest {
|
||||||
.t(otherLanguage)
|
.t(otherLanguage)
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils.parseMessage(TestUtils.getMessageParser(control));
|
message = (Message) PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(otherLanguage, message.getSubject());
|
assertEquals(otherLanguage, message.getSubject());
|
||||||
assertTrue(message.getSubjectLanguages().isEmpty());
|
assertTrue(message.getSubjectLanguages().isEmpty());
|
||||||
|
@ -255,7 +254,7 @@ public class PacketParserUtilsTest {
|
||||||
.t(defaultLanguage)
|
.t(defaultLanguage)
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils.parseMessage(TestUtils.getMessageParser(control));
|
message = (Message) PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(defaultLanguage, message.getSubject());
|
assertEquals(defaultLanguage, message.getSubject());
|
||||||
assertTrue(message.getSubjectLanguages().isEmpty());
|
assertTrue(message.getSubjectLanguages().isEmpty());
|
||||||
|
@ -274,7 +273,7 @@ public class PacketParserUtilsTest {
|
||||||
.t(defaultLanguage)
|
.t(defaultLanguage)
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils.parseMessage(TestUtils.getMessageParser(control));
|
message = (Message) PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(defaultLanguage, message.getSubject());
|
assertEquals(defaultLanguage, message.getSubject());
|
||||||
assertTrue(message.getSubjectLanguages().isEmpty());
|
assertTrue(message.getSubjectLanguages().isEmpty());
|
||||||
|
@ -295,7 +294,7 @@ public class PacketParserUtilsTest {
|
||||||
.t(otherLanguage)
|
.t(otherLanguage)
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils.parseMessage(TestUtils.getMessageParser(control));
|
message = (Message) PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertNull(message.getSubject());
|
assertNull(message.getSubject());
|
||||||
assertFalse(message.getSubjectLanguages().isEmpty());
|
assertFalse(message.getSubjectLanguages().isEmpty());
|
||||||
|
@ -316,7 +315,7 @@ public class PacketParserUtilsTest {
|
||||||
.t(otherLanguage)
|
.t(otherLanguage)
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils.parseMessage(TestUtils.getMessageParser(control));
|
message = (Message) PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertNull(message.getSubject());
|
assertNull(message.getSubject());
|
||||||
assertFalse(message.getSubjectLanguages().isEmpty());
|
assertFalse(message.getSubjectLanguages().isEmpty());
|
||||||
|
@ -337,7 +336,7 @@ public class PacketParserUtilsTest {
|
||||||
.t(defaultLanguage)
|
.t(defaultLanguage)
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils.parseMessage(TestUtils.getMessageParser(control));
|
message = (Message) PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertNull(message.getSubject());
|
assertNull(message.getSubject());
|
||||||
assertFalse(message.getSubjectLanguages().isEmpty());
|
assertFalse(message.getSubjectLanguages().isEmpty());
|
||||||
|
@ -372,7 +371,7 @@ public class PacketParserUtilsTest {
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils
|
message = (Message) PacketParserUtils
|
||||||
.parseMessage(TestUtils.getMessageParser(control));
|
.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(defaultLanguage, message.getBody());
|
assertEquals(defaultLanguage, message.getBody());
|
||||||
assertEquals(otherLanguage, message.getBody(otherLanguage));
|
assertEquals(otherLanguage, message.getBody(otherLanguage));
|
||||||
|
@ -397,7 +396,7 @@ public class PacketParserUtilsTest {
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils
|
message = (Message) PacketParserUtils
|
||||||
.parseMessage(TestUtils.getMessageParser(control));
|
.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(defaultLanguage, message.getBody());
|
assertEquals(defaultLanguage, message.getBody());
|
||||||
assertEquals(defaultLanguage, message.getBody(defaultLanguage));
|
assertEquals(defaultLanguage, message.getBody(defaultLanguage));
|
||||||
|
@ -421,7 +420,7 @@ public class PacketParserUtilsTest {
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils
|
message = (Message) PacketParserUtils
|
||||||
.parseMessage(TestUtils.getMessageParser(control));
|
.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(otherLanguage, message.getBody());
|
assertEquals(otherLanguage, message.getBody());
|
||||||
assertEquals(defaultLanguage, message.getBody(defaultLanguage));
|
assertEquals(defaultLanguage, message.getBody(defaultLanguage));
|
||||||
|
@ -445,7 +444,7 @@ public class PacketParserUtilsTest {
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils
|
message = (Message) PacketParserUtils
|
||||||
.parseMessage(TestUtils.getMessageParser(control));
|
.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(defaultLanguage, message.getBody());
|
assertEquals(defaultLanguage, message.getBody());
|
||||||
assertEquals(defaultLanguage, message.getBody(defaultLanguage));
|
assertEquals(defaultLanguage, message.getBody(defaultLanguage));
|
||||||
|
@ -468,7 +467,7 @@ public class PacketParserUtilsTest {
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils
|
message = (Message) PacketParserUtils
|
||||||
.parseMessage(TestUtils.getMessageParser(control));
|
.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(defaultLanguage, message.getBody());
|
assertEquals(defaultLanguage, message.getBody());
|
||||||
assertEquals(defaultLanguage, message.getBody(defaultLanguage));
|
assertEquals(defaultLanguage, message.getBody(defaultLanguage));
|
||||||
|
@ -491,7 +490,7 @@ public class PacketParserUtilsTest {
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils
|
message = (Message) PacketParserUtils
|
||||||
.parseMessage(TestUtils.getMessageParser(control));
|
.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(defaultLanguage, message.getBody());
|
assertEquals(defaultLanguage, message.getBody());
|
||||||
assertEquals(defaultLanguage, message.getBody(defaultLanguage));
|
assertEquals(defaultLanguage, message.getBody(defaultLanguage));
|
||||||
|
@ -525,7 +524,7 @@ public class PacketParserUtilsTest {
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils
|
message = (Message) PacketParserUtils
|
||||||
.parseMessage(TestUtils.getMessageParser(control));
|
.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(defaultLanguage, message.getSubject());
|
assertEquals(defaultLanguage, message.getSubject());
|
||||||
assertEquals(otherLanguage, message.getSubject(otherLanguage));
|
assertEquals(otherLanguage, message.getSubject(otherLanguage));
|
||||||
|
@ -550,7 +549,7 @@ public class PacketParserUtilsTest {
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils
|
message = (Message) PacketParserUtils
|
||||||
.parseMessage(TestUtils.getMessageParser(control));
|
.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(defaultLanguage, message.getSubject());
|
assertEquals(defaultLanguage, message.getSubject());
|
||||||
assertEquals(defaultLanguage, message.getSubject(defaultLanguage));
|
assertEquals(defaultLanguage, message.getSubject(defaultLanguage));
|
||||||
|
@ -574,7 +573,7 @@ public class PacketParserUtilsTest {
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils
|
message = (Message) PacketParserUtils
|
||||||
.parseMessage(TestUtils.getMessageParser(control));
|
.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(otherLanguage, message.getSubject());
|
assertEquals(otherLanguage, message.getSubject());
|
||||||
assertEquals(defaultLanguage, message.getSubject(defaultLanguage));
|
assertEquals(defaultLanguage, message.getSubject(defaultLanguage));
|
||||||
|
@ -598,7 +597,7 @@ public class PacketParserUtilsTest {
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils
|
message = (Message) PacketParserUtils
|
||||||
.parseMessage(TestUtils.getMessageParser(control));
|
.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(defaultLanguage, message.getSubject());
|
assertEquals(defaultLanguage, message.getSubject());
|
||||||
assertEquals(defaultLanguage, message.getSubject(defaultLanguage));
|
assertEquals(defaultLanguage, message.getSubject(defaultLanguage));
|
||||||
|
@ -621,7 +620,7 @@ public class PacketParserUtilsTest {
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils
|
message = (Message) PacketParserUtils
|
||||||
.parseMessage(TestUtils.getMessageParser(control));
|
.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(defaultLanguage, message.getSubject());
|
assertEquals(defaultLanguage, message.getSubject());
|
||||||
assertEquals(defaultLanguage, message.getSubject(defaultLanguage));
|
assertEquals(defaultLanguage, message.getSubject(defaultLanguage));
|
||||||
|
@ -644,7 +643,7 @@ public class PacketParserUtilsTest {
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
message = (Message) PacketParserUtils
|
message = (Message) PacketParserUtils
|
||||||
.parseMessage(TestUtils.getMessageParser(control));
|
.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(defaultLanguage, message.getSubject());
|
assertEquals(defaultLanguage, message.getSubject());
|
||||||
assertEquals(defaultLanguage, message.getSubject(defaultLanguage));
|
assertEquals(defaultLanguage, message.getSubject(defaultLanguage));
|
||||||
|
@ -670,7 +669,7 @@ public class PacketParserUtilsTest {
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Message message = (Message) PacketParserUtils.parseMessage(TestUtils.getMessageParser(control));
|
Message message = (Message) PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
|
||||||
String body = "<span style=\"font-weight: bold;\">"
|
String body = "<span style=\"font-weight: bold;\">"
|
||||||
+ "Bad Message Body</span>";
|
+ "Bad Message Body</span>";
|
||||||
assertEquals(body, message.getBody());
|
assertEquals(body, message.getBody());
|
||||||
|
@ -702,7 +701,7 @@ public class PacketParserUtilsTest {
|
||||||
String invalidControl = validControl.replace("Good Message Body", "Bad </span> Body");
|
String invalidControl = validControl.replace("Good Message Body", "Bad </span> Body");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PacketParserUtils.parseMessage(TestUtils.getMessageParser(invalidControl));
|
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
|
||||||
fail("Exception should be thrown");
|
fail("Exception should be thrown");
|
||||||
} catch(XmlPullParserException e) {
|
} catch(XmlPullParserException e) {
|
||||||
assertTrue(e.getMessage().contains("end tag name </span>"));
|
assertTrue(e.getMessage().contains("end tag name </span>"));
|
||||||
|
@ -711,7 +710,7 @@ public class PacketParserUtilsTest {
|
||||||
invalidControl = validControl.replace("Good Message Body", "Bad </body> Body");
|
invalidControl = validControl.replace("Good Message Body", "Bad </body> Body");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PacketParserUtils.parseMessage(TestUtils.getMessageParser(invalidControl));
|
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
|
||||||
fail("Exception should be thrown");
|
fail("Exception should be thrown");
|
||||||
} catch(XmlPullParserException e) {
|
} catch(XmlPullParserException e) {
|
||||||
assertTrue(e.getMessage().contains("end tag name </body>"));
|
assertTrue(e.getMessage().contains("end tag name </body>"));
|
||||||
|
@ -720,7 +719,7 @@ public class PacketParserUtilsTest {
|
||||||
invalidControl = validControl.replace("Good Message Body", "Bad </message> Body");
|
invalidControl = validControl.replace("Good Message Body", "Bad </message> Body");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PacketParserUtils.parseMessage(TestUtils.getMessageParser(invalidControl));
|
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
|
||||||
fail("Exception should be thrown");
|
fail("Exception should be thrown");
|
||||||
} catch(XmlPullParserException e) {
|
} catch(XmlPullParserException e) {
|
||||||
assertTrue(e.getMessage().contains("end tag name </message>"));
|
assertTrue(e.getMessage().contains("end tag name </message>"));
|
||||||
|
@ -748,7 +747,7 @@ public class PacketParserUtilsTest {
|
||||||
.t("This is a test of the emergency broadcast system, 3.")
|
.t("This is a test of the emergency broadcast system, 3.")
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
Packet message = PacketParserUtils.parseMessage(TestUtils.getMessageParser(control));
|
Packet message = PacketParserUtils.parseStanza(control);
|
||||||
Diff xmlDiff = new Diff(control, message.toXML().toString());
|
Diff xmlDiff = new Diff(control, message.toXML().toString());
|
||||||
xmlDiff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
|
xmlDiff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
|
||||||
assertTrue(xmlDiff.similar());
|
assertTrue(xmlDiff.similar());
|
||||||
|
@ -758,7 +757,7 @@ public class PacketParserUtilsTest {
|
||||||
public void validateSimplePresence() throws Exception {
|
public void validateSimplePresence() throws Exception {
|
||||||
String stanza = "<presence from='juliet@example.com/balcony' to='romeo@example.net'/>";
|
String stanza = "<presence from='juliet@example.com/balcony' to='romeo@example.net'/>";
|
||||||
|
|
||||||
Presence presence = PacketParserUtils.parsePresence(TestUtils.getPresenceParser(stanza));
|
Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza));
|
||||||
|
|
||||||
assertXMLEqual(stanza, presence.toXML().toString());
|
assertXMLEqual(stanza, presence.toXML().toString());
|
||||||
}
|
}
|
||||||
|
@ -767,7 +766,7 @@ public class PacketParserUtilsTest {
|
||||||
public void validatePresenceProbe() throws Exception {
|
public void validatePresenceProbe() throws Exception {
|
||||||
String stanza = "<presence from='mercutio@example.com' id='xv291f38' to='juliet@example.com' type='unsubscribed'/>";
|
String stanza = "<presence from='mercutio@example.com' id='xv291f38' to='juliet@example.com' type='unsubscribed'/>";
|
||||||
|
|
||||||
Presence presence = PacketParserUtils.parsePresence(TestUtils.getPresenceParser(stanza));
|
Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza));
|
||||||
|
|
||||||
assertXMLEqual(stanza, presence.toXML().toString());
|
assertXMLEqual(stanza, presence.toXML().toString());
|
||||||
assertEquals(Presence.Type.unsubscribed, presence.getType());
|
assertEquals(Presence.Type.unsubscribed, presence.getType());
|
||||||
|
@ -781,7 +780,7 @@ public class PacketParserUtilsTest {
|
||||||
+ "<priority>1</priority>"
|
+ "<priority>1</priority>"
|
||||||
+ "</presence>";
|
+ "</presence>";
|
||||||
|
|
||||||
Presence presence = PacketParserUtils.parsePresence(TestUtils.getPresenceParser(stanza));
|
Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza));
|
||||||
assertXMLEqual(stanza, presence.toXML().toString());
|
assertXMLEqual(stanza, presence.toXML().toString());
|
||||||
assertEquals(Presence.Type.unsubscribed, presence.getType());
|
assertEquals(Presence.Type.unsubscribed, presence.getType());
|
||||||
assertEquals("dnd", presence.getMode().name());
|
assertEquals("dnd", presence.getMode().name());
|
||||||
|
@ -793,7 +792,7 @@ public class PacketParserUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void parseContentDepthTest() throws Exception {
|
public void parseContentDepthTest() throws Exception {
|
||||||
final String stanza = "<iq type='result' to='foo@bar.com' from='baz.com' id='42'/>";
|
final String stanza = "<iq type='result' to='foo@bar.com' from='baz.com' id='42'/>";
|
||||||
XmlPullParser parser = TestUtils.getParser(stanza, "iq");
|
XmlPullParser parser = PacketParserUtils.getParserFor(stanza, "iq");
|
||||||
String content = PacketParserUtils.parseContentDepth(parser, 1);
|
String content = PacketParserUtils.parseContentDepth(parser, 1);
|
||||||
assertEquals("", content);
|
assertEquals("", content);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.jivesoftware.smack.provider.ProviderManager;
|
import org.jivesoftware.smack.provider.ProviderManager;
|
||||||
import org.jivesoftware.smack.test.util.TestUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
|
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
|
||||||
import org.jivesoftware.smackx.carbons.provider.CarbonManagerProvider;
|
import org.jivesoftware.smackx.carbons.provider.CarbonManagerProvider;
|
||||||
import org.jivesoftware.smackx.forward.Forwarded;
|
import org.jivesoftware.smackx.forward.Forwarded;
|
||||||
|
@ -58,7 +58,7 @@ public class CarbonTest {
|
||||||
.a("from", "romeo@montague.com")
|
.a("from", "romeo@montague.com")
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
parser = TestUtils.getParser(control, "sent");
|
parser = PacketParserUtils.getParserFor(control);
|
||||||
cc = (CarbonExtension) new CarbonManagerProvider().parseExtension(parser);
|
cc = (CarbonExtension) new CarbonManagerProvider().parseExtension(parser);
|
||||||
fwd = cc.getForwarded();
|
fwd = cc.getForwarded();
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ public class CarbonTest {
|
||||||
.a("from", "romeo@montague.com")
|
.a("from", "romeo@montague.com")
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
parser = TestUtils.getParser(control, "received");
|
parser = PacketParserUtils.getParserFor(control);
|
||||||
cc = (CarbonExtension) new CarbonManagerProvider().parseExtension(parser);
|
cc = (CarbonExtension) new CarbonManagerProvider().parseExtension(parser);
|
||||||
|
|
||||||
assertEquals(CarbonExtension.Direction.received, cc.getDirection());
|
assertEquals(CarbonExtension.Direction.received, cc.getDirection());
|
||||||
|
@ -108,7 +108,7 @@ public class CarbonTest {
|
||||||
.a("xmlns", "urn:xmpp:forwarded:0")
|
.a("xmlns", "urn:xmpp:forwarded:0")
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
parser = TestUtils.getParser(control, "sent");
|
parser = PacketParserUtils.getParserFor(control);
|
||||||
new CarbonManagerProvider().parseExtension(parser);
|
new CarbonManagerProvider().parseExtension(parser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
package org.jivesoftware.smackx.hoxt.provider;
|
package org.jivesoftware.smackx.hoxt.provider;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.test.util.TestUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.jivesoftware.smackx.hoxt.packet.AbstractHttpOverXmpp;
|
import org.jivesoftware.smackx.hoxt.packet.AbstractHttpOverXmpp;
|
||||||
import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppReq;
|
import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppReq;
|
||||||
import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppResp;
|
import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppResp;
|
||||||
|
@ -53,7 +53,7 @@ public class AbstractHttpOverXmppProviderTest {
|
||||||
expectedHeaders.put("Content-Length", "0");
|
expectedHeaders.put("Content-Length", "0");
|
||||||
|
|
||||||
AbstractHttpOverXmppProvider provider = new HttpOverXmppRespProvider();
|
AbstractHttpOverXmppProvider provider = new HttpOverXmppRespProvider();
|
||||||
XmlPullParser parser = TestUtils.getParser(string, "resp");
|
XmlPullParser parser = PacketParserUtils.getParserFor(string);
|
||||||
|
|
||||||
IQ iq = provider.parseIQ(parser);
|
IQ iq = provider.parseIQ(parser);
|
||||||
assertTrue(iq instanceof HttpOverXmppResp);
|
assertTrue(iq instanceof HttpOverXmppResp);
|
||||||
|
@ -73,7 +73,7 @@ public class AbstractHttpOverXmppProviderTest {
|
||||||
expectedHeaders.put("Host", "clayster.com");
|
expectedHeaders.put("Host", "clayster.com");
|
||||||
|
|
||||||
AbstractHttpOverXmppProvider provider = new HttpOverXmppReqProvider();
|
AbstractHttpOverXmppProvider provider = new HttpOverXmppReqProvider();
|
||||||
XmlPullParser parser = TestUtils.getParser(string, "req");
|
XmlPullParser parser = PacketParserUtils.getParserFor(string);
|
||||||
|
|
||||||
IQ iq = provider.parseIQ(parser);
|
IQ iq = provider.parseIQ(parser);
|
||||||
assertTrue(iq instanceof HttpOverXmppReq);
|
assertTrue(iq instanceof HttpOverXmppReq);
|
||||||
|
@ -182,7 +182,7 @@ public class AbstractHttpOverXmppProviderTest {
|
||||||
|
|
||||||
private AbstractHttpOverXmpp.AbstractBody parseAbstractBody(String string, String tag) throws Exception {
|
private AbstractHttpOverXmpp.AbstractBody parseAbstractBody(String string, String tag) throws Exception {
|
||||||
AbstractHttpOverXmppProvider provider = new HttpOverXmppRespProvider();
|
AbstractHttpOverXmppProvider provider = new HttpOverXmppRespProvider();
|
||||||
XmlPullParser parser = TestUtils.getParser(string, tag);
|
XmlPullParser parser = PacketParserUtils.getParserFor(string, tag);
|
||||||
|
|
||||||
IQ iq = provider.parseIQ(parser);
|
IQ iq = provider.parseIQ(parser);
|
||||||
assertTrue(iq instanceof HttpOverXmppResp);
|
assertTrue(iq instanceof HttpOverXmppResp);
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
package org.jivesoftware.smackx.hoxt.provider;
|
package org.jivesoftware.smackx.hoxt.provider;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.PacketExtension;
|
import org.jivesoftware.smack.packet.PacketExtension;
|
||||||
import org.jivesoftware.smack.test.util.TestUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.jivesoftware.smackx.hoxt.packet.Base64BinaryChunk;
|
import org.jivesoftware.smackx.hoxt.packet.Base64BinaryChunk;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
@ -35,7 +35,7 @@ public class Base64BinaryChunkProviderTest {
|
||||||
String string = "<chunk xmlns='urn:xmpp:http' streamId='Stream0001'>" + base64Text + "</chunk>";
|
String string = "<chunk xmlns='urn:xmpp:http' streamId='Stream0001'>" + base64Text + "</chunk>";
|
||||||
|
|
||||||
Base64BinaryChunkProvider provider = new Base64BinaryChunkProvider();
|
Base64BinaryChunkProvider provider = new Base64BinaryChunkProvider();
|
||||||
XmlPullParser parser = TestUtils.getParser(string, "chunk");
|
XmlPullParser parser = PacketParserUtils.getParserFor(string);
|
||||||
|
|
||||||
PacketExtension extension = provider.parseExtension(parser);
|
PacketExtension extension = provider.parseExtension(parser);
|
||||||
assertTrue(extension instanceof Base64BinaryChunk);
|
assertTrue(extension instanceof Base64BinaryChunk);
|
||||||
|
@ -52,7 +52,7 @@ public class Base64BinaryChunkProviderTest {
|
||||||
String string = "<chunk xmlns='urn:xmpp:http' streamId='Stream0001' last='true'>" + base64Text + "</chunk>";
|
String string = "<chunk xmlns='urn:xmpp:http' streamId='Stream0001' last='true'>" + base64Text + "</chunk>";
|
||||||
|
|
||||||
Base64BinaryChunkProvider provider = new Base64BinaryChunkProvider();
|
Base64BinaryChunkProvider provider = new Base64BinaryChunkProvider();
|
||||||
XmlPullParser parser = TestUtils.getParser(string, "chunk");
|
XmlPullParser parser = PacketParserUtils.getParserFor(string);
|
||||||
|
|
||||||
PacketExtension extension = provider.parseExtension(parser);
|
PacketExtension extension = provider.parseExtension(parser);
|
||||||
assertTrue(extension instanceof Base64BinaryChunk);
|
assertTrue(extension instanceof Base64BinaryChunk);
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
package org.jivesoftware.smackx.hoxt.provider;
|
package org.jivesoftware.smackx.hoxt.provider;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.test.util.TestUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.jivesoftware.smackx.hoxt.packet.HttpMethod;
|
import org.jivesoftware.smackx.hoxt.packet.HttpMethod;
|
||||||
import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppReq;
|
import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppReq;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -67,7 +67,7 @@ public class HttpOverXmppReqProviderTest {
|
||||||
|
|
||||||
private HttpOverXmppReq.Req parseReq(String string) throws Exception {
|
private HttpOverXmppReq.Req parseReq(String string) throws Exception {
|
||||||
HttpOverXmppReqProvider provider = new HttpOverXmppReqProvider();
|
HttpOverXmppReqProvider provider = new HttpOverXmppReqProvider();
|
||||||
XmlPullParser parser = TestUtils.getParser(string, "req");
|
XmlPullParser parser = PacketParserUtils.getParserFor(string);
|
||||||
IQ iq = provider.parseIQ(parser);
|
IQ iq = provider.parseIQ(parser);
|
||||||
assertTrue(iq instanceof HttpOverXmppReq);
|
assertTrue(iq instanceof HttpOverXmppReq);
|
||||||
HttpOverXmppReq castedIq = (HttpOverXmppReq) iq;
|
HttpOverXmppReq castedIq = (HttpOverXmppReq) iq;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
package org.jivesoftware.smackx.hoxt.provider;
|
package org.jivesoftware.smackx.hoxt.provider;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.test.util.TestUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppResp;
|
import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppResp;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
@ -33,7 +33,7 @@ public class HttpOverXmppRespProviderTest {
|
||||||
public void areAllRespAttributesCorrectlyParsed() throws Exception {
|
public void areAllRespAttributesCorrectlyParsed() throws Exception {
|
||||||
String string = "<resp xmlns='urn:xmpp:http' version='1.1' statusCode='200' statusMessage='OK'/>";
|
String string = "<resp xmlns='urn:xmpp:http' version='1.1' statusCode='200' statusMessage='OK'/>";
|
||||||
HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
|
HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
|
||||||
XmlPullParser parser = TestUtils.getParser(string, "resp");
|
XmlPullParser parser = PacketParserUtils.getParserFor(string);
|
||||||
|
|
||||||
IQ iq = provider.parseIQ(parser);
|
IQ iq = provider.parseIQ(parser);
|
||||||
assertTrue(iq instanceof HttpOverXmppResp);
|
assertTrue(iq instanceof HttpOverXmppResp);
|
||||||
|
@ -49,7 +49,7 @@ public class HttpOverXmppRespProviderTest {
|
||||||
public void areRespAttributesWothoutMessageCorrectlyParsed() throws Exception {
|
public void areRespAttributesWothoutMessageCorrectlyParsed() throws Exception {
|
||||||
String string = "<resp xmlns='urn:xmpp:http' version='1.1' statusCode='200'/>";
|
String string = "<resp xmlns='urn:xmpp:http' version='1.1' statusCode='200'/>";
|
||||||
HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
|
HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
|
||||||
XmlPullParser parser = TestUtils.getParser(string, "resp");
|
XmlPullParser parser = PacketParserUtils.getParserFor(string);
|
||||||
|
|
||||||
IQ iq = provider.parseIQ(parser);
|
IQ iq = provider.parseIQ(parser);
|
||||||
assertTrue(iq instanceof HttpOverXmppResp);
|
assertTrue(iq instanceof HttpOverXmppResp);
|
||||||
|
|
|
@ -22,20 +22,13 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
|
||||||
import org.jivesoftware.smack.provider.IQProvider;
|
|
||||||
import org.jivesoftware.smack.util.Base32Encoder;
|
import org.jivesoftware.smack.util.Base32Encoder;
|
||||||
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.jivesoftware.smack.util.StringEncoder;
|
import org.jivesoftware.smack.util.StringEncoder;
|
||||||
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
||||||
import org.jivesoftware.smackx.disco.provider.DiscoverInfoProvider;
|
|
||||||
import org.xmlpull.v1.XmlPullParserFactory;
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple implementation of an EntityCapsPersistentCache that uses a directory
|
* Simple implementation of an EntityCapsPersistentCache that uses a directory
|
||||||
|
@ -106,7 +99,7 @@ public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache
|
||||||
try {
|
try {
|
||||||
info = restoreInfoFromFile(nodeFile);
|
info = restoreInfoFromFile(nodeFile);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (Exception e) {
|
||||||
LOGGER.log(Level.WARNING, "Coud not restore info from file", e);
|
LOGGER.log(Level.WARNING, "Coud not restore info from file", e);
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
|
@ -147,58 +140,21 @@ public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache
|
||||||
*
|
*
|
||||||
* @param file
|
* @param file
|
||||||
* @return the restored DiscoverInfo
|
* @return the restored DiscoverInfo
|
||||||
* @throws IOException
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private static DiscoverInfo restoreInfoFromFile(File file) throws IOException {
|
private static DiscoverInfo restoreInfoFromFile(File file) throws Exception {
|
||||||
DataInputStream dis = new DataInputStream(new FileInputStream(file));
|
DataInputStream dis = new DataInputStream(new FileInputStream(file));
|
||||||
String fileContent = null;
|
String fileContent = null;
|
||||||
String id;
|
|
||||||
String from;
|
|
||||||
String to;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fileContent = dis.readUTF();
|
fileContent = dis.readUTF();
|
||||||
} finally {
|
} finally {
|
||||||
dis.close();
|
dis.close();
|
||||||
}
|
}
|
||||||
if (fileContent == null)
|
if (fileContent == null) {
|
||||||
return null;
|
|
||||||
|
|
||||||
Reader reader = new StringReader(fileContent);
|
|
||||||
XmlPullParser parser;
|
|
||||||
try {
|
|
||||||
parser = XmlPullParserFactory.newInstance().newPullParser();
|
|
||||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
|
||||||
parser.setInput(reader);
|
|
||||||
} catch (XmlPullParserException xppe) {
|
|
||||||
LOGGER.log(Level.SEVERE, "Exception initializing parser", xppe);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
DiscoverInfo info = (DiscoverInfo) PacketParserUtils.parseStanza(fileContent);
|
||||||
|
|
||||||
DiscoverInfo iqPacket;
|
return info;
|
||||||
IQProvider provider = new DiscoverInfoProvider();
|
|
||||||
|
|
||||||
// Parse the IQ, we only need the id
|
|
||||||
try {
|
|
||||||
parser.next();
|
|
||||||
id = parser.getAttributeValue("", "id");
|
|
||||||
from = parser.getAttributeValue("", "from");
|
|
||||||
to = parser.getAttributeValue("", "to");
|
|
||||||
parser.next();
|
|
||||||
} catch (XmlPullParserException e1) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
iqPacket = (DiscoverInfo) provider.parseIQ(parser);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
iqPacket.setPacketID(id);
|
|
||||||
iqPacket.setFrom(from);
|
|
||||||
iqPacket.setTo(to);
|
|
||||||
iqPacket.setType(IQ.Type.RESULT);
|
|
||||||
return iqPacket;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.util.Base32Encoder;
|
import org.jivesoftware.smack.util.Base32Encoder;
|
||||||
import org.jivesoftware.smack.util.Base64FileUrlEncoder;
|
import org.jivesoftware.smack.util.Base64FileUrlEncoder;
|
||||||
import org.jivesoftware.smack.util.StringEncoder;
|
import org.jivesoftware.smack.util.StringEncoder;
|
||||||
|
import org.jivesoftware.smackx.InitExtensions;
|
||||||
import org.jivesoftware.smackx.caps.EntityCapsManager;
|
import org.jivesoftware.smackx.caps.EntityCapsManager;
|
||||||
import org.jivesoftware.smackx.caps.cache.EntityCapsPersistentCache;
|
import org.jivesoftware.smackx.caps.cache.EntityCapsPersistentCache;
|
||||||
import org.jivesoftware.smackx.caps.cache.SimpleDirectoryPersistentCache;
|
import org.jivesoftware.smackx.caps.cache.SimpleDirectoryPersistentCache;
|
||||||
|
@ -38,7 +39,7 @@ import org.jivesoftware.smackx.xdata.packet.DataForm;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
public class EntityCapsManagerTest {
|
public class EntityCapsManagerTest extends InitExtensions {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <a href="http://xmpp.org/extensions/xep-0115.html#ver-gen-complex">XEP-
|
* <a href="http://xmpp.org/extensions/xep-0115.html#ver-gen-complex">XEP-
|
||||||
|
|
|
@ -28,7 +28,6 @@ import java.util.Properties;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.Presence;
|
import org.jivesoftware.smack.packet.Presence;
|
||||||
import org.jivesoftware.smack.test.util.TestUtils;
|
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.jivesoftware.smack.util.XmppDateTime;
|
import org.jivesoftware.smack.util.XmppDateTime;
|
||||||
import org.jivesoftware.smackx.InitExtensions;
|
import org.jivesoftware.smackx.InitExtensions;
|
||||||
|
@ -65,7 +64,7 @@ public class DelayInformationTest extends InitExtensions {
|
||||||
.t("Offline Storage")
|
.t("Offline Storage")
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
parser = TestUtils.getParser(control, "x");
|
parser = PacketParserUtils.getParserFor(control);
|
||||||
delayInfo = (DelayInformation) p.parseExtension(parser);
|
delayInfo = (DelayInformation) p.parseExtension(parser);
|
||||||
|
|
||||||
assertEquals("capulet.com", delayInfo.getFrom());
|
assertEquals("capulet.com", delayInfo.getFrom());
|
||||||
|
@ -81,7 +80,7 @@ public class DelayInformationTest extends InitExtensions {
|
||||||
.a("stamp", "2002-09-10T23:08:25Z")
|
.a("stamp", "2002-09-10T23:08:25Z")
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
parser = TestUtils.getParser(control, "x");
|
parser = PacketParserUtils.getParserFor(control);
|
||||||
delayInfo = (DelayInformation) p.parseExtension(parser);
|
delayInfo = (DelayInformation) p.parseExtension(parser);
|
||||||
|
|
||||||
assertEquals("capulet.com", delayInfo.getFrom());
|
assertEquals("capulet.com", delayInfo.getFrom());
|
||||||
|
@ -110,7 +109,7 @@ public class DelayInformationTest extends InitExtensions {
|
||||||
.t("Offline Storage")
|
.t("Offline Storage")
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
parser = TestUtils.getParser(control, "delay");
|
parser = PacketParserUtils.getParserFor(control);
|
||||||
delayInfo = (DelayInfo) p.parseExtension(parser);
|
delayInfo = (DelayInfo) p.parseExtension(parser);
|
||||||
|
|
||||||
assertEquals("capulet.com", delayInfo.getFrom());
|
assertEquals("capulet.com", delayInfo.getFrom());
|
||||||
|
@ -126,7 +125,7 @@ public class DelayInformationTest extends InitExtensions {
|
||||||
.a("stamp", "2002-09-10T23:08:25Z")
|
.a("stamp", "2002-09-10T23:08:25Z")
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
parser = TestUtils.getParser(control, "delay");
|
parser = PacketParserUtils.getParserFor(control);
|
||||||
delayInfo = (DelayInfo) p.parseExtension(parser);
|
delayInfo = (DelayInfo) p.parseExtension(parser);
|
||||||
|
|
||||||
assertEquals("capulet.com", delayInfo.getFrom());
|
assertEquals("capulet.com", delayInfo.getFrom());
|
||||||
|
@ -153,7 +152,7 @@ public class DelayInformationTest extends InitExtensions {
|
||||||
.a("stamp", "2002-09-10T23:08:25.12Z")
|
.a("stamp", "2002-09-10T23:08:25.12Z")
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
delayInfo = (DelayInfo) p.parseExtension(TestUtils.getParser(control, "delay"));
|
delayInfo = (DelayInfo) p.parseExtension(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
GregorianCalendar cal = (GregorianCalendar) calendar.clone();
|
GregorianCalendar cal = (GregorianCalendar) calendar.clone();
|
||||||
cal.add(Calendar.MILLISECOND, 12);
|
cal.add(Calendar.MILLISECOND, 12);
|
||||||
|
@ -166,7 +165,7 @@ public class DelayInformationTest extends InitExtensions {
|
||||||
.a("stamp", "2002-09-10T23:08:25Z")
|
.a("stamp", "2002-09-10T23:08:25Z")
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
delayInfo = (DelayInfo) p.parseExtension(TestUtils.getParser(control, "delay"));
|
delayInfo = (DelayInfo) p.parseExtension(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(calendar.getTime(), delayInfo.getStamp());
|
assertEquals(calendar.getTime(), delayInfo.getStamp());
|
||||||
|
|
||||||
|
@ -177,7 +176,7 @@ public class DelayInformationTest extends InitExtensions {
|
||||||
.a("stamp", "2002-9-10T23:08:25Z")
|
.a("stamp", "2002-9-10T23:08:25Z")
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
delayInfo = (DelayInfo) p.parseExtension(TestUtils.getParser(control, "delay"));
|
delayInfo = (DelayInfo) p.parseExtension(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(calendar.getTime(), delayInfo.getStamp());
|
assertEquals(calendar.getTime(), delayInfo.getStamp());
|
||||||
|
|
||||||
|
@ -188,7 +187,7 @@ public class DelayInformationTest extends InitExtensions {
|
||||||
.a("stamp", "20020910T23:08:25")
|
.a("stamp", "20020910T23:08:25")
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
delayInfo = (DelayInfo) p.parseExtension(TestUtils.getParser(control, "delay"));
|
delayInfo = (DelayInfo) p.parseExtension(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(calendar.getTime(), delayInfo.getStamp());
|
assertEquals(calendar.getTime(), delayInfo.getStamp());
|
||||||
|
|
||||||
|
@ -208,7 +207,7 @@ public class DelayInformationTest extends InitExtensions {
|
||||||
.a("stamp", dateFormat.format(dateInPast.getTime()))
|
.a("stamp", dateFormat.format(dateInPast.getTime()))
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
delayInfo = (DelayInfo) p.parseExtension(TestUtils.getParser(control, "delay"));
|
delayInfo = (DelayInfo) p.parseExtension(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertEquals(dateInPast.getTime(), delayInfo.getStamp());
|
assertEquals(dateInPast.getTime(), delayInfo.getStamp());
|
||||||
|
|
||||||
|
@ -219,7 +218,7 @@ public class DelayInformationTest extends InitExtensions {
|
||||||
.a("stamp", "200868T09:16:20")
|
.a("stamp", "200868T09:16:20")
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
delayInfo = (DelayInfo) p.parseExtension(TestUtils.getParser(control, "delay"));
|
delayInfo = (DelayInfo) p.parseExtension(PacketParserUtils.getParserFor(control));
|
||||||
Date controlDate = XmppDateTime.parseDate("2008-06-08T09:16:20.0Z");
|
Date controlDate = XmppDateTime.parseDate("2008-06-08T09:16:20.0Z");
|
||||||
|
|
||||||
assertEquals(controlDate, delayInfo.getStamp());
|
assertEquals(controlDate, delayInfo.getStamp());
|
||||||
|
@ -231,7 +230,7 @@ public class DelayInformationTest extends InitExtensions {
|
||||||
.a("stamp", "yesterday")
|
.a("stamp", "yesterday")
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
delayInfo = (DelayInfo) p.parseExtension(TestUtils.getParser(control, "delay"));
|
delayInfo = (DelayInfo) p.parseExtension(PacketParserUtils.getParserFor(control));
|
||||||
|
|
||||||
assertNotNull(delayInfo.getStamp());
|
assertNotNull(delayInfo.getStamp());
|
||||||
|
|
||||||
|
@ -242,7 +241,7 @@ public class DelayInformationTest extends InitExtensions {
|
||||||
String stanza = "<presence from='mercutio@example.com' to='juliet@example.com'>"
|
String stanza = "<presence from='mercutio@example.com' to='juliet@example.com'>"
|
||||||
+ "<delay xmlns='urn:xmpp:delay' stamp='2002-09-10T23:41:07Z'/></presence>";
|
+ "<delay xmlns='urn:xmpp:delay' stamp='2002-09-10T23:41:07Z'/></presence>";
|
||||||
|
|
||||||
Presence presence = PacketParserUtils.parsePresence(TestUtils.getPresenceParser(stanza));
|
Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza));
|
||||||
|
|
||||||
DelayInformation delay = (DelayInformation) presence.getExtension("urn:xmpp:delay");
|
DelayInformation delay = (DelayInformation) presence.getExtension("urn:xmpp:delay");
|
||||||
assertNotNull(delay);
|
assertNotNull(delay);
|
||||||
|
@ -255,7 +254,7 @@ public class DelayInformationTest extends InitExtensions {
|
||||||
String stanza = "<presence from='mercutio@example.com' to='juliet@example.com'>"
|
String stanza = "<presence from='mercutio@example.com' to='juliet@example.com'>"
|
||||||
+ "<x xmlns='jabber:x:delay' stamp='20020910T23:41:07'/></presence>";
|
+ "<x xmlns='jabber:x:delay' stamp='20020910T23:41:07'/></presence>";
|
||||||
|
|
||||||
Presence presence = PacketParserUtils.parsePresence(TestUtils.getPresenceParser(stanza));
|
Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza));
|
||||||
|
|
||||||
DelayInformation delay = (DelayInformation) presence.getExtension("jabber:x:delay");
|
DelayInformation delay = (DelayInformation) presence.getExtension("jabber:x:delay");
|
||||||
assertNotNull(delay);
|
assertNotNull(delay);
|
||||||
|
@ -271,7 +270,7 @@ public class DelayInformationTest extends InitExtensions {
|
||||||
String stanza = "<presence from='mercutio@example.com' to='juliet@example.com'>"
|
String stanza = "<presence from='mercutio@example.com' to='juliet@example.com'>"
|
||||||
+ "<x xmlns='jabber:x:delay'/></presence>";
|
+ "<x xmlns='jabber:x:delay'/></presence>";
|
||||||
|
|
||||||
Presence presence = PacketParserUtils.parsePresence(TestUtils.getPresenceParser(stanza));
|
Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza));
|
||||||
DelayInformation delay = (DelayInformation) presence.getExtension("urn:xmpp:delay");
|
DelayInformation delay = (DelayInformation) presence.getExtension("urn:xmpp:delay");
|
||||||
assertNull((Object)delay);
|
assertNull((Object)delay);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,13 @@ package org.jivesoftware.smackx.forward;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import org.jivesoftware.smack.test.util.TestUtils;
|
|
||||||
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.jivesoftware.smackx.forward.Forwarded;
|
import org.jivesoftware.smackx.forward.Forwarded;
|
||||||
import org.jivesoftware.smackx.forward.provider.ForwardedProvider;
|
import org.jivesoftware.smackx.forward.provider.ForwardedProvider;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
|
||||||
import com.jamesmurty.utils.XMLBuilder;
|
import com.jamesmurty.utils.XMLBuilder;
|
||||||
|
|
||||||
public class ForwardedTest {
|
public class ForwardedTest {
|
||||||
|
@ -45,7 +47,7 @@ public class ForwardedTest {
|
||||||
.a("from", "romeo@montague.com")
|
.a("from", "romeo@montague.com")
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
parser = TestUtils.getParser(control, "forwarded");
|
parser = PacketParserUtils.getParserFor(control);
|
||||||
fwd = (Forwarded) new ForwardedProvider().parseExtension(parser);
|
fwd = (Forwarded) new ForwardedProvider().parseExtension(parser);
|
||||||
|
|
||||||
// no delay in packet
|
// no delay in packet
|
||||||
|
@ -69,7 +71,7 @@ public class ForwardedTest {
|
||||||
.a("xmlns", "urn:xmpp:forwarded:0")
|
.a("xmlns", "urn:xmpp:forwarded:0")
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
parser = TestUtils.getParser(control, "forwarded");
|
parser = PacketParserUtils.getParserFor(control);
|
||||||
new ForwardedProvider().parseExtension(parser);
|
new ForwardedProvider().parseExtension(parser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ import static org.junit.Assert.assertTrue;
|
||||||
import org.jivesoftware.smack.DummyConnection;
|
import org.jivesoftware.smack.DummyConnection;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.test.util.TestUtils;
|
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.jivesoftware.smackx.InitExtensions;
|
import org.jivesoftware.smackx.InitExtensions;
|
||||||
import org.jivesoftware.smackx.iqlast.packet.LastActivity;
|
import org.jivesoftware.smackx.iqlast.packet.LastActivity;
|
||||||
|
@ -43,7 +42,7 @@ public class LastActivityTest extends InitExtensions {
|
||||||
.namespace(LastActivity.NAMESPACE);
|
.namespace(LastActivity.NAMESPACE);
|
||||||
|
|
||||||
DummyConnection c = new DummyConnection();
|
DummyConnection c = new DummyConnection();
|
||||||
IQ lastRequest = PacketParserUtils.parseIQ(TestUtils.getIQParser(xml.asString()), c);
|
IQ lastRequest = (IQ) PacketParserUtils.parseStanza(xml.asString());
|
||||||
assertTrue(lastRequest instanceof LastActivity);
|
assertTrue(lastRequest instanceof LastActivity);
|
||||||
|
|
||||||
c.processPacket(lastRequest);;
|
c.processPacket(lastRequest);;
|
||||||
|
|
|
@ -22,7 +22,6 @@ import static org.junit.Assert.assertTrue;
|
||||||
import org.jivesoftware.smack.DummyConnection;
|
import org.jivesoftware.smack.DummyConnection;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.test.util.TestUtils;
|
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.jivesoftware.smackx.iqversion.packet.Version;
|
import org.jivesoftware.smackx.iqversion.packet.Version;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -39,7 +38,7 @@ public class VersionTest {
|
||||||
|
|
||||||
// Enable version replys for this connection
|
// Enable version replys for this connection
|
||||||
VersionManager.getInstanceFor(con).setVersion(new Version("Test", "0.23", "DummyOS"));
|
VersionManager.getInstanceFor(con).setVersion(new Version("Test", "0.23", "DummyOS"));
|
||||||
IQ versionRequest = PacketParserUtils.parseIQ(TestUtils.getIQParser(control), con);
|
IQ versionRequest = (IQ) PacketParserUtils.parseStanza(control);
|
||||||
|
|
||||||
assertTrue(versionRequest instanceof Version);
|
assertTrue(versionRequest instanceof Version);
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
import org.jivesoftware.smack.test.util.TestUtils;
|
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.jivesoftware.smackx.InitExtensions;
|
import org.jivesoftware.smackx.InitExtensions;
|
||||||
import org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension;
|
import org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension;
|
||||||
|
@ -54,7 +53,7 @@ public class JivePropertiesExtensionTest extends InitExtensions {
|
||||||
+ "</message>";
|
+ "</message>";
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
||||||
Message message = PacketParserUtils.parseMessage(TestUtils.getMessageParser(properties));
|
Message message = (Message) PacketParserUtils.parseStanza(properties);
|
||||||
JivePropertiesExtension jpe = (JivePropertiesExtension) message.getExtension(JivePropertiesExtension.NAMESPACE);
|
JivePropertiesExtension jpe = (JivePropertiesExtension) message.getExtension(JivePropertiesExtension.NAMESPACE);
|
||||||
assertNotNull(jpe);
|
assertNotNull(jpe);
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||||
import org.jivesoftware.smack.ThreadedDummyConnection;
|
import org.jivesoftware.smack.ThreadedDummyConnection;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.test.util.TestUtils;
|
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.jivesoftware.smackx.InitExtensions;
|
import org.jivesoftware.smackx.InitExtensions;
|
||||||
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
||||||
|
@ -57,7 +56,7 @@ public class PingTest extends InitExtensions {
|
||||||
|
|
||||||
// Enable ping for this connection
|
// Enable ping for this connection
|
||||||
PingManager.getInstanceFor(con);
|
PingManager.getInstanceFor(con);
|
||||||
IQ pingRequest = PacketParserUtils.parseIQ(TestUtils.getIQParser(control), con);
|
IQ pingRequest = (IQ) PacketParserUtils.parseStanza(control);
|
||||||
|
|
||||||
assertTrue(pingRequest instanceof Ping);
|
assertTrue(pingRequest instanceof Ping);
|
||||||
|
|
||||||
|
@ -133,7 +132,7 @@ public class PingTest extends InitExtensions {
|
||||||
"</error>" +
|
"</error>" +
|
||||||
"</iq>";
|
"</iq>";
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
IQ serviceUnavailable = PacketParserUtils.parseIQ(TestUtils.getIQParser(reply), threadedCon);
|
IQ serviceUnavailable = (IQ) PacketParserUtils.parseStanza(reply);
|
||||||
threadedCon.addIQReply(serviceUnavailable);
|
threadedCon.addIQReply(serviceUnavailable);
|
||||||
|
|
||||||
PingManager pinger = PingManager.getInstanceFor(threadedCon);
|
PingManager pinger = PingManager.getInstanceFor(threadedCon);
|
||||||
|
@ -169,7 +168,7 @@ public class PingTest extends InitExtensions {
|
||||||
"</error>" +
|
"</error>" +
|
||||||
"</iq>";
|
"</iq>";
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
IQ serviceUnavailable = PacketParserUtils.parseIQ(TestUtils.getIQParser(reply), con);
|
IQ serviceUnavailable = (IQ) PacketParserUtils.parseStanza(reply);
|
||||||
con.addIQReply(serviceUnavailable);
|
con.addIQReply(serviceUnavailable);
|
||||||
|
|
||||||
PingManager pinger = PingManager.getInstanceFor(con);
|
PingManager pinger = PingManager.getInstanceFor(con);
|
||||||
|
@ -201,7 +200,7 @@ public class PingTest extends InitExtensions {
|
||||||
"<feature var='urn:xmpp:ping'/>" +
|
"<feature var='urn:xmpp:ping'/>" +
|
||||||
"</query></iq>";
|
"</query></iq>";
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
IQ discoReply = PacketParserUtils.parseIQ(TestUtils.getIQParser(reply), con);
|
IQ discoReply = (IQ) PacketParserUtils.parseStanza(reply);
|
||||||
con.addIQReply(discoReply);
|
con.addIQReply(discoReply);
|
||||||
|
|
||||||
PingManager pinger = PingManager.getInstanceFor(con);
|
PingManager pinger = PingManager.getInstanceFor(con);
|
||||||
|
@ -223,7 +222,7 @@ public class PingTest extends InitExtensions {
|
||||||
"<feature var='urn:xmpp:noping'/>" +
|
"<feature var='urn:xmpp:noping'/>" +
|
||||||
"</query></iq>";
|
"</query></iq>";
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
IQ discoReply = PacketParserUtils.parseIQ(TestUtils.getIQParser(reply), con);
|
IQ discoReply = (IQ) PacketParserUtils.parseStanza(reply);
|
||||||
con.addIQReply(discoReply);
|
con.addIQReply(discoReply);
|
||||||
|
|
||||||
PingManager pinger = PingManager.getInstanceFor(con);
|
PingManager pinger = PingManager.getInstanceFor(con);
|
||||||
|
|
|
@ -21,9 +21,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.jivesoftware.smack.DummyConnection;
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.test.util.TestUtils;
|
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.jivesoftware.smackx.InitExtensions;
|
import org.jivesoftware.smackx.InitExtensions;
|
||||||
import org.jivesoftware.smackx.privacy.packet.Privacy;
|
import org.jivesoftware.smackx.privacy.packet.Privacy;
|
||||||
|
@ -34,8 +32,6 @@ public class PrivacyProviderTest extends InitExtensions {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parsePrivacyList() throws Exception {
|
public void parsePrivacyList() throws Exception {
|
||||||
DummyConnection connection = new DummyConnection();
|
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
final String xmlPrivacyList =
|
final String xmlPrivacyList =
|
||||||
"<iq type='result' id='getlist2' to='romeo@example.net/orchard'>"
|
"<iq type='result' id='getlist2' to='romeo@example.net/orchard'>"
|
||||||
|
@ -50,7 +46,7 @@ public class PrivacyProviderTest extends InitExtensions {
|
||||||
+ "</query>"
|
+ "</query>"
|
||||||
+ "</iq>";
|
+ "</iq>";
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
IQ iqPrivacyList = PacketParserUtils.parseIQ(TestUtils.getIQParser(xmlPrivacyList), connection);
|
IQ iqPrivacyList = (IQ) PacketParserUtils.parseStanza(xmlPrivacyList);
|
||||||
assertTrue(iqPrivacyList instanceof Privacy);
|
assertTrue(iqPrivacyList instanceof Privacy);
|
||||||
|
|
||||||
Privacy privacyList = (Privacy) iqPrivacyList;
|
Privacy privacyList = (Privacy) iqPrivacyList;
|
||||||
|
|
|
@ -23,7 +23,6 @@ import static org.junit.Assert.assertTrue;
|
||||||
import org.jivesoftware.smack.ThreadedDummyConnection;
|
import org.jivesoftware.smack.ThreadedDummyConnection;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.packet.PacketExtension;
|
import org.jivesoftware.smack.packet.PacketExtension;
|
||||||
import org.jivesoftware.smack.test.util.TestUtils;
|
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.jivesoftware.smackx.InitExtensions;
|
import org.jivesoftware.smackx.InitExtensions;
|
||||||
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
|
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
|
||||||
|
@ -95,7 +94,7 @@ public class ItemValidationTest extends InitExtensions {
|
||||||
@Test
|
@Test
|
||||||
public void parseBasicItem() throws Exception
|
public void parseBasicItem() throws Exception
|
||||||
{
|
{
|
||||||
XmlPullParser parser = TestUtils.getMessageParser(
|
XmlPullParser parser = PacketParserUtils.getParserFor(
|
||||||
"<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" +
|
"<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" +
|
||||||
"<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
|
"<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
|
||||||
"<items node='testNode'>" +
|
"<items node='testNode'>" +
|
||||||
|
@ -124,7 +123,7 @@ public class ItemValidationTest extends InitExtensions {
|
||||||
{
|
{
|
||||||
String itemContent = "<foo xmlns='smack:test'>Some text</foo>";
|
String itemContent = "<foo xmlns='smack:test'>Some text</foo>";
|
||||||
|
|
||||||
XmlPullParser parser = TestUtils.getMessageParser(
|
XmlPullParser parser = PacketParserUtils.getParserFor(
|
||||||
"<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" +
|
"<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" +
|
||||||
"<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
|
"<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
|
||||||
"<items node='testNode'>" +
|
"<items node='testNode'>" +
|
||||||
|
@ -171,7 +170,7 @@ public class ItemValidationTest extends InitExtensions {
|
||||||
"<updated>2003-12-13T18:30:02Z</updated>" +
|
"<updated>2003-12-13T18:30:02Z</updated>" +
|
||||||
"</entry>";
|
"</entry>";
|
||||||
|
|
||||||
XmlPullParser parser = TestUtils.getMessageParser(
|
XmlPullParser parser = PacketParserUtils.getParserFor(
|
||||||
"<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" +
|
"<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" +
|
||||||
"<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
|
"<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
|
||||||
"<items node='testNode'>" +
|
"<items node='testNode'>" +
|
||||||
|
@ -204,7 +203,7 @@ public class ItemValidationTest extends InitExtensions {
|
||||||
{
|
{
|
||||||
String itemContent = "<foo xmlns='smack:test'><bar/></foo>";
|
String itemContent = "<foo xmlns='smack:test'><bar/></foo>";
|
||||||
|
|
||||||
XmlPullParser parser = TestUtils.getMessageParser(
|
XmlPullParser parser = PacketParserUtils.getParserFor(
|
||||||
"<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" +
|
"<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" +
|
||||||
"<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
|
"<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
|
||||||
"<items node='testNode'>" +
|
"<items node='testNode'>" +
|
||||||
|
|
|
@ -26,7 +26,6 @@ import java.util.Properties;
|
||||||
import org.jivesoftware.smack.DummyConnection;
|
import org.jivesoftware.smack.DummyConnection;
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.test.util.TestUtils;
|
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.jivesoftware.smackx.InitExtensions;
|
import org.jivesoftware.smackx.InitExtensions;
|
||||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
|
@ -53,7 +52,7 @@ public class DeliveryReceiptTest extends InitExtensions {
|
||||||
.a("xmlns", "urn:xmpp:receipts")
|
.a("xmlns", "urn:xmpp:receipts")
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
parser = TestUtils.getMessageParser(control);
|
parser = PacketParserUtils.getParserFor(control);
|
||||||
Packet p = PacketParserUtils.parseMessage(parser);
|
Packet p = PacketParserUtils.parseMessage(parser);
|
||||||
|
|
||||||
DeliveryReceiptRequest drr = (DeliveryReceiptRequest)p.getExtension(
|
DeliveryReceiptRequest drr = (DeliveryReceiptRequest)p.getExtension(
|
||||||
|
|
|
@ -23,9 +23,7 @@ import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.jivesoftware.smack.DummyConnection;
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.test.util.TestUtils;
|
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.jivesoftware.smackx.InitExtensions;
|
import org.jivesoftware.smackx.InitExtensions;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -63,8 +61,6 @@ public class TimeTest extends InitExtensions {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseTimeWithIntrospectionTest() throws Exception {
|
public void parseTimeWithIntrospectionTest() throws Exception {
|
||||||
DummyConnection connection = new DummyConnection();
|
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
final String request =
|
final String request =
|
||||||
"<iq type='get'"
|
"<iq type='get'"
|
||||||
|
@ -74,7 +70,7 @@ public class TimeTest extends InitExtensions {
|
||||||
+ "<time xmlns='urn:xmpp:time'/>"
|
+ "<time xmlns='urn:xmpp:time'/>"
|
||||||
+ "</iq>";
|
+ "</iq>";
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
IQ iqRequest = PacketParserUtils.parseIQ(TestUtils.getIQParser(request), connection);
|
IQ iqRequest = (IQ) PacketParserUtils.parseStanza(request);
|
||||||
assertTrue(iqRequest instanceof Time);
|
assertTrue(iqRequest instanceof Time);
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
|
@ -89,7 +85,7 @@ public class TimeTest extends InitExtensions {
|
||||||
+ "</time>"
|
+ "</time>"
|
||||||
+ "</iq>";
|
+ "</iq>";
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
IQ iqResponse = PacketParserUtils.parseIQ(TestUtils.getIQParser(response), connection);
|
IQ iqResponse = (IQ) PacketParserUtils.parseStanza(response);
|
||||||
assertTrue(iqResponse instanceof Time);
|
assertTrue(iqResponse instanceof Time);
|
||||||
Time time = (Time) iqResponse;
|
Time time = (Time) iqResponse;
|
||||||
assertEquals("-06:00", time.getTzo());
|
assertEquals("-06:00", time.getTzo());
|
||||||
|
|
|
@ -19,9 +19,7 @@ package org.jivesoftware.smack.tcp;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.packet.Presence;
|
|
||||||
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
|
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
|
||||||
import org.jivesoftware.smack.parsing.UnparsablePacket;
|
import org.jivesoftware.smack.parsing.UnparsablePacket;
|
||||||
import org.jivesoftware.smack.sasl.SASLMechanism.Challenge;
|
import org.jivesoftware.smack.sasl.SASLMechanism.Challenge;
|
||||||
|
@ -151,52 +149,25 @@ class PacketReader {
|
||||||
do {
|
do {
|
||||||
if (eventType == XmlPullParser.START_TAG) {
|
if (eventType == XmlPullParser.START_TAG) {
|
||||||
int parserDepth = parser.getDepth();
|
int parserDepth = parser.getDepth();
|
||||||
|
String name = parser.getName();
|
||||||
ParsingExceptionCallback callback = connection.getParsingExceptionCallback();
|
ParsingExceptionCallback callback = connection.getParsingExceptionCallback();
|
||||||
if (parser.getName().equals("message")) {
|
Packet packet;
|
||||||
Packet packet;
|
try {
|
||||||
try {
|
packet = PacketParserUtils.parseStanza(parser, connection);
|
||||||
packet = PacketParserUtils.parseMessage(parser);
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
String content = PacketParserUtils.parseContentDepth(parser, parserDepth);
|
||||||
String content = PacketParserUtils.parseContentDepth(parser, parserDepth);
|
UnparsablePacket message = new UnparsablePacket(content, e);
|
||||||
UnparsablePacket message = new UnparsablePacket(content, e);
|
if (callback != null) {
|
||||||
if (callback != null) {
|
callback.handleUnparsablePacket(message);
|
||||||
callback.handleUnparsablePacket(message);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (packet != null) {
|
||||||
connection.processPacket(packet);
|
connection.processPacket(packet);
|
||||||
}
|
}
|
||||||
else if (parser.getName().equals("iq")) {
|
|
||||||
IQ iq;
|
|
||||||
try {
|
|
||||||
iq = PacketParserUtils.parseIQ(parser, connection);
|
|
||||||
} catch (Exception e) {
|
|
||||||
String content = PacketParserUtils.parseContentDepth(parser, parserDepth);
|
|
||||||
UnparsablePacket message = new UnparsablePacket(content, e);
|
|
||||||
if (callback != null) {
|
|
||||||
callback.handleUnparsablePacket(message);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
connection.processPacket(iq);
|
|
||||||
}
|
|
||||||
else if (parser.getName().equals("presence")) {
|
|
||||||
Presence presence;
|
|
||||||
try {
|
|
||||||
presence = PacketParserUtils.parsePresence(parser);
|
|
||||||
} catch (Exception e) {
|
|
||||||
String content = PacketParserUtils.parseContentDepth(parser, parserDepth);
|
|
||||||
UnparsablePacket message = new UnparsablePacket(content, e);
|
|
||||||
if (callback != null) {
|
|
||||||
callback.handleUnparsablePacket(message);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
connection.processPacket(presence);
|
|
||||||
}
|
|
||||||
// We found an opening stream. Record information about it, then notify
|
// We found an opening stream. Record information about it, then notify
|
||||||
// the connectionID lock so that the packet reader startup can finish.
|
// the connectionID lock so that the packet reader startup can finish.
|
||||||
else if (parser.getName().equals("stream")) {
|
else if (name.equals("stream")) {
|
||||||
// Ensure the correct jabber:client namespace is being used.
|
// Ensure the correct jabber:client namespace is being used.
|
||||||
if ("jabber:client".equals(parser.getNamespace(null))) {
|
if ("jabber:client".equals(parser.getNamespace(null))) {
|
||||||
// Get the connection id.
|
// Get the connection id.
|
||||||
|
@ -212,20 +183,20 @@ class PacketReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (parser.getName().equals("error")) {
|
else if (name.equals("error")) {
|
||||||
throw new StreamErrorException(PacketParserUtils.parseStreamError(parser));
|
throw new StreamErrorException(PacketParserUtils.parseStreamError(parser));
|
||||||
}
|
}
|
||||||
else if (parser.getName().equals("features")) {
|
else if (name.equals("features")) {
|
||||||
parseFeatures(parser);
|
parseFeatures(parser);
|
||||||
}
|
}
|
||||||
else if (parser.getName().equals("proceed")) {
|
else if (name.equals("proceed")) {
|
||||||
// Secure the connection by negotiating TLS
|
// Secure the connection by negotiating TLS
|
||||||
connection.proceedTLSReceived();
|
connection.proceedTLSReceived();
|
||||||
// Reset the state of the parser since a new stream element is going
|
// Reset the state of the parser since a new stream element is going
|
||||||
// to be sent by the server
|
// to be sent by the server
|
||||||
resetParser();
|
resetParser();
|
||||||
}
|
}
|
||||||
else if (parser.getName().equals("failure")) {
|
else if (name.equals("failure")) {
|
||||||
String namespace = parser.getNamespace(null);
|
String namespace = parser.getNamespace(null);
|
||||||
if ("urn:ietf:params:xml:ns:xmpp-tls".equals(namespace)) {
|
if ("urn:ietf:params:xml:ns:xmpp-tls".equals(namespace)) {
|
||||||
// TLS negotiation has failed. The server will close the connection
|
// TLS negotiation has failed. The server will close the connection
|
||||||
|
@ -245,13 +216,13 @@ class PacketReader {
|
||||||
connection.getSASLAuthentication().authenticationFailed(failure);
|
connection.getSASLAuthentication().authenticationFailed(failure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (parser.getName().equals("challenge")) {
|
else if (name.equals("challenge")) {
|
||||||
// The server is challenging the SASL authentication made by the client
|
// The server is challenging the SASL authentication made by the client
|
||||||
String challengeData = parser.nextText();
|
String challengeData = parser.nextText();
|
||||||
connection.processPacket(new Challenge(challengeData));
|
connection.processPacket(new Challenge(challengeData));
|
||||||
connection.getSASLAuthentication().challengeReceived(challengeData);
|
connection.getSASLAuthentication().challengeReceived(challengeData);
|
||||||
}
|
}
|
||||||
else if (parser.getName().equals("success")) {
|
else if (name.equals("success")) {
|
||||||
connection.processPacket(new Success(parser.nextText()));
|
connection.processPacket(new Success(parser.nextText()));
|
||||||
// We now need to bind a resource for the connection
|
// We now need to bind a resource for the connection
|
||||||
// Open a new stream and wait for the response
|
// Open a new stream and wait for the response
|
||||||
|
@ -263,7 +234,7 @@ class PacketReader {
|
||||||
// will be to bind the resource
|
// will be to bind the resource
|
||||||
connection.getSASLAuthentication().authenticated();
|
connection.getSASLAuthentication().authenticated();
|
||||||
}
|
}
|
||||||
else if (parser.getName().equals("compressed")) {
|
else if (name.equals("compressed")) {
|
||||||
// Server confirmed that it's possible to use stream compression. Start
|
// Server confirmed that it's possible to use stream compression. Start
|
||||||
// stream compression
|
// stream compression
|
||||||
connection.startStreamCompression();
|
connection.startStreamCompression();
|
||||||
|
|
Loading…
Reference in a new issue