mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-25 05:22:06 +01:00
Fix PubSub namespaces
Those were broken since 9e797c1b17
as they
always used the basic PubSub namespace, i.e. without a fragment. Which
resulted in e.g. delete requests look like
<iq to="pubsub.ec-xmpp" id="2GAeW-75" type="set">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
<delete node="2e92d38c-9e90-47f6-8e26-330d25ebe96b"/>
</pubsub>
</iq>
when the namespace should be in fact
http://jabber.org/protocol/pubsub#owner
This commit is contained in:
parent
d0341c1d94
commit
add4ff5b5a
5 changed files with 70 additions and 69 deletions
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smack;
|
package org.jivesoftware.smack;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
@ -37,13 +38,8 @@ public class ThreadedDummyConnection extends DummyConnection {
|
||||||
private volatile boolean timeout = false;
|
private volatile boolean timeout = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendPacket(Packet packet) {
|
public void sendPacket(Packet packet) throws NotConnectedException {
|
||||||
try {
|
|
||||||
super.sendPacket(packet);
|
super.sendPacket(packet);
|
||||||
}
|
|
||||||
catch (NotConnectedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (packet instanceof IQ && !timeout) {
|
if (packet instanceof IQ && !timeout) {
|
||||||
timeout = false;
|
timeout = false;
|
||||||
|
@ -106,4 +102,10 @@ public class ThreadedDummyConnection extends DummyConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ThreadedDummyConnection newInstance() throws SmackException, IOException, XMPPException {
|
||||||
|
ThreadedDummyConnection threadedDummyConnection = new ThreadedDummyConnection();
|
||||||
|
threadedDummyConnection.connect();
|
||||||
|
return threadedDummyConnection;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,23 +32,18 @@ public class PubSub extends IQ
|
||||||
public static final String ELEMENT = "pubsub";
|
public static final String ELEMENT = "pubsub";
|
||||||
public static final String NAMESPACE = "http://jabber.org/protocol/pubsub";
|
public static final String NAMESPACE = "http://jabber.org/protocol/pubsub";
|
||||||
|
|
||||||
private PubSubNamespace ns = PubSubNamespace.BASIC;
|
|
||||||
|
|
||||||
public PubSub() {
|
public PubSub() {
|
||||||
super(ELEMENT, NAMESPACE);
|
super(ELEMENT, NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PubSub(String to, Type type) {
|
public PubSub(PubSubNamespace ns) {
|
||||||
this();
|
super(ELEMENT, ns.getXmlns());
|
||||||
setTo(to);
|
|
||||||
setType(type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PubSub(String to, Type type, PubSubNamespace ns) {
|
public PubSub(String to, Type type, PubSubNamespace ns) {
|
||||||
this(to, type);
|
super(ELEMENT, (ns == null ? PubSubNamespace.BASIC : ns).getXmlns());
|
||||||
if (ns != null) {
|
setTo(to);
|
||||||
setPubSubNamespace(ns);
|
setType(type);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,49 +55,12 @@ public class PubSub extends IQ
|
||||||
return ELEMENT;
|
return ELEMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the XML namespace of the extension sub-packet root element.
|
|
||||||
* According the specification the namespace is
|
|
||||||
* http://jabber.org/protocol/pubsub with a specific fragment depending
|
|
||||||
* on the request. The namespace is defined at <a href="http://xmpp.org/registrar/namespaces.html">XMPP Registrar</a> at
|
|
||||||
*
|
|
||||||
* The default value has no fragment.
|
|
||||||
*
|
|
||||||
* @return the XML namespace of the packet extension.
|
|
||||||
*/
|
|
||||||
public String getNamespace()
|
|
||||||
{
|
|
||||||
return ns.getXmlns();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the namespace for the packet if it something other than the default
|
|
||||||
* case of {@link PubSubNamespace#BASIC}. The {@link #getNamespace()} method will return
|
|
||||||
* the result of calling {@link PubSubNamespace#getXmlns()} on the specified enum.
|
|
||||||
*
|
|
||||||
* @param ns - The new value for the namespace.
|
|
||||||
*/
|
|
||||||
public void setPubSubNamespace(PubSubNamespace ns)
|
|
||||||
{
|
|
||||||
this.ns = ns;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <PE extends PacketExtension> PE getExtension(PubSubElementType elem)
|
public <PE extends PacketExtension> PE getExtension(PubSubElementType elem)
|
||||||
{
|
{
|
||||||
return (PE) getExtension(elem.getElementName(), elem.getNamespace().getXmlns());
|
return (PE) getExtension(elem.getElementName(), elem.getNamespace().getXmlns());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the current value of the namespace. The {@link #getNamespace()} method will return
|
|
||||||
* the result of calling {@link PubSubNamespace#getXmlns()} this value.
|
|
||||||
*
|
|
||||||
* @return The current value of the namespace.
|
|
||||||
*/
|
|
||||||
public PubSubNamespace getPubSubNamespace()
|
|
||||||
{
|
|
||||||
return ns;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Returns the XML representation of a pubsub element according the specification.
|
* Returns the XML representation of a pubsub element according the specification.
|
||||||
*
|
*
|
||||||
|
|
|
@ -38,25 +38,22 @@ public class PubSubProvider extends IQProvider<PubSub>
|
||||||
@Override
|
@Override
|
||||||
public PubSub parse(XmlPullParser parser, int initialDepth)
|
public PubSub parse(XmlPullParser parser, int initialDepth)
|
||||||
throws XmlPullParserException, IOException, SmackException {
|
throws XmlPullParserException, IOException, SmackException {
|
||||||
PubSub pubsub = new PubSub();
|
|
||||||
String namespace = parser.getNamespace();
|
String namespace = parser.getNamespace();
|
||||||
pubsub.setPubSubNamespace(PubSubNamespace.valueOfFromXmlns(namespace));
|
PubSubNamespace pubSubNamespace = PubSubNamespace.valueOfFromXmlns(namespace);
|
||||||
boolean done = false;
|
PubSub pubsub = new PubSub(pubSubNamespace);
|
||||||
|
|
||||||
while (!done)
|
outerloop: while (true)
|
||||||
{
|
{
|
||||||
int eventType = parser.next();
|
int eventType = parser.next();
|
||||||
|
switch (eventType) {
|
||||||
if (eventType == XmlPullParser.START_TAG)
|
case XmlPullParser.START_TAG:
|
||||||
{
|
|
||||||
PacketParserUtils.addPacketExtension(pubsub, parser);
|
PacketParserUtils.addPacketExtension(pubsub, parser);
|
||||||
|
break;
|
||||||
|
case XmlPullParser.END_TAG:
|
||||||
|
if (parser.getDepth() == initialDepth) {
|
||||||
|
break outerloop;
|
||||||
}
|
}
|
||||||
else if (eventType == XmlPullParser.END_TAG)
|
break;
|
||||||
{
|
|
||||||
if (parser.getName().equals("pubsub"))
|
|
||||||
{
|
|
||||||
done = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pubsub;
|
return pubsub;
|
||||||
|
|
|
@ -18,6 +18,8 @@ package org.jivesoftware.smackx.pubsub;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
import org.jivesoftware.smack.SmackConfiguration;
|
||||||
import org.jivesoftware.smack.SmackException;
|
import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.ThreadedDummyConnection;
|
import org.jivesoftware.smack.ThreadedDummyConnection;
|
||||||
|
@ -47,9 +49,9 @@ public class ConfigureFormTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getConfigFormWithInsufficientPriviliges() throws XMPPException, SmackException
|
public void getConfigFormWithInsufficientPriviliges() throws XMPPException, SmackException, IOException
|
||||||
{
|
{
|
||||||
ThreadedDummyConnection con = new ThreadedDummyConnection();
|
ThreadedDummyConnection con = ThreadedDummyConnection.newInstance();
|
||||||
PubSubManager mgr = new PubSubManager(con);
|
PubSubManager mgr = new PubSubManager(con);
|
||||||
DiscoverInfo info = new DiscoverInfo();
|
DiscoverInfo info = new DiscoverInfo();
|
||||||
Identity ident = new Identity("pubsub", null, "leaf");
|
Identity ident = new Identity("pubsub", null, "leaf");
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.smackx.pubsub;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.SmackException;
|
||||||
|
import org.jivesoftware.smack.ThreadedDummyConnection;
|
||||||
|
import org.jivesoftware.smack.XMPPException;
|
||||||
|
import org.jivesoftware.smackx.pubsub.packet.PubSub;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class PubSubManagerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteNodeTest() throws InterruptedException, SmackException, IOException, XMPPException {
|
||||||
|
ThreadedDummyConnection con = ThreadedDummyConnection.newInstance();
|
||||||
|
PubSubManager mgr = new PubSubManager(con);
|
||||||
|
|
||||||
|
mgr.deleteNode("foo@bar.org");
|
||||||
|
|
||||||
|
PubSub pubSubDeleteRequest = con.getSentPacket();
|
||||||
|
assertEquals("http://jabber.org/protocol/pubsub#owner", pubSubDeleteRequest.getChildElementNamespace());
|
||||||
|
assertEquals("pubsub", pubSubDeleteRequest.getChildElementName());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue