You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by Marco Ferretti <ma...@gmail.com> on 2005/03/23 12:31:55 UTC
notification does not work after error
Hi.
I use a simple NotificationListener to test slide with tomcat. I
subscribe to "Update", "Update/newmember" and "Delete" to a file and a
collection . I mess a little bit with DAVExplorer and then I
unsubscribe ( getting the error of my previous post ) . I then restart
the test code (the server was still running) and get
Mar 23, 2005 12:12:55 PM org.apache.webdav.lib.NotificationListener subscribe
SEVERE: Subscription for uri='' failed. State: 500
I can't register or subscribe anything else untill I restart the server .
I use jakarta-slide-2.1-tomcat-5.0.28 bundled . Any help would be appreciated
==============================================
Here's the code I use to produce the error :
==============================================
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JTextField;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.webdav.lib.NotificationListener;
import org.apache.webdav.lib.Subscriber;
import org.apache.webdav.lib.methods.DepthSupport;
import com.terma.webdav.Utils;
public class Test {
public static void main(String args[]) {
Test test = new Test();
test.testNotify();
}
public static void testConnect() {
try {
Utils util = new Utils("127.0.0.1", "8080");
util.connect("root", "root");
} catch (Exception e) {
e.printStackTrace();
}
}
public void testNotify() {
String testDossier = "testNotify";
Utils help = new Utils("127.0.0.1", "8080");
Test test = new Test();
mySubscriber subscriber;
mySubscriber subscriber1;
myFrame fr = test.new myFrame();
try {
subscriber = test.new mySubscriber(fr);
subscriber1 = test.new mySubscriber(fr);
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
help.connect("root", "root");
File f1 = new File("/home/marco/install.log");
File f2 = new File("/home/marco/tmp/tmp.xpi");
help
.uploadFile(new FileInputStream(f1), f1.getName(), null,
"DAV:");
help
.uploadFile(new FileInputStream(f2), f2.getName(), null,
"DAV:");
System.out.println("subscribing to " + f1.getName());
NotificationListener listener = subscribe("root", "root", "test",
subscriber1);
fr.setSize(400, 400);
fr.show();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(
"root", "root");
boolean success = listener.unsubscribe(help
.normalize(Utils.DEFAULT_ROOT_PATH + "test"), subscriber,
credentials);
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
}
public NotificationListener subscribe(String username, String password,
String path, Subscriber subscriber) throws IOException {
try {
NotificationListener listener = null;
int pollInterval = 10000; //10 seconds
boolean success = true;
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(
username, password);
listener = new NotificationListener("", 0, "127.0.0.1", 8080,
Protocol.getProtocol("http"), credentials, "/slide/files",
pollInterval, false);
success = listener.subscribe("Update", "",
DepthSupport.DEPTH_INFINITY, pollInterval, 100, subscriber,
credentials);
success = listener.subscribe("Update/newmember", "",
DepthSupport.DEPTH_INFINITY, pollInterval, 100, subscriber,
credentials);
success = success ? listener.subscribe("Delete", "",
DepthSupport.DEPTH_INFINITY, pollInterval, 100, subscriber,
credentials) : false;
return listener;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
}
}
class mySubscriber implements Subscriber {
myFrame fr;
public mySubscriber(myFrame fr) {
this.fr = fr;
}
/* (non-Javadoc)
* @see org.apache.webdav.lib.Subscriber#notify(java.lang.String,
java.util.Map)
*/
public void notify(String uri, Map information) {
StringBuffer message = new StringBuffer("Notification : ");
String corpo = "The resource(s) \n";
if (!information.isEmpty()) {
Set keys = information.keySet();
Iterator it = keys.iterator();
Object key = null;
Object msg = null;
while (it.hasNext()) {
key = it.next();
msg = information.get(key);
if (message != null)
message.append("\n");
else
message = new StringBuffer();
message.append(key.toString());
message.append(" = ");
message.append(msg.toString());
corpo += msg.toString();
}
}
fr.addMessage(message.toString());
}
}
class myFrame extends JDialog {
/**
* Comment for <code>serialVersionUID</code>
*/
private static final long serialVersionUID = 3760558698267096374L;
JTextField text = new JTextField();
public myFrame() {
getContentPane().add(text);
JButton btn = new JButton(new AbstractAction("close") {
public void actionPerformed(ActionEvent e) {
myFrame.this.dispose();
}
});
getContentPane().add(btn, BorderLayout.SOUTH);
}
public void addMessage(String txt) {
StringBuffer msg = new StringBuffer(text.getText());
msg.append("\n");
msg.append(txt);
text.setText(msg.toString());
}
public void show() {
super.setModal(true);
super.show();
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org