1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 20:12:07 +01:00

Introduce packet.Element

Re-work filetransfer/bytestream stanza toXML() method to use
XmlStringBuilder. Move the ELEMENT and NAMESPACE definitions in the
right place, ie. the stanza class.
This commit is contained in:
Florian Schmaus 2014-07-05 11:58:13 +02:00
parent f05b208120
commit 8526f8ab29
20 changed files with 203 additions and 199 deletions

View file

@ -0,0 +1,39 @@
/**
*
* Copyright © 2014 Florian Schmaus
*
* 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.packet;
/**
* Interface to represent a XML element. This is similar to {@link PacketExtension}, but does not
* carry a namespace and is usually included as child element of an packet extension.
*/
public interface Element {
/**
* Returns the root element name.
*
* @return the element name.
*/
public String getElementName();
/**
* Returns the XML representation of the PacketExtension.
*
* @return the packet extension as XML.
*/
public CharSequence toXML();
}

View file

@ -40,6 +40,8 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
*/
public abstract class IQ extends Packet {
public static final String QUERY_ELEMENT = "query";
private Type type = Type.get;
public IQ() {

View file

@ -28,14 +28,7 @@ package org.jivesoftware.smack.packet;
* @see org.jivesoftware.smack.provider.PacketExtensionProvider
* @author Matt Tucker
*/
public interface PacketExtension {
/**
* Returns the root element name.
*
* @return the element name.
*/
public String getElementName();
public interface PacketExtension extends Element {
/**
* Returns the root element XML namespace.
@ -44,10 +37,4 @@ public interface PacketExtension {
*/
public String getNamespace();
/**
* Returns the XML representation of the PacketExtension.
*
* @return the packet extension as XML.
*/
public CharSequence toXML();
}

View file

@ -16,6 +16,7 @@
*/
package org.jivesoftware.smack.util;
import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.packet.PacketExtension;
public class XmlStringBuilder implements Appendable, CharSequence {
@ -32,6 +33,11 @@ public class XmlStringBuilder implements Appendable, CharSequence {
prelude(pe);
}
public XmlStringBuilder(Element e) {
this();
halfOpenElement(e.getElementName());
}
/**
* Does nothing if content is null.
*
@ -83,8 +89,8 @@ public class XmlStringBuilder implements Appendable, CharSequence {
return this;
}
public XmlStringBuilder closeElement(PacketExtension pe) {
closeElement(pe.getElementName());
public XmlStringBuilder closeElement(Element e) {
closeElement(e.getElementName());
return this;
}

View file

@ -131,11 +131,6 @@ public class InBandBytestreamManager implements BytestreamManager {
});
}
/**
* The XMPP namespace of the In-Band Bytestream
*/
public static final String NAMESPACE = "http://jabber.org/protocol/ibb";
/**
* Maximum block size that is allowed for In-Band Bytestreams
*/

View file

@ -451,8 +451,8 @@ public class InBandBytestreamSession implements BytestreamSession {
public void processPacket(Packet packet) throws NotConnectedException {
// get data packet extension
DataPacketExtension data = (DataPacketExtension) packet.getExtension(
DataPacketExtension.ELEMENT_NAME,
InBandBytestreamManager.NAMESPACE);
DataPacketExtension.ELEMENT,
DataPacketExtension.NAMESPACE);
/*
* check if sequence was not used already (see XEP-0047 Section 2.2)
@ -514,8 +514,8 @@ public class InBandBytestreamSession implements BytestreamSession {
public void processPacket(Packet packet) {
// get data packet extension
DataPacketExtension data = (DataPacketExtension) packet.getExtension(
DataPacketExtension.ELEMENT_NAME,
InBandBytestreamManager.NAMESPACE);
DataPacketExtension.ELEMENT,
DataPacketExtension.NAMESPACE);
// check if encoded data is valid
if (data.getDecodedData() == null) {
@ -563,8 +563,8 @@ public class InBandBytestreamSession implements BytestreamSession {
}
// stanza contains data packet extension
PacketExtension packetExtension = packet.getExtension(DataPacketExtension.ELEMENT_NAME,
InBandBytestreamManager.NAMESPACE);
PacketExtension packetExtension = packet.getExtension(DataPacketExtension.ELEMENT,
DataPacketExtension.NAMESPACE);
if (packetExtension == null || !(packetExtension instanceof DataPacketExtension)) {
return false;
}

View file

@ -17,7 +17,7 @@
package org.jivesoftware.smackx.bytestreams.ibb.packet;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager;
import org.jivesoftware.smack.util.XmlStringBuilder;
/**
* Represents a request to close an In-Band Bytestream.
@ -26,6 +26,8 @@ import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager;
*/
public class Close extends IQ {
public static final String ELEMENT = "close";
/* unique session ID identifying this In-Band Bytestream */
private final String sessionID;
@ -52,17 +54,13 @@ public class Close extends IQ {
}
@Override
public String getChildElementXML() {
StringBuilder buf = new StringBuilder();
buf.append("<close ");
buf.append("xmlns=\"");
buf.append(InBandBytestreamManager.NAMESPACE);
buf.append("\" ");
buf.append("sid=\"");
buf.append(sessionID);
buf.append("\"");
buf.append("/>");
return buf.toString();
public XmlStringBuilder getChildElementXML() {
XmlStringBuilder xml = new XmlStringBuilder();
xml.halfOpenElement(ELEMENT);
xml.xmlnsAttribute(DataPacketExtension.NAMESPACE);
xml.attribute("sid", sessionID);
xml.closeEmptyElement();
return xml;
}
}

View file

@ -17,6 +17,7 @@
package org.jivesoftware.smackx.bytestreams.ibb.packet;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.XmlStringBuilder;
/**
* Represents a chunk of data sent over an In-Band Bytestream encapsulated in an
@ -60,8 +61,9 @@ public class Data extends IQ {
return this.dataPacketExtension;
}
public String getChildElementXML() {
return this.dataPacketExtension.toXML();
@Override
public XmlStringBuilder getChildElementXML() {
return dataPacketExtension.toXML();
}
}

View file

@ -18,7 +18,7 @@ package org.jivesoftware.smackx.bytestreams.ibb.packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager;
import org.jivesoftware.smack.util.XmlStringBuilder;
/**
* Represents a chunk of data of an In-Band Bytestream within an IQ stanza or a
@ -31,7 +31,12 @@ public class DataPacketExtension implements PacketExtension {
/**
* The element name of the data packet extension.
*/
public final static String ELEMENT_NAME = "data";
public final static String ELEMENT = "data";
/**
* The XMPP namespace of the In-Band Bytestream
*/
public static final String NAMESPACE = "http://jabber.org/protocol/ibb";
/* unique session ID identifying this In-Band Bytestream */
private final String sessionID;
@ -121,32 +126,22 @@ public class DataPacketExtension implements PacketExtension {
}
public String getElementName() {
return ELEMENT_NAME;
return ELEMENT;
}
public String getNamespace() {
return InBandBytestreamManager.NAMESPACE;
return NAMESPACE;
}
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<");
buf.append(getElementName());
buf.append(" ");
buf.append("xmlns=\"");
buf.append(InBandBytestreamManager.NAMESPACE);
buf.append("\" ");
buf.append("seq=\"");
buf.append(seq);
buf.append("\" ");
buf.append("sid=\"");
buf.append(sessionID);
buf.append("\">");
buf.append(data);
buf.append("</");
buf.append(getElementName());
buf.append(">");
return buf.toString();
@Override
public XmlStringBuilder toXML() {
XmlStringBuilder xml = new XmlStringBuilder(this);
xml.attribute("seq", Long.toString(seq));
xml.attribute("sid", sessionID);
xml.rightAngelBracket();
xml.append(data);
xml.closeElement(this);
return xml;
}
}

View file

@ -19,7 +19,7 @@ package org.jivesoftware.smackx.bytestreams.ibb.packet;
import java.util.Locale;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaType;
/**
@ -29,6 +29,8 @@ import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaTyp
*/
public class Open extends IQ {
public static final String ELEMENT = "open";
/* unique session ID identifying this In-Band Bytestream */
private final String sessionID;
@ -109,23 +111,15 @@ public class Open extends IQ {
}
@Override
public String getChildElementXML() {
StringBuilder buf = new StringBuilder();
buf.append("<open ");
buf.append("xmlns=\"");
buf.append(InBandBytestreamManager.NAMESPACE);
buf.append("\" ");
buf.append("block-size=\"");
buf.append(blockSize);
buf.append("\" ");
buf.append("sid=\"");
buf.append(sessionID);
buf.append("\" ");
buf.append("stanza=\"");
buf.append(stanza.toString().toLowerCase(Locale.US));
buf.append("\"");
buf.append("/>");
return buf.toString();
public XmlStringBuilder getChildElementXML() {
XmlStringBuilder xml = new XmlStringBuilder();
xml.halfOpenElement(ELEMENT);
xml.xmlnsAttribute(DataPacketExtension.NAMESPACE);
xml.attribute("block-size", Integer.toString(blockSize));
xml.attribute("sid", sessionID);
xml.attribute("stanza", stanza.toString().toLowerCase(Locale.US));
xml.closeEmptyElement();
return xml;
}
}

View file

@ -125,11 +125,6 @@ public final class Socks5BytestreamManager implements BytestreamManager {
});
}
/**
* The XMPP namespace of the SOCKS5 Bytestream
*/
public static final String NAMESPACE = "http://jabber.org/protocol/bytestreams";
/* prefix used to generate session IDs */
private static final String SESSION_ID_PREFIX = "js5_";
@ -322,7 +317,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
// check if service discovery is not already disposed by connection shutdown
if (serviceDiscoveryManager != null) {
serviceDiscoveryManager.removeFeature(NAMESPACE);
serviceDiscoveryManager.removeFeature(Bytestream.NAMESPACE);
}
}
@ -540,7 +535,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
* @throws NotConnectedException
*/
private boolean supportsSocks5(String targetJID) throws NoResponseException, XMPPErrorException, NotConnectedException {
return ServiceDiscoveryManager.getInstanceFor(connection).supportsFeature(targetJID, NAMESPACE);
return ServiceDiscoveryManager.getInstanceFor(connection).supportsFeature(targetJID, Bytestream.NAMESPACE);
}
/**
@ -732,9 +727,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
*/
private void enableService() {
ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(this.connection);
if (!manager.includesFeature(NAMESPACE)) {
manager.addFeature(NAMESPACE);
}
manager.addFeature(Bytestream.NAMESPACE);
}
/**

View file

@ -21,8 +21,9 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.util.XmlStringBuilder;
/**
* A packet representing part of a SOCKS5 Bytestream negotiation.
@ -30,6 +31,10 @@ import org.jivesoftware.smack.packet.PacketExtension;
* @author Alexander Wenckus
*/
public class Bytestream extends IQ {
/**
* The XMPP namespace of the SOCKS5 Bytestream
*/
public static final String NAMESPACE = "http://jabber.org/protocol/bytestreams";
private String sessionID;
@ -213,48 +218,51 @@ public class Bytestream extends IQ {
this.toActivate = new Activate(targetID);
}
public String getChildElementXML() {
StringBuilder buf = new StringBuilder();
@Override
public XmlStringBuilder getChildElementXML() {
XmlStringBuilder xml = new XmlStringBuilder();
xml.openElement(IQ.QUERY_ELEMENT);
xml.xmlnsAttribute(NAMESPACE);
buf.append("<query xmlns=\"http://jabber.org/protocol/bytestreams\"");
if (this.getType().equals(IQ.Type.set)) {
switch(getType()) {
case set:
if (getSessionID() != null) {
buf.append(" sid=\"").append(getSessionID()).append("\"");
xml.attribute("sid", getSessionID());
}
if (getMode() != null) {
buf.append(" mode = \"").append(getMode()).append("\"");
xml.attribute("mode", getMode());
}
buf.append(">");
xml.rightAngelBracket();
if (getToActivate() == null) {
for (StreamHost streamHost : getStreamHosts()) {
buf.append(streamHost.toXML());
xml.append(streamHost.toXML());
}
}
else {
buf.append(getToActivate().toXML());
xml.append(getToActivate().toXML());
}
}
else if (this.getType().equals(IQ.Type.result)) {
buf.append(">");
break;
case result:
xml.rightAngelBracket();
if (getUsedHost() != null) {
buf.append(getUsedHost().toXML());
xml.append(getUsedHost().toXML());
}
// A result from the server can also contain stream hosts
else if (countStreamHosts() > 0) {
for (StreamHost host : streamHosts) {
buf.append(host.toXML());
xml.append(host.toXML());
}
}
break;
case get:
xml.closeEmptyElement();
return xml;
default:
throw new IllegalStateException();
}
else if (this.getType().equals(IQ.Type.get)) {
return buf.append("/>").toString();
}
else {
return null;
}
buf.append("</query>");
xml.closeElement(IQ.QUERY_ELEMENT);
return buf.toString();
return xml;
}
/**
@ -263,9 +271,7 @@ public class Bytestream extends IQ {
*
* @author Alexander Wenckus
*/
public static class StreamHost implements PacketExtension {
public static String NAMESPACE = "";
public static class StreamHost implements Element {
public static String ELEMENTNAME = "streamhost";
@ -322,29 +328,22 @@ public class Bytestream extends IQ {
return port;
}
public String getNamespace() {
return NAMESPACE;
}
public String getElementName() {
return ELEMENTNAME;
}
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" ");
buf.append("jid=\"").append(getJID()).append("\" ");
buf.append("host=\"").append(getAddress()).append("\" ");
@Override
public XmlStringBuilder toXML() {
XmlStringBuilder xml = new XmlStringBuilder(this);
xml.attribute("jid", getJID());
xml.attribute("host", getAddress());
if (getPort() != 0) {
buf.append("port=\"").append(getPort()).append("\"");
xml.attribute("port", Integer.toString(getPort()));
} else {
xml.attribute("zeroconf", "_jabber.bytestreams");
}
else {
buf.append("zeroconf=\"_jabber.bytestreams\"");
}
buf.append("/>");
return buf.toString();
xml.closeEmptyElement();
return xml;
}
}
@ -354,9 +353,7 @@ public class Bytestream extends IQ {
*
* @author Alexander Wenckus
*/
public static class StreamHostUsed implements PacketExtension {
public String NAMESPACE = "";
public static class StreamHostUsed implements Element {
public static String ELEMENTNAME = "streamhost-used";
@ -380,20 +377,16 @@ public class Bytestream extends IQ {
return JID;
}
public String getNamespace() {
return NAMESPACE;
}
public String getElementName() {
return ELEMENTNAME;
}
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" ");
buf.append("jid=\"").append(getJID()).append("\" ");
buf.append("/>");
return buf.toString();
@Override
public XmlStringBuilder toXML() {
XmlStringBuilder xml = new XmlStringBuilder(this);
xml.attribute("jid", getJID());
xml.closeEmptyElement();
return xml;
}
}
@ -402,9 +395,7 @@ public class Bytestream extends IQ {
*
* @author Alexander Wenckus
*/
public static class Activate implements PacketExtension {
public String NAMESPACE = "";
public static class Activate implements Element {
public static String ELEMENTNAME = "activate";
@ -428,20 +419,17 @@ public class Bytestream extends IQ {
return target;
}
public String getNamespace() {
return NAMESPACE;
}
public String getElementName() {
return ELEMENTNAME;
}
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(">");
buf.append(getTarget());
buf.append("</").append(getElementName()).append(">");
return buf.toString();
@Override
public XmlStringBuilder toXML() {
XmlStringBuilder xml = new XmlStringBuilder(this);
xml.rightAngelBracket();
xml.escape(getTarget());
xml.closeElement(this);
return xml;
}
}

View file

@ -405,10 +405,12 @@ public class ServiceDiscoveryManager extends Manager {
*/
public void addFeature(String feature) {
synchronized (features) {
if (!features.contains(feature)) {
features.add(feature);
renewEntityCapsVersion();
}
}
}
/**
* Removes the specified feature from the supported features by this XMPP entity.<p>

View file

@ -34,8 +34,8 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager;
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.si.packet.StreamInitiation;
import org.jivesoftware.smackx.xdata.Form;
@ -103,9 +103,9 @@ public class FileTransferNegotiator extends Manager {
List<String> namespaces = new ArrayList<String>();
namespaces.addAll(Arrays.asList(NAMESPACE));
namespaces.add(InBandBytestreamManager.NAMESPACE);
namespaces.add(DataPacketExtension.NAMESPACE);
if (!IBB_ONLY) {
namespaces.add(Socks5BytestreamManager.NAMESPACE);
namespaces.add(Bytestream.NAMESPACE);
}
for (String namespace : namespaces) {
@ -130,9 +130,9 @@ public class FileTransferNegotiator extends Manager {
List<String> namespaces = new ArrayList<String>();
namespaces.addAll(Arrays.asList(NAMESPACE));
namespaces.add(InBandBytestreamManager.NAMESPACE);
namespaces.add(DataPacketExtension.NAMESPACE);
if (!IBB_ONLY) {
namespaces.add(Socks5BytestreamManager.NAMESPACE);
namespaces.add(Bytestream.NAMESPACE);
}
for (String namespace : namespaces) {
@ -150,9 +150,9 @@ public class FileTransferNegotiator extends Manager {
*/
public static Collection<String> getSupportedProtocols() {
List<String> protocols = new ArrayList<String>();
protocols.add(InBandBytestreamManager.NAMESPACE);
protocols.add(DataPacketExtension.NAMESPACE);
if (!IBB_ONLY) {
protocols.add(Socks5BytestreamManager.NAMESPACE);
protocols.add(Bytestream.NAMESPACE);
}
return Collections.unmodifiableList(protocols);
}
@ -227,10 +227,10 @@ public class FileTransferNegotiator extends Manager {
boolean isIBB = false;
for (FormField.Option option : field.getOptions()) {
variable = option.getValue();
if (variable.equals(Socks5BytestreamManager.NAMESPACE) && !IBB_ONLY) {
if (variable.equals(Bytestream.NAMESPACE) && !IBB_ONLY) {
isByteStream = true;
}
else if (variable.equals(InBandBytestreamManager.NAMESPACE)) {
else if (variable.equals(DataPacketExtension.NAMESPACE)) {
isIBB = true;
}
}
@ -354,10 +354,10 @@ public class FileTransferNegotiator extends Manager {
boolean isByteStream = false;
boolean isIBB = false;
for (String variable : field.getValues()) {
if (variable.equals(Socks5BytestreamManager.NAMESPACE) && !IBB_ONLY) {
if (variable.equals(Bytestream.NAMESPACE) && !IBB_ONLY) {
isByteStream = true;
}
else if (variable.equals(InBandBytestreamManager.NAMESPACE)) {
else if (variable.equals(DataPacketExtension.NAMESPACE)) {
isIBB = true;
}
}
@ -385,9 +385,9 @@ public class FileTransferNegotiator extends Manager {
FormField field = new FormField(STREAM_DATA_FIELD_NAME);
field.setType(FormField.TYPE_LIST_SINGLE);
if (!IBB_ONLY) {
field.addOption(new FormField.Option(Socks5BytestreamManager.NAMESPACE));
field.addOption(new FormField.Option(Bytestream.NAMESPACE));
}
field.addOption(new FormField.Option(InBandBytestreamManager.NAMESPACE));
field.addOption(new FormField.Option(DataPacketExtension.NAMESPACE));
form.addField(field);
return form;
}

View file

@ -32,6 +32,7 @@ import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager;
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamRequest;
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamSession;
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
import org.jivesoftware.smackx.si.packet.StreamInitiation;
@ -92,7 +93,7 @@ public class IBBTransferNegotiator extends StreamNegotiator {
}
public String[] getNamespaces() {
return new String[] { InBandBytestreamManager.NAMESPACE };
return new String[] { DataPacketExtension.NAMESPACE };
}
InputStream negotiateIncomingStream(Packet streamInitiation) throws NotConnectedException {

View file

@ -97,7 +97,7 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
@Override
public String[] getNamespaces() {
return new String[] { Socks5BytestreamManager.NAMESPACE };
return new String[] { Bytestream.NAMESPACE };
}
@Override

View file

@ -99,7 +99,7 @@ public class InBandBytestreamSessionMessageTest {
public void verify(Message request, IQ response) {
DataPacketExtension dpe = (DataPacketExtension) request.getExtension(
DataPacketExtension.ELEMENT_NAME, InBandBytestreamManager.NAMESPACE);
DataPacketExtension.ELEMENT, DataPacketExtension.NAMESPACE);
assertEquals(lastSeq++, dpe.getSeq());
}

View file

@ -93,7 +93,7 @@ public class DataPacketExtensionTest {
.asString(outputProperties);
DataPacketExtension data = new DataPacketExtension("i781hf64", 0, "DATA");
assertXMLEqual(control, data.toXML());
assertXMLEqual(control, data.toXML().toString());
}
}

View file

@ -18,13 +18,13 @@ 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.*;
import java.util.Properties;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Data;
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension;
import org.junit.Test;
@ -72,12 +72,14 @@ public class DataTest {
.asString(outputProperties);
DataPacketExtension dpe = mock(DataPacketExtension.class);
String dataTag = XMLBuilder.create("data")
.a("xmlns", "http://jabber.org/protocol/ibb")
.a("seq", "0")
.a("sid", "i781hf64")
.t(encodedData)
.asString(outputProperties);
XmlStringBuilder dataTag = new XmlStringBuilder();
dataTag.halfOpenElement(DataPacketExtension.ELEMENT);
dataTag.xmlnsAttribute(DataPacketExtension.NAMESPACE);
dataTag.attribute("seq", "0");
dataTag.attribute("sid", "i781hf64");
dataTag.rightAngelBracket();
dataTag.escape(encodedData);
dataTag.closeElement(DataPacketExtension.ELEMENT);
when(dpe.toXML()).thenReturn(dataTag);
Data data = new Data(dpe);
data.setFrom("romeo@montague.lit/orchard");

View file

@ -127,11 +127,11 @@ public class Socks5ByteStreamManagerTest {
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
assertTrue(discoveryManager.includesFeature(Socks5BytestreamManager.NAMESPACE));
assertTrue(discoveryManager.includesFeature(Bytestream.NAMESPACE));
byteStreamManager.disableService();
assertFalse(discoveryManager.includesFeature(Socks5BytestreamManager.NAMESPACE));
assertFalse(discoveryManager.includesFeature(Bytestream.NAMESPACE));
}
/**
@ -182,7 +182,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info that supports the SOCKS5 feature
DiscoverInfo discoverInfo = Socks5PacketUtils.createDiscoverInfo(targetJID, initiatorJID);
discoverInfo.addFeature(Socks5BytestreamManager.NAMESPACE);
discoverInfo.addFeature(Bytestream.NAMESPACE);
// return that SOCKS5 is supported if target is queried
protocol.addResponse(discoverInfo, Verification.correspondingSenderReceiver,
@ -233,7 +233,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info that supports the SOCKS5 feature
DiscoverInfo discoverInfo = Socks5PacketUtils.createDiscoverInfo(targetJID, initiatorJID);
discoverInfo.addFeature(Socks5BytestreamManager.NAMESPACE);
discoverInfo.addFeature(Bytestream.NAMESPACE);
// return that SOCKS5 is supported if target is queried
protocol.addResponse(discoverInfo, Verification.correspondingSenderReceiver,
@ -297,7 +297,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info that supports the SOCKS5 feature
DiscoverInfo discoverInfo = Socks5PacketUtils.createDiscoverInfo(targetJID, initiatorJID);
discoverInfo.addFeature(Socks5BytestreamManager.NAMESPACE);
discoverInfo.addFeature(Bytestream.NAMESPACE);
// return that SOCKS5 is supported if target is queried
protocol.addResponse(discoverInfo, Verification.correspondingSenderReceiver,
@ -388,7 +388,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info that supports the SOCKS5 feature
DiscoverInfo discoverInfo = Socks5PacketUtils.createDiscoverInfo(targetJID, initiatorJID);
discoverInfo.addFeature(Socks5BytestreamManager.NAMESPACE);
discoverInfo.addFeature(Bytestream.NAMESPACE);
// return that SOCKS5 is supported if target is queried
protocol.addResponse(discoverInfo, Verification.correspondingSenderReceiver,
@ -478,7 +478,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info that supports the SOCKS5 feature
DiscoverInfo discoverInfo = Socks5PacketUtils.createDiscoverInfo(targetJID, initiatorJID);
discoverInfo.addFeature(Socks5BytestreamManager.NAMESPACE);
discoverInfo.addFeature(Bytestream.NAMESPACE);
// return that SOCKS5 is supported if target is queried
protocol.addResponse(discoverInfo, Verification.correspondingSenderReceiver,
@ -560,7 +560,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info that supports the SOCKS5 feature
DiscoverInfo discoverInfo = Socks5PacketUtils.createDiscoverInfo(targetJID, initiatorJID);
discoverInfo.addFeature(Socks5BytestreamManager.NAMESPACE);
discoverInfo.addFeature(Bytestream.NAMESPACE);
// return that SOCKS5 is supported if target is queried
protocol.addResponse(discoverInfo, Verification.correspondingSenderReceiver,
@ -654,7 +654,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info that supports the SOCKS5 feature
DiscoverInfo discoverInfo = Socks5PacketUtils.createDiscoverInfo(targetJID, initiatorJID);
discoverInfo.addFeature(Socks5BytestreamManager.NAMESPACE);
discoverInfo.addFeature(Bytestream.NAMESPACE);
// return that SOCKS5 is supported if target is queried
protocol.addResponse(discoverInfo, Verification.correspondingSenderReceiver,
@ -773,7 +773,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info that supports the SOCKS5 feature
DiscoverInfo discoverInfo = Socks5PacketUtils.createDiscoverInfo(targetJID, initiatorJID);
discoverInfo.addFeature(Socks5BytestreamManager.NAMESPACE);
discoverInfo.addFeature(Bytestream.NAMESPACE);
// return that SOCKS5 is supported if target is queried
protocol.addResponse(discoverInfo, Verification.correspondingSenderReceiver,
@ -1003,7 +1003,7 @@ public class Socks5ByteStreamManagerTest {
private void createResponses(Verification<Bytestream, Bytestream> streamHostUsedVerification) {
// build discover info that supports the SOCKS5 feature
DiscoverInfo discoverInfo = Socks5PacketUtils.createDiscoverInfo(targetJID, initiatorJID);
discoverInfo.addFeature(Socks5BytestreamManager.NAMESPACE);
discoverInfo.addFeature(Bytestream.NAMESPACE);
// return that SOCKS5 is supported if target is queried
protocol.addResponse(discoverInfo, Verification.correspondingSenderReceiver,