receiver.addPacketListener(new PacketListener() {
public void processPacket(Packet packet) {
IncomingTransferObject ito = incomingTransferObjectExtensionProvider
.getPayload(packet);
ConnectionTestResponse result = new ConnectionTestResponse();
result.transferMode = ito.getTransferMode();
try {
byte[] data = ito.accept(SubMonitor
.convert(new NullProgressMonitor()));
result.dataHash = Arrays.hashCode(data);
log.info(Utils.prefix(new JID(packet.getFrom()))
+ "Connection Test Data received: " + data.length
+ " bytes, hashCode==" + result.dataHash);
} catch (SarosCancellationException e) {
log.error(
"Connection Test failed because of an CancelationException",
e);
result.errorMessage = "SarosCancellationException: "
+ Utils.getMessage(e);
} catch (IOException e) {
log.error(
"Connection Test failed because of an IOException", e);
result.errorMessage = "IOException: " + Utils.getMessage(e);
}
try {
IQ iqResponse = responseProvider.createIQ(result);
iqResponse.setTo(packet.getFrom());
iqResponse.setPacketID(ito.getTransferDescription().testID);
sarosNet.getConnection().sendPacket(iqResponse);
} catch (Exception e) {
log.error(
"Could not send test results to "
+ Utils.prefix(new JID(packet.getFrom())), e);
}
}
}, new PacketFilter() {
public boolean accept(Packet packet) {
IncomingTransferObject payload = incomingTransferObjectExtensionProvider
.getPayload(packet);
if (payload == null)
return false;
return FileTransferType.CONNECTION_TEST.equals(payload
.getTransferDescription().type);
}
});
}