use of org.eclipse.ecf.filetransfer.IFileTransferListener in project ecf by eclipse.
the class URLRetrieveTestWithCustomJob method testReceive.
protected void testReceive(String url) throws Exception {
assertNotNull(retrieveAdapter);
final IFileTransferListener listener = createFileTransferListener();
final IFileID fileID = createFileID(new URL(url));
fileTransferJob = new FileTransferJob(fileID.getName());
fileTransferJob.addJobChangeListener(new JobChangeTraceListener(startTime));
retrieveAdapter.sendRetrieveRequest(fileID, listener, null);
waitForDone(10000);
final IStatus result = fileTransferJob.getResult();
System.out.println("job=" + fileTransferJob.getName() + " result=" + result);
assertTrue(result != null);
assertHasEvent(startEvents, IIncomingFileTransferReceiveStartEvent.class);
assertHasMoreThanEventCount(dataEvents, IIncomingFileTransferReceiveDataEvent.class, 0);
assertDoneOK();
assertTrue(tmpFile.exists());
assertTrue(tmpFile.length() > 0);
}
use of org.eclipse.ecf.filetransfer.IFileTransferListener in project ecf by eclipse.
the class XMPPCompoundContributionItem method sendFileToTarget.
private void sendFileToTarget(ISendFileTransferContainerAdapter fileTransfer, final ID targetID) {
final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
final FileDialog fd = new FileDialog(shell, SWT.OPEN);
// XXX this should be some default path set by preferences
// $NON-NLS-1$
fd.setFilterPath(System.getProperty("user.home"));
fd.setText(NLS.bind(Messages.XMPPCompoundContributionItem_CHOOSE_FILE, targetID.getName()));
final String res = fd.open();
if (res != null) {
final File aFile = new File(res);
try {
final IFileID targetFileID = FileIDFactory.getDefault().createFileID(fileTransfer.getOutgoingNamespace(), new Object[] { targetID, res });
fileTransfer.sendOutgoingRequest(targetFileID, aFile, new IFileTransferListener() {
public void handleTransferEvent(final IFileTransferEvent event) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
// bar?)
if (event instanceof IOutgoingFileTransferResponseEvent) {
if (!((IOutgoingFileTransferResponseEvent) event).requestAccepted())
MessageDialog.openInformation(shell, Messages.XMPPCompoundContributionItem_FILE_SEND_REFUSED_TITLE, NLS.bind(Messages.XMPPCompoundContributionItem_FILE_SEND_REFUSED_MESSAGE, res, targetID.getName()));
}
}
});
}
}, null);
} catch (final Exception e) {
MessageDialog.openError(shell, Messages.XMPPCompoundContributionItem_SEND_ERROR_TITLE, NLS.bind(Messages.XMPPCompoundContributionItem_SEND_ERROR_MESSAGE, res, e.getLocalizedMessage()));
}
}
}
use of org.eclipse.ecf.filetransfer.IFileTransferListener in project ecf by eclipse.
the class SCPRetrieveTest method testReceive.
public void testReceive() throws Exception {
assertNotNull(adapter);
final IFileTransferListener listener = new IFileTransferListener() {
public void handleTransferEvent(IFileTransferEvent event) {
if (event instanceof IIncomingFileTransferReceiveStartEvent) {
IIncomingFileTransferReceiveStartEvent rse = (IIncomingFileTransferReceiveStartEvent) event;
receiveStartEvents.add(rse);
assertNotNull(rse.getFileID());
assertNotNull(rse.getFileID().getFilename());
try {
rse.receive(System.out);
} catch (IOException e) {
fail(e.getLocalizedMessage());
}
} else if (event instanceof IIncomingFileTransferReceiveDataEvent) {
receiveDataEvents.add(event);
} else if (event instanceof IIncomingFileTransferReceiveDoneEvent) {
receiveDoneEvents.add(event);
syncNotify();
}
}
};
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
String targetURL = "scp://" + host + (retrieveFile.startsWith("/") ? "" : "/") + retrieveFile;
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("Retrieving from " + targetURL + " with username=" + username);
adapter.setConnectContextForAuthentication(ConnectContextFactory.createUsernamePasswordConnectContext(username, password));
adapter.sendRetrieveRequest(FileIDFactory.getDefault().createFileID(adapter.getRetrieveNamespace(), targetURL), listener, null);
syncWaitForNotify(60000);
assertHasEvent(receiveStartEvents, IIncomingFileTransferReceiveStartEvent.class);
assertHasMoreThanEventCount(receiveDataEvents, IIncomingFileTransferReceiveDataEvent.class, 0);
assertHasEvent(receiveDoneEvents, IIncomingFileTransferReceiveDoneEvent.class);
}
use of org.eclipse.ecf.filetransfer.IFileTransferListener 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.IFileTransferListener in project ecf by eclipse.
the class URLRetrieveTest method testReceiveFails.
protected void testReceiveFails(String url) throws Exception {
assertNotNull(retrieveAdapter);
final IFileTransferListener listener = createFileTransferListener();
try {
final IFileID fileID = createFileID(new URL(url));
retrieveAdapter.sendRetrieveRequest(fileID, listener, null);
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
waitForDone(10000);
assertHasNoEvent(startEvents, IIncomingFileTransferReceiveStartEvent.class);
assertHasNoEvent(dataEvents, IIncomingFileTransferReceiveDataEvent.class);
assertHasDoneEvent();
}
Aggregations