mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-15 03:59:38 +02:00
Enable PacketExtensions for IQs
This is actually only part one, i.e. with this commit if the user adds a PacketExtension to an IQ it will be included in IQ.toXml(). Which was previously only the case if the IQ subclass explicitly included packet extensions. The second part of the change is to change the IQ provider, so that packet extensions are automatically parsed. Cases where PacketExtensions are used for Message and IQ are slightly changed. The IQ sublcass now only has a field with this PacketExtension (see for example bytestreams.ibb.packet.DataPacketExtension). Also changed hoxt API: Removed unnecessary indirection and made the API more Smack idiomatic.
This commit is contained in:
parent
a9c798f3bb
commit
9e797c1b17
93 changed files with 1347 additions and 1438 deletions
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.bytestreams.ibb;
|
||||
|
||||
import org.jivesoftware.smack.packet.EmptyResultIQ;
|
||||
import org.jivesoftware.smack.packet.ErrorIQ;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
|
||||
|
@ -35,17 +37,10 @@ public class IBBPacketUtils {
|
|||
* @return an error IQ
|
||||
*/
|
||||
public static IQ createErrorIQ(String from, String to, XMPPError xmppError) {
|
||||
IQ errorIQ = new IQ() {
|
||||
|
||||
public String getChildElementXML() {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
IQ errorIQ = new ErrorIQ(xmppError);
|
||||
errorIQ.setType(IQ.Type.error);
|
||||
errorIQ.setFrom(from);
|
||||
errorIQ.setTo(to);
|
||||
errorIQ.setError(xmppError);
|
||||
return errorIQ;
|
||||
}
|
||||
|
||||
|
@ -57,13 +52,7 @@ public class IBBPacketUtils {
|
|||
* @return a result IQ
|
||||
*/
|
||||
public static IQ createResultIQ(String from, String to) {
|
||||
IQ result = new IQ() {
|
||||
|
||||
public String getChildElementXML() {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
IQ result = new EmptyResultIQ();
|
||||
result.setType(IQ.Type.result);
|
||||
result.setFrom(from);
|
||||
result.setTo(to);
|
||||
|
|
|
@ -64,8 +64,8 @@ public class CloseTest {
|
|||
@Test
|
||||
public void shouldReturnValidIQStanzaXML() throws Exception {
|
||||
String control = XMLBuilder.create("iq")
|
||||
.a("from", "romeo@montague.lit/orchard")
|
||||
.a("to", "juliet@capulet.lit/balcony")
|
||||
.a("from", "romeo@montague.lit/orchard")
|
||||
.a("id", "us71g45j")
|
||||
.a("type", "set")
|
||||
.e("close")
|
||||
|
|
|
@ -19,12 +19,10 @@ package org.jivesoftware.smackx.bytestreams.ibb.packet;
|
|||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -70,16 +68,7 @@ public class DataTest {
|
|||
.t(encodedData)
|
||||
.asString(outputProperties);
|
||||
|
||||
DataPacketExtension dpe = mock(DataPacketExtension.class);
|
||||
XmlStringBuilder dataTag = new XmlStringBuilder();
|
||||
dataTag.halfOpenElement(DataPacketExtension.ELEMENT);
|
||||
dataTag.xmlnsAttribute(DataPacketExtension.NAMESPACE);
|
||||
dataTag.attribute("seq", "0");
|
||||
dataTag.attribute("sid", "i781hf64");
|
||||
dataTag.rightAngleBracket();
|
||||
dataTag.escape(encodedData);
|
||||
dataTag.closeElement(DataPacketExtension.ELEMENT);
|
||||
when(dpe.toXML()).thenReturn(dataTag);
|
||||
DataPacketExtension dpe = new DataPacketExtension("i781hf64", 0, encodedData);
|
||||
Data data = new Data(dpe);
|
||||
data.setFrom("romeo@montague.lit/orchard");
|
||||
data.setTo("juliet@capulet.lit/balcony");
|
||||
|
|
|
@ -34,9 +34,9 @@ import org.jivesoftware.smack.SmackException.FeatureNotSupportedException;
|
|||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smack.packet.ErrorIQ;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.packet.IQ.Type;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
|
@ -426,14 +426,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
|
||||
// build error packet to reject SOCKS5 Bytestream
|
||||
XMPPError xmppError = new XMPPError(XMPPError.Condition.not_acceptable);
|
||||
IQ rejectPacket = new IQ() {
|
||||
|
||||
public String getChildElementXML() {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
rejectPacket.setType(Type.error);
|
||||
IQ rejectPacket = new ErrorIQ(xmppError);
|
||||
rejectPacket.setFrom(targetJID);
|
||||
rejectPacket.setTo(initiatorJID);
|
||||
rejectPacket.setError(xmppError);
|
||||
|
|
|
@ -30,9 +30,10 @@ import org.jivesoftware.smack.SmackException;
|
|||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smack.packet.EmptyResultIQ;
|
||||
import org.jivesoftware.smack.packet.ErrorIQ;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.packet.IQ.Type;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
|
||||
import org.jivesoftware.util.ConnectionUtils;
|
||||
|
@ -197,17 +198,9 @@ public class Socks5ClientForInitiatorTest {
|
|||
|
||||
// build error response as reply to the stream activation
|
||||
XMPPError xmppError = new XMPPError(XMPPError.Condition.internal_server_error);
|
||||
IQ error = new IQ() {
|
||||
|
||||
public String getChildElementXML() {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
error.setType(Type.error);
|
||||
IQ error = new ErrorIQ(xmppError);
|
||||
error.setFrom(proxyJID);
|
||||
error.setTo(initiatorJID);
|
||||
error.setError(xmppError);
|
||||
|
||||
protocol.addResponse(error, Verification.correspondingSenderReceiver,
|
||||
Verification.requestTypeSET);
|
||||
|
@ -249,17 +242,10 @@ public class Socks5ClientForInitiatorTest {
|
|||
public void shouldSuccessfullyEstablishConnectionAndActivateSocks5Proxy() throws Exception {
|
||||
|
||||
// build activation confirmation response
|
||||
IQ activationResponse = new IQ() {
|
||||
IQ activationResponse = new EmptyResultIQ();
|
||||
|
||||
@Override
|
||||
public String getChildElementXML() {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
activationResponse.setFrom(proxyJID);
|
||||
activationResponse.setTo(initiatorJID);
|
||||
activationResponse.setType(IQ.Type.result);
|
||||
|
||||
protocol.addResponse(activationResponse, Verification.correspondingSenderReceiver,
|
||||
Verification.requestTypeSET, new Verification<Bytestream, IQ>() {
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.bytestreams.socks5;
|
||||
|
||||
import org.jivesoftware.smack.packet.EmptyResultIQ;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
||||
|
@ -100,17 +101,9 @@ public class Socks5PacketUtils {
|
|||
* @return response IQ for a activation request to the proxy
|
||||
*/
|
||||
public static IQ createActivationConfirmation(String from, String to) {
|
||||
IQ response = new IQ() {
|
||||
|
||||
@Override
|
||||
public String getChildElementXML() {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
IQ response = new EmptyResultIQ();
|
||||
response.setFrom(from);
|
||||
response.setTo(to);
|
||||
response.setType(IQ.Type.result);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue