use of org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent in project ecf by eclipse.
the class TorrentFileTransfer method notifyCompletion.
private void notifyCompletion(Exception exception) {
this.exception = exception;
torrent.removePieceProgressListener(pieceListener);
torrent.removeTorrentStateListener(stateListener);
listener.handleTransferEvent(new IIncomingFileTransferReceiveDoneEvent() {
public Exception getException() {
return TorrentFileTransfer.this.exception;
}
public IIncomingFileTransfer getSource() {
return TorrentFileTransfer.this;
}
});
}
use of org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent in project ecf by eclipse.
the class URLRetrievePauseResumeTest method testReceiveHttp.
protected void testReceiveHttp(String url) throws Exception {
assertNotNull(transferInstance);
final IFileTransferListener listener = new IFileTransferListener() {
public void handleTransferEvent(IFileTransferEvent event) {
if (event instanceof IIncomingFileTransferReceiveResumedEvent) {
try {
IIncomingFileTransferReceiveResumedEvent rse = (IIncomingFileTransferReceiveResumedEvent) event;
session = rse.receive(outs);
} catch (Exception e) {
fail(e.getLocalizedMessage());
}
} else if (event instanceof IIncomingFileTransferReceiveStartEvent) {
IIncomingFileTransferReceiveStartEvent rse = (IIncomingFileTransferReceiveStartEvent) event;
try {
incomingFile = new File(FILENAME);
outs = new FileOutputStream(incomingFile);
session = rse.receive(outs);
pausable = (IFileTransferPausable) session.getAdapter(IFileTransferPausable.class);
if (pausable == null)
fail("pausable is null");
} catch (IOException e) {
fail(e.getLocalizedMessage());
}
} else if (event instanceof IIncomingFileTransferReceiveDataEvent) {
System.out.println("data=" + event);
} else if (event instanceof IIncomingFileTransferReceivePausedEvent) {
System.out.println("paused=" + event);
} else if (event instanceof IIncomingFileTransferReceiveDoneEvent) {
closeOutputStream();
System.out.println("done=" + event);
synchronized (notify) {
notify.notify();
}
}
}
};
transferInstance.sendRetrieveRequest(FileIDFactory.getDefault().createFileID(transferInstance.getRetrieveNamespace(), url), listener, null);
// Now if we can do pausing, then pause, wait a while and resume
if (pausable != null) {
Thread.sleep(500);
System.out.println("pausable.pause()=" + pausable.pause());
System.out.println("Pausing " + PAUSE_TIME / 1000 + " seconds");
Thread.sleep(PAUSE_TIME);
final boolean success = pausable.resume();
System.out.println("pausable.resume()=" + success);
if (!success) {
System.out.println("session=" + session);
final Exception e = session.getException();
System.out.println(" exception=" + e);
if (e != null)
e.printStackTrace();
System.out.println(" isDone=" + session.isDone());
return;
}
System.out.println();
}
synchronized (notify) {
notify.wait();
}
final Exception e = session.getException();
if (e != null)
throw e;
}
use of org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent in project ecf by eclipse.
the class URLRetrieveTestCancelConnectJob method testReceiveFile_cancelConnectJob.
// TODO: add test that cancel without connect job, when server does not
// respond
public void testReceiveFile_cancelConnectJob() throws Exception {
if (!CANCEL_SUPPORTED_ON_CONNECT) {
trace("WARNING: Cancel not supported by this provider. testReceiveFile_cancelConnectJob cannot be used");
return;
}
final Object[] doCancel = new Object[1];
final IFileTransferListener listener = createFileTransferListener();
final FileTransferListenerWrapper lw = new FileTransferListenerWrapper(listener) {
protected void handleStartConnectEvent(final IFileTransferConnectStartEvent event) {
assertNotNull(event.getFileID());
assertNotNull(event.getFileID().getFilename());
FileTransferJob connectJob = event.prepareConnectJob(null);
connectJob.addJobChangeListener(new JobChangeTraceListener(startTime) {
public void running(IJobChangeEvent jobEvent) {
super.running(jobEvent);
spawnCancelThread(doCancel, new ICancelable() {
public void cancel() {
assertNotNull(socketInReadWrapper);
assertTrue(socketInReadWrapper.inRead);
event.cancel();
}
});
}
});
event.connectUsingJob(connectJob);
}
};
final SimpleServer server = new SimpleServer(getName());
SimpleHttpServer simple = server.getSimpleHttpServer();
simple.setRequestHandler(new HttpRequestHandler() {
public boolean processRequest(SimpleHttpServerConnection conn, SimpleRequest request) throws IOException {
trace("Not responding to request " + request.getRequestLine());
return stalledInRequestHandler(doCancel);
}
});
try {
// path does not matter as server does not respond.
testReceive(server.getServerURL() + "/foo", lw);
assertHasEvent(startConnectEvents, IFileTransferConnectStartEvent.class);
assertHasNoEvent(startEvents, IIncomingFileTransferReceiveStartEvent.class);
assertHasNoEvent(dataEvents, IIncomingFileTransferReceiveDataEvent.class);
IIncomingFileTransferReceiveDoneEvent doneEvent = getDoneEvent();
assertTrue(doneEvent.getException().toString(), doneEvent.getException() instanceof UserCancelledException);
assertTrue(doneEvent.getSource().isDone());
assertSame(doneEvent.getException(), doneEvent.getSource().getException());
assertNull(tmpFile);
assertFalse(socketInReadWrapper.inRead);
socketEvents.validateOneSocketCreatedAndClosed();
} finally {
server.shutdown();
}
}
use of org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent in project ecf by eclipse.
the class AbstractRetrieveTestCase method checkGetDoneException.
protected Exception checkGetDoneException(Class cls) {
IIncomingFileTransferReceiveDoneEvent doneEvent = getDoneEvent();
Exception e = doneEvent.getException();
assertNotNull(e);
// assertTrue(e.getClass().getName(), cls.isInstance(e));
return e;
}
use of org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent in project ecf by eclipse.
the class XMPPFileTransferRequestListener method fileTransferRequest.
/*
* (non-Javadoc)
*
* @see
* org.jivesoftware.smackx.filetransfer.FileTransferListener#fileTransferRequest
* (org.jivesoftware.smackx.filetransfer.FileTransferRequest)
*/
public void fileTransferRequest(final FileTransferRequest request) {
requestListener.handleFileTransferRequest(new IFileTransferRequestEvent() {
boolean requestAccepted = false;
IFileTransferInfo fileTransferInfo = new IFileTransferInfo() {
Map props = new HashMap();
File f = new File(request.getFileName());
public String getDescription() {
return request.getDescription();
}
public File getFile() {
return f;
}
public Map getProperties() {
return props;
}
public Object getAdapter(Class adapter) {
if (adapter == null)
return null;
if (adapter.isInstance(this))
return this;
final IAdapterManager adapterManager = XmppPlugin.getDefault().getAdapterManager();
return (adapterManager == null) ? null : adapterManager.loadAdapter(this, adapter.getName());
}
public long getFileSize() {
return request.getFileSize();
}
public String getMimeType() {
return request.getMimeType();
}
public String toString() {
final StringBuffer buf = new StringBuffer("FileTransferInfo[");
buf.append("file=").append(f);
buf.append(";size=").append(getFileSize());
buf.append(";description=" + getDescription());
buf.append(";mimeType=").append(getMimeType()).append("]");
return buf.toString();
}
};
public IIncomingFileTransfer accept(File localFileToSave) throws IncomingFileTransferException {
try {
final OutputStream outs = new FileOutputStream(localFileToSave);
return accept(outs, new IFileTransferListener() {
public void handleTransferEvent(IFileTransferEvent event) {
if (event instanceof IIncomingFileTransferReceiveDoneEvent) {
try {
outs.close();
} catch (final IOException e) {
}
}
}
});
} catch (final FileNotFoundException e) {
throw new IncomingFileTransferException("Exception opening file for writing", e);
}
}
public IFileTransferInfo getFileTransferInfo() {
return fileTransferInfo;
}
public ID getRequesterID() {
return createIDFromName(request.getRequestor());
}
public void reject() {
request.reject();
}
public boolean requestAccepted() {
return requestAccepted;
}
public String toString() {
final StringBuffer buf = new StringBuffer("FileTransferRequestEvent[");
buf.append("requester=").append(getRequesterID());
buf.append(";requestAccepted=").append(requestAccepted());
buf.append(";transferInfo=").append(getFileTransferInfo()).append("]");
return buf.toString();
}
public IIncomingFileTransfer accept(OutputStream outputStream, IFileTransferListener listener) throws IncomingFileTransferException {
if (requestAccepted)
throw new IncomingFileTransferException("Incoming request previously accepted");
if (outputStream == null)
throw new IncomingFileTransferException("outputStream cannot be null");
incoming = request.accept();
requestAccepted = true;
try {
return new XMPPIncomingFileTransfer(IDFactory.getDefault().createStringID(request.getStreamID()), request.getFileName(), incoming.recieveFile(), outputStream, request.getFileSize(), listener);
} catch (final Exception e) {
throw new IncomingFileTransferException("Exception receiving file", e);
}
}
});
}
Aggregations