I monitor the file transfer and it is sent correctly. When my user(s) connect and login to Openfire, I add a listener to listen to file transfers:
final FileTransferManager manager = FileTransferManager.getInstanceFor(connection);
// FileTransferNegotiator.setServiceEnabled(connection, true);
manager.addFileTransferListener((FileTransferRequest request) -> {
// Check to see if the request should be accepted
if (request.getFileName() != null) {
try {
// Accept it
IncomingFileTransfer transfer = request.accept();
// monitorFileTransfer(transfer, "");
try (InputStream fileReceived = transfer.receiveFile();
BufferedInputStream bis = new BufferedInputStream(fileReceived)) {
...
} else {
try {
// Reject it
request.reject();
LOG.warning("File rejected " + request.getFileName());
} catch (SmackException.NotConnectedException | InterruptedException ex) {
LOG.log(Level.SEVERE, null, ex);
}
}
However, the listener is never called. Do I need to add the listener at a specific moment? Is there something else I 've been missing? The results is that the file transfers are being sent to Openfire and are never consumed.
Thank you for your reply. However, I have reported according to the guidelines you mention.
The Smack version (e.g. obtained via SmackConfiguration.getVersion() ) ==> 4.3.4 already mentioned
The exception and the full stacktrace (if applicable). Note that some exceptions, e.g. plain SmackException or ExecutionException, wrap the causing exception. Make sure to take those into consideration. ==> No exception
An XMPP trace of the exchanged stream elements between client and server, which can be obtained by setting SmackConfiguration.DEBUG ( DEBUG_ENABLED in older Smack versions) to true . ==> I missed; I present it below
The relevant code parts (please do not post whole source files!) ==> already mentioned in my original post
INFO: Initializing connection to server localhost port 5222 [Wed Apr 29 15:36:25 CEST 2020]
INFO: Connected: true [Wed Apr 29 15:36:45 CEST 2020]
INFO: user001 authenticated? true [Wed Apr 29 15:36:46 CEST 2020]
...
INFO: Sending attachment 'test.txt' to user user002@localhost [Wed Apr 29 15:36:55 CEST 2020]
INFO: status is:Initial [Wed Apr 29 15:36:55 CEST 2020]
INFO: status is:Initial [Wed Apr 29 15:36:55 CEST 2020]
INFO: File transfer status: Negotiating Transfer, progress: 0.0 [Wed Apr 29 15:36:55 CEST 2020]
INFO: test.txt has been successfully transferred. [Wed Apr 29 15:36:56 CEST 2020]
INFO: The file transfer is done. [Wed Apr 29 15:36:56 CEST 2020]
INFO: Attachment test.txt sent from user001@localhost to user002@localhost [Wed Apr 29 15:36:56 CEST 2020]
Regarding smack debug, I 'm not sure what to post. These are the last stanzas:
The file transfer was not actually happening this is why the listener was listening but wa receiving nothing.
To send a file you need the full JID of the recipient. If you use smack, there is no physical XMPP client (like spark). In that case you use “Smack” or “Resource” (see here).
And of course the problem had nothing to do with smack. The issue was that the tool I have created was reading and writing to the same file, as a result, the file was erased and the error was because smack was requested to transfer an empty file. So, if you see this error, check the file you try to transfer first; it might have 0 bytes.