mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-27 14:32:06 +01:00
Use handler to notify on finished file transfer
This commit is contained in:
parent
63d71230cc
commit
f9086439a8
14 changed files with 163 additions and 36 deletions
|
@ -30,10 +30,12 @@ import org.jivesoftware.smackx.jingle.JingleTransportMethodManager;
|
||||||
import org.jivesoftware.smackx.jingle.Role;
|
import org.jivesoftware.smackx.jingle.Role;
|
||||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
||||||
|
import org.jivesoftware.smackx.jingle.element.JingleReason;
|
||||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportInitiationCallback;
|
import org.jivesoftware.smackx.jingle.transports.JingleTransportInitiationCallback;
|
||||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.callback.IncomingFileOfferCallback;
|
import org.jivesoftware.smackx.jingle_filetransfer.callback.IncomingFileOfferCallback;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
||||||
|
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
||||||
|
|
||||||
import org.jxmpp.jid.FullJid;
|
import org.jxmpp.jid.FullJid;
|
||||||
|
|
||||||
|
@ -46,6 +48,12 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
|
||||||
private ReceiveTask receivingThread;
|
private ReceiveTask receivingThread;
|
||||||
private File target;
|
private File target;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cancel() {
|
||||||
|
//TODO: Actually cancel
|
||||||
|
notifyEndedListeners(JingleReason.Reason.cancel);
|
||||||
|
}
|
||||||
|
|
||||||
public enum State {
|
public enum State {
|
||||||
fresh,
|
fresh,
|
||||||
pending,
|
pending,
|
||||||
|
@ -132,7 +140,7 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
|
||||||
@Override
|
@Override
|
||||||
public void onSessionInitiated(BytestreamSession bytestreamSession) {
|
public void onSessionInitiated(BytestreamSession bytestreamSession) {
|
||||||
LOGGER.log(Level.INFO, "Bytestream initiated. Start receiving.");
|
LOGGER.log(Level.INFO, "Bytestream initiated. Start receiving.");
|
||||||
receivingThread = new ReceiveTask(bytestreamSession, file, target);
|
receivingThread = new ReceiveTask(IncomingJingleFileOffer.this, bytestreamSession, file, target);
|
||||||
queued.add(JingleManager.getThreadPool().submit(receivingThread));
|
queued.add(JingleManager.getThreadPool().submit(receivingThread));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +191,7 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void acceptIncomingFileOffer(final Jingle request, final File target) {
|
public FileTransferHandler acceptIncomingFileOffer(final Jingle request, final File target) {
|
||||||
this.target = target;
|
this.target = target;
|
||||||
LOGGER.log(Level.INFO, "Client accepted incoming file offer. Try to start receiving.");
|
LOGGER.log(Level.INFO, "Client accepted incoming file offer. Try to start receiving.");
|
||||||
if (transportSession == null) {
|
if (transportSession == null) {
|
||||||
|
@ -195,7 +203,7 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
|
||||||
SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
|
SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
|
||||||
LOGGER.log(Level.SEVERE, "Could not send session-terminate: " + e, e);
|
LOGGER.log(Level.SEVERE, "Could not send session-terminate: " + e, e);
|
||||||
}
|
}
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
state = State.active;
|
state = State.active;
|
||||||
|
@ -213,8 +221,10 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
|
||||||
@Override
|
@Override
|
||||||
public void onSessionInitiated(BytestreamSession bytestreamSession) {
|
public void onSessionInitiated(BytestreamSession bytestreamSession) {
|
||||||
LOGGER.log(Level.INFO, "Bytestream initiated. Start receiving.");
|
LOGGER.log(Level.INFO, "Bytestream initiated. Start receiving.");
|
||||||
receivingThread = new ReceiveTask(bytestreamSession, file, target);
|
receivingThread = new ReceiveTask(IncomingJingleFileOffer.this, bytestreamSession, file, target);
|
||||||
queued.add(JingleManager.getThreadPool().submit(receivingThread));
|
queued.add(JingleManager.getThreadPool().submit(receivingThread));
|
||||||
|
started = true;
|
||||||
|
notifyStartedListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -222,6 +232,8 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
|
||||||
LOGGER.log(Level.SEVERE, "EXCEPTION IN INCOMING SESSION: ", e);
|
LOGGER.log(Level.SEVERE, "EXCEPTION IN INCOMING SESSION: ", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -46,4 +46,9 @@ public class JingleFileRequest extends JingleFileTransferSession {
|
||||||
public void onTransportMethodFailed(String namespace) {
|
public void onTransportMethodFailed(String namespace) {
|
||||||
//Not implemented
|
//Not implemented
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cancel() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.jivesoftware.smack.Manager;
|
import org.jivesoftware.smack.Manager;
|
||||||
import org.jivesoftware.smack.SmackException;
|
import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.SmackFuture;
|
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
|
@ -41,7 +40,6 @@ import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.callback.IncomingFileOfferCallback;
|
import org.jivesoftware.smackx.jingle_filetransfer.callback.IncomingFileOfferCallback;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
||||||
|
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.listener.JingleFileTransferOfferListener;
|
import org.jivesoftware.smackx.jingle_filetransfer.listener.JingleFileTransferOfferListener;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.provider.JingleFileTransferProvider;
|
import org.jivesoftware.smackx.jingle_filetransfer.provider.JingleFileTransferProvider;
|
||||||
|
@ -83,14 +81,7 @@ public final class JingleFileTransferManager extends Manager implements JingleHa
|
||||||
OutgoingJingleFileOffer offer = new OutgoingJingleFileOffer(connection(), recipient);
|
OutgoingJingleFileOffer offer = new OutgoingJingleFileOffer(connection(), recipient);
|
||||||
JingleManager.getInstanceFor(connection()).registerJingleSessionHandler(recipient, offer.getSessionId(), offer);
|
JingleManager.getInstanceFor(connection()).registerJingleSessionHandler(recipient, offer.getSessionId(), offer);
|
||||||
offer.send(file);
|
offer.send(file);
|
||||||
//return offer;
|
return offer;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SmackFuture<?> asyncSendFile(FullJid recipient, File file) {
|
|
||||||
OutgoingJingleFileOffer offer = new OutgoingJingleFileOffer(connection(), recipient);
|
|
||||||
JingleManager.getInstanceFor(connection()).registerJingleSessionHandler(recipient, offer.getSessionId(), offer);
|
|
||||||
return offer.sendAsync(file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -16,18 +16,27 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle_filetransfer;
|
package org.jivesoftware.smackx.jingle_filetransfer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||||
import org.jivesoftware.smackx.jingle.JingleUtil;
|
import org.jivesoftware.smackx.jingle.JingleUtil;
|
||||||
import org.jivesoftware.smackx.jingle.Role;
|
import org.jivesoftware.smackx.jingle.Role;
|
||||||
|
import org.jivesoftware.smackx.jingle.element.JingleReason;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
||||||
|
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
||||||
|
|
||||||
import org.jxmpp.jid.FullJid;
|
import org.jxmpp.jid.FullJid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class representing a Jingle session in the context of Jingle File Transfer (XEP-0234).
|
* Class representing a Jingle session in the context of Jingle File Transfer (XEP-0234).
|
||||||
*/
|
*/
|
||||||
public abstract class JingleFileTransferSession extends JingleSession {
|
public abstract class JingleFileTransferSession extends JingleSession implements FileTransferHandler {
|
||||||
|
|
||||||
|
protected final ArrayList<EndedListener> endedListeners = new ArrayList<>();
|
||||||
|
protected final ArrayList<StartedListener> startedListeners = new ArrayList<>();
|
||||||
|
|
||||||
|
protected boolean started, ended;
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
offer,
|
offer,
|
||||||
|
@ -69,6 +78,42 @@ public abstract class JingleFileTransferSession extends JingleSession {
|
||||||
return (isRequest() && isInitiator()) || (isOffer() && isResponder());
|
return (isRequest() && isInitiator()) || (isOffer() && isResponder());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFinished() {
|
||||||
|
return ended;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStarted() {
|
||||||
|
return started;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addEndedListener(EndedListener listener) {
|
||||||
|
endedListeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addStartedListener(StartedListener listener) {
|
||||||
|
startedListeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notifyEndedListeners(JingleReason.Reason reason) {
|
||||||
|
ended = true;
|
||||||
|
for (EndedListener e : endedListeners) {
|
||||||
|
e.onEnded(reason);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notifyStartedListeners() {
|
||||||
|
started = true;
|
||||||
|
for (StartedListener s : startedListeners) {
|
||||||
|
s.onStarted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XMPPConnection getConnection() {
|
public XMPPConnection getConnection() {
|
||||||
return connection;
|
return connection;
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.jivesoftware.smackx.jingle.JingleTransportMethodManager;
|
||||||
import org.jivesoftware.smackx.jingle.Role;
|
import org.jivesoftware.smackx.jingle.Role;
|
||||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
||||||
|
import org.jivesoftware.smackx.jingle.element.JingleReason;
|
||||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportInitiationCallback;
|
import org.jivesoftware.smackx.jingle.transports.JingleTransportInitiationCallback;
|
||||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
||||||
|
@ -45,6 +46,12 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(OutgoingJingleFileOffer.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(OutgoingJingleFileOffer.class.getName());
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cancel() {
|
||||||
|
//TODO: Actually cancel
|
||||||
|
notifyEndedListeners(JingleReason.Reason.cancel);
|
||||||
|
}
|
||||||
|
|
||||||
public enum State {
|
public enum State {
|
||||||
fresh,
|
fresh,
|
||||||
pending,
|
pending,
|
||||||
|
@ -119,9 +126,10 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
|
||||||
|
|
||||||
transportSession.initiateOutgoingSession(new JingleTransportInitiationCallback() {
|
transportSession.initiateOutgoingSession(new JingleTransportInitiationCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onSessionInitiated(final BytestreamSession session) {
|
public void onSessionInitiated(final BytestreamSession byteStream) {
|
||||||
sendingThread = new SendTask(session, source);
|
sendingThread = new SendTask(OutgoingJingleFileOffer.this, byteStream, source);
|
||||||
queued.add(JingleManager.getThreadPool().submit(sendingThread));
|
queued.add(JingleManager.getThreadPool().submit(sendingThread));
|
||||||
|
notifyStartedListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||||
|
import org.jivesoftware.smackx.jingle.element.JingleReason;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
||||||
|
|
||||||
|
@ -33,14 +34,16 @@ import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChi
|
||||||
public class ReceiveTask implements Runnable {
|
public class ReceiveTask implements Runnable {
|
||||||
private static final Logger LOGGER = Logger.getLogger(ReceiveTask.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(ReceiveTask.class.getName());
|
||||||
|
|
||||||
private final BytestreamSession session;
|
private final BytestreamSession byteStream;
|
||||||
private final JingleFileTransfer fileTransfer;
|
private final JingleFileTransfer fileTransfer;
|
||||||
private final File target;
|
private final File target;
|
||||||
|
private final JingleFileTransferSession session;
|
||||||
|
|
||||||
public ReceiveTask(BytestreamSession session, JingleFileTransfer fileTransfer, File target) {
|
public ReceiveTask(JingleFileTransferSession session, BytestreamSession byteStream, JingleFileTransfer fileTransfer, File target) {
|
||||||
this.session = session;
|
this.byteStream = byteStream;
|
||||||
this.fileTransfer = fileTransfer;
|
this.fileTransfer = fileTransfer;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
|
this.session = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,7 +54,7 @@ public class ReceiveTask implements Runnable {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
outputStream = new FileOutputStream(target);
|
outputStream = new FileOutputStream(target);
|
||||||
inputStream = session.getInputStream();
|
inputStream = byteStream.getInputStream();
|
||||||
|
|
||||||
byte[] filebuf = new byte[transfer.getSize()];
|
byte[] filebuf = new byte[transfer.getSize()];
|
||||||
int read = 0;
|
int read = 0;
|
||||||
|
@ -75,7 +78,7 @@ public class ReceiveTask implements Runnable {
|
||||||
LOGGER.log(Level.SEVERE, "Error while receiving data: ", e);
|
LOGGER.log(Level.SEVERE, "Error while receiving data: ", e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
session.close();
|
byteStream.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.log(Level.SEVERE, "Could not close InputStream.", e);
|
LOGGER.log(Level.SEVERE, "Could not close InputStream.", e);
|
||||||
}
|
}
|
||||||
|
@ -86,6 +89,8 @@ public class ReceiveTask implements Runnable {
|
||||||
LOGGER.log(Level.SEVERE, "Could not close FileOutputStream.", e);
|
LOGGER.log(Level.SEVERE, "Could not close FileOutputStream.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
session.notifyEndedListeners(JingleReason.Reason.success);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||||
|
import org.jivesoftware.smackx.jingle.element.JingleReason;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by vanitas on 21.06.17.
|
* Created by vanitas on 21.06.17.
|
||||||
|
@ -32,12 +33,14 @@ import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||||
public class SendTask implements Runnable {
|
public class SendTask implements Runnable {
|
||||||
private static final Logger LOGGER = Logger.getLogger(SendTask.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(SendTask.class.getName());
|
||||||
|
|
||||||
private final BytestreamSession session;
|
private final BytestreamSession byteStream;
|
||||||
|
private final JingleFileTransferSession session;
|
||||||
private final File source;
|
private final File source;
|
||||||
|
|
||||||
public SendTask(BytestreamSession session, File source) {
|
public SendTask(JingleFileTransferSession session, BytestreamSession byteStream, File source) {
|
||||||
this.session = session;
|
this.byteStream = byteStream;
|
||||||
this.source = source;
|
this.source = source;
|
||||||
|
this.session = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -47,7 +50,7 @@ public class SendTask implements Runnable {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
inputStream = new FileInputStream(source);
|
inputStream = new FileInputStream(source);
|
||||||
outputStream = session.getOutputStream();
|
outputStream = byteStream.getOutputStream();
|
||||||
|
|
||||||
byte[] filebuf = new byte[(int) source.length()];
|
byte[] filebuf = new byte[(int) source.length()];
|
||||||
int r = inputStream.read(filebuf);
|
int r = inputStream.read(filebuf);
|
||||||
|
@ -74,6 +77,8 @@ public class SendTask implements Runnable {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.log(Level.SEVERE, "Could not close session.", e);
|
LOGGER.log(Level.SEVERE, "Could not close session.", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
session.notifyEndedListeners(JingleReason.Reason.success);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,13 +19,14 @@ package org.jivesoftware.smackx.jingle_filetransfer.callback;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||||
|
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback used to accept/decline file offers.
|
* Callback used to accept/decline file offers.
|
||||||
*/
|
*/
|
||||||
public interface IncomingFileOfferCallback {
|
public interface IncomingFileOfferCallback {
|
||||||
|
|
||||||
void acceptIncomingFileOffer(Jingle request, File target);
|
FileTransferHandler acceptIncomingFileOffer(Jingle request, File target);
|
||||||
|
|
||||||
void declineIncomingFileOffer(Jingle request);
|
void declineIncomingFileOffer(Jingle request);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@ public interface FileTransferHandler {
|
||||||
void cancel();
|
void cancel();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true, if the file transfer is finished.
|
* Returns true, if the file transfer is ended.
|
||||||
* @return true if transfer finished.
|
* @return true if transfer ended.
|
||||||
*/
|
*/
|
||||||
boolean isFinished();
|
boolean isFinished();
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public interface FileTransferHandler {
|
||||||
void addStartedListener(StartedListener listener);
|
void addStartedListener(StartedListener listener);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify all registered FinishedListeners that the file transfer has finished.
|
* Notify all registered FinishedListeners that the file transfer has ended.
|
||||||
*/
|
*/
|
||||||
void notifyEndedListeners(JingleReason.Reason reason);
|
void notifyEndedListeners(JingleReason.Reason reason);
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ public interface FileTransferHandler {
|
||||||
void notifyStartedListeners();
|
void notifyStartedListeners();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A FinishedListener will be notified by the SendFileHandler when the corresponding file transfer is finished.
|
* A FinishedListener will be notified by the SendFileHandler when the corresponding file transfer is ended.
|
||||||
*/
|
*/
|
||||||
interface EndedListener {
|
interface EndedListener {
|
||||||
void onEnded(JingleReason.Reason reason);
|
void onEnded(JingleReason.Reason reason);
|
||||||
|
|
|
@ -1,9 +1,25 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Paul Schaub
|
||||||
|
*
|
||||||
|
* 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.jingle;
|
package org.jivesoftware.smackx.jingle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by vanitas on 06.07.17.
|
* Created by vanitas on 06.07.17.
|
||||||
*/
|
*/
|
||||||
public class JingleStreamRouter {
|
public final class JingleStreamRouter {
|
||||||
private static JingleStreamRouter INSTANCE;
|
private static JingleStreamRouter INSTANCE;
|
||||||
|
|
||||||
private JingleStreamRouter() {
|
private JingleStreamRouter() {
|
||||||
|
|
|
@ -25,6 +25,14 @@ public class JingleContentProviderManager {
|
||||||
|
|
||||||
private static final Map<String, JingleContentTransportProvider<?>> jingleContentTransportProviders = new ConcurrentHashMap<>();
|
private static final Map<String, JingleContentTransportProvider<?>> jingleContentTransportProviders = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public static void removeJingleContentTransportProvider(String namespace) {
|
||||||
|
jingleContentTransportProviders.remove(namespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeJingleContentDescriptionProvider(String namespace) {
|
||||||
|
jingleContentDescriptionProviders.remove(namespace);
|
||||||
|
}
|
||||||
|
|
||||||
public static JingleContentDescriptionProvider<?> addJingleContentDescriptionProvider(String namespace,
|
public static JingleContentDescriptionProvider<?> addJingleContentDescriptionProvider(String namespace,
|
||||||
JingleContentDescriptionProvider<?> provider) {
|
JingleContentDescriptionProvider<?> provider) {
|
||||||
return jingleContentDescriptionProviders.put(namespace, provider);
|
return jingleContentDescriptionProviders.put(namespace, provider);
|
||||||
|
|
|
@ -35,6 +35,9 @@ public class JingleContentProviderManagerTest extends SmackTestSuite {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void transportProviderTest() {
|
public void transportProviderTest() {
|
||||||
|
JingleContentProviderManager.removeJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1);
|
||||||
|
JingleContentProviderManager.removeJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1);
|
||||||
|
|
||||||
assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1));
|
assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1));
|
||||||
assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1));
|
assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1));
|
||||||
|
|
||||||
|
|
|
@ -254,7 +254,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
||||||
String xml =
|
String xml =
|
||||||
"<iq " +
|
"<iq " +
|
||||||
"to='" + romeo + "' " +
|
"to='" + romeo + "' " +
|
||||||
"from='" + romeo +"' " +
|
"from='" + romeo + "' " +
|
||||||
"id='" + j.getStanzaId() + "' " +
|
"id='" + j.getStanzaId() + "' " +
|
||||||
"type='error'>" +
|
"type='error'>" +
|
||||||
"<error type='cancel'>" +
|
"<error type='cancel'>" +
|
||||||
|
|
|
@ -29,12 +29,15 @@ import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy;
|
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy;
|
||||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||||
|
import org.jivesoftware.smackx.jingle.element.JingleReason;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.callback.IncomingFileOfferCallback;
|
import org.jivesoftware.smackx.jingle_filetransfer.callback.IncomingFileOfferCallback;
|
||||||
|
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.listener.JingleFileTransferOfferListener;
|
import org.jivesoftware.smackx.jingle_filetransfer.listener.JingleFileTransferOfferListener;
|
||||||
|
|
||||||
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
|
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
|
||||||
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
|
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
|
||||||
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
|
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
|
||||||
|
import org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.jxmpp.jid.FullJid;
|
import org.jxmpp.jid.FullJid;
|
||||||
|
|
||||||
|
@ -61,6 +64,8 @@ public class FileTransferTest extends AbstractSmackIntegrationTest {
|
||||||
|
|
||||||
@SmackIntegrationTest
|
@SmackIntegrationTest
|
||||||
public void basicFileTransferTest() {
|
public void basicFileTransferTest() {
|
||||||
|
final SimpleResultSyncPoint resultSyncPoint1 = new SimpleResultSyncPoint();
|
||||||
|
final SimpleResultSyncPoint resultSyncPoint2 = new SimpleResultSyncPoint();
|
||||||
|
|
||||||
FullJid alice = conOne.getUser().asFullJidOrThrow();
|
FullJid alice = conOne.getUser().asFullJidOrThrow();
|
||||||
FullJid bob = conTwo.getUser().asFullJidOrThrow();
|
FullJid bob = conTwo.getUser().asFullJidOrThrow();
|
||||||
|
@ -74,16 +79,40 @@ public class FileTransferTest extends AbstractSmackIntegrationTest {
|
||||||
bftm.addJingleFileTransferOfferListener(new JingleFileTransferOfferListener() {
|
bftm.addJingleFileTransferOfferListener(new JingleFileTransferOfferListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFileOffer(Jingle request, IncomingFileOfferCallback callback) {
|
public void onFileOffer(Jingle request, IncomingFileOfferCallback callback) {
|
||||||
callback.acceptIncomingFileOffer(request, target);
|
FileTransferHandler handler2 = callback.acceptIncomingFileOffer(request, target);
|
||||||
|
handler2.addEndedListener(new FileTransferHandler.EndedListener() {
|
||||||
|
@Override
|
||||||
|
public void onEnded(JingleReason.Reason reason) {
|
||||||
|
resultSyncPoint2.signal();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
aftm.sendFile(bob, source);
|
FileTransferHandler handler = aftm.sendFile(bob, source);
|
||||||
|
handler.addEndedListener(new FileTransferHandler.EndedListener() {
|
||||||
|
@Override
|
||||||
|
public void onEnded(JingleReason.Reason reason) {
|
||||||
|
resultSyncPoint1.signal();
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
|
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
resultSyncPoint1.waitForResult(10 * 1000);
|
||||||
|
} catch (Exception e) {
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
resultSyncPoint2.waitForResult(10 * 1000);
|
||||||
|
} catch (Exception e) {
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
|
||||||
byte[] sBytes = new byte[(int) source.length()];
|
byte[] sBytes = new byte[(int) source.length()];
|
||||||
byte[] tBytes = new byte[(int) target.length()];
|
byte[] tBytes = new byte[(int) target.length()];
|
||||||
try {
|
try {
|
||||||
|
@ -92,7 +121,6 @@ public class FileTransferTest extends AbstractSmackIntegrationTest {
|
||||||
fi.close();
|
fi.close();
|
||||||
fi = new FileInputStream(target);
|
fi = new FileInputStream(target);
|
||||||
fi.read(tBytes);
|
fi.read(tBytes);
|
||||||
fi.close();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.log(Level.SEVERE, "Could not read files.");
|
LOGGER.log(Level.SEVERE, "Could not read files.");
|
||||||
fail();
|
fail();
|
||||||
|
|
Loading…
Reference in a new issue