Search in sources :

Example 6 with IFileTransferListener

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);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFileID(org.eclipse.ecf.filetransfer.identity.IFileID) FileTransferJob(org.eclipse.ecf.filetransfer.FileTransferJob) IFileTransferListener(org.eclipse.ecf.filetransfer.IFileTransferListener) URL(java.net.URL)

Example 7 with IFileTransferListener

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()));
        }
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IFileTransferEvent(org.eclipse.ecf.filetransfer.events.IFileTransferEvent) IFileID(org.eclipse.ecf.filetransfer.identity.IFileID) IOutgoingFileTransferResponseEvent(org.eclipse.ecf.filetransfer.events.IOutgoingFileTransferResponseEvent) IFileTransferListener(org.eclipse.ecf.filetransfer.IFileTransferListener) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 8 with IFileTransferListener

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);
}
Also used : IFileTransferListener(org.eclipse.ecf.filetransfer.IFileTransferListener) IOException(java.io.IOException)

Example 9 with IFileTransferListener

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;
}
Also used : IIncomingFileTransferReceiveResumedEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveResumedEvent) IFileTransferPausable(org.eclipse.ecf.filetransfer.IFileTransferPausable) IIncomingFileTransferReceiveStartEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveStartEvent) IFileTransferListener(org.eclipse.ecf.filetransfer.IFileTransferListener) IOException(java.io.IOException) IOException(java.io.IOException) IFileTransferEvent(org.eclipse.ecf.filetransfer.events.IFileTransferEvent) FileOutputStream(java.io.FileOutputStream) IIncomingFileTransferReceiveDoneEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent) IIncomingFileTransferReceivePausedEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceivePausedEvent) File(java.io.File) IIncomingFileTransferReceiveDataEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDataEvent)

Example 10 with IFileTransferListener

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();
}
Also used : IFileID(org.eclipse.ecf.filetransfer.identity.IFileID) IFileTransferListener(org.eclipse.ecf.filetransfer.IFileTransferListener) URL(java.net.URL) IOException(java.io.IOException) ConnectException(java.net.ConnectException)

Aggregations

IFileTransferListener (org.eclipse.ecf.filetransfer.IFileTransferListener)18 IOException (java.io.IOException)9 IFileID (org.eclipse.ecf.filetransfer.identity.IFileID)7 File (java.io.File)5 URL (java.net.URL)5 FileTransferJob (org.eclipse.ecf.filetransfer.FileTransferJob)5 IFileTransferConnectStartEvent (org.eclipse.ecf.filetransfer.events.IFileTransferConnectStartEvent)5 IFileTransferEvent (org.eclipse.ecf.filetransfer.events.IFileTransferEvent)5 IIncomingFileTransferReceiveStartEvent (org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveStartEvent)5 IIncomingFileTransferReceiveDoneEvent (org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent)4 FileOutputStream (java.io.FileOutputStream)3 HttpRequestHandler (org.apache.commons.httpclient.server.HttpRequestHandler)3 SimpleHttpServer (org.apache.commons.httpclient.server.SimpleHttpServer)3 SimpleHttpServerConnection (org.apache.commons.httpclient.server.SimpleHttpServerConnection)3 SimpleRequest (org.apache.commons.httpclient.server.SimpleRequest)3 IncomingFileTransferException (org.eclipse.ecf.filetransfer.IncomingFileTransferException)3 SimpleServer (org.eclipse.ecf.internal.tests.filetransfer.httpserver.SimpleServer)3 UnknownHostException (java.net.UnknownHostException)2 ResponseWriter (org.apache.commons.httpclient.server.ResponseWriter)2 IFileTransferPausable (org.eclipse.ecf.filetransfer.IFileTransferPausable)2