Search in sources :

Example 1 with IIncomingFileTransferReceiveDoneEvent

use of org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent in project ecf by eclipse.

the class URIProtocolFactoryRetrieveTest method testURIProtocolFactoryRetrieveFail.

public void testURIProtocolFactoryRetrieveFail() throws Exception {
    // Call sendRetrieveRequest on retrieveAdapter...this should fail as the
    // protocol factory hasn't been set
    retrieveAdapter.sendRetrieveRequest(createFileID(uri), createFileTransferListener(), null);
    waitForDone(1000);
    assertTrue(doneEvents.size() > 0);
    IIncomingFileTransferReceiveDoneEvent doneEvent = (IIncomingFileTransferReceiveDoneEvent) doneEvents.get(0);
    Exception e = doneEvent.getException();
    assertNotNull(e);
    assertTrue(e instanceof MalformedURLException);
}
Also used : MalformedURLException(java.net.MalformedURLException) IIncomingFileTransferReceiveDoneEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent) MalformedURLException(java.net.MalformedURLException) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException)

Example 2 with IIncomingFileTransferReceiveDoneEvent

use of org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent in project ecf by eclipse.

the class URLPartialRetrieveTest method testReceiveHttp.

protected void testReceiveHttp(final long start, final long end, String url) throws Exception {
    assertNotNull(transferInstance);
    final IFileTransferListener listener = new IFileTransferListener() {

        public void handleTransferEvent(IFileTransferEvent event) {
            if (event instanceof IIncomingFileTransferReceiveResumedEvent) {
                try {
                    final IIncomingFileTransferReceiveResumedEvent rse = (IIncomingFileTransferReceiveResumedEvent) event;
                    session = rse.receive(outs);
                } catch (final Exception e) {
                    fail(e.getLocalizedMessage());
                }
            } else if (event instanceof IIncomingFileTransferReceiveStartEvent) {
                final IIncomingFileTransferReceiveStartEvent rse = (IIncomingFileTransferReceiveStartEvent) event;
                try {
                    outs = new FileOutputStream(FILENAME);
                    session = rse.receive(outs);
                    pausable = (IFileTransferPausable) session.getAdapter(IFileTransferPausable.class);
                    if (pausable == null)
                        fail("pausable is null");
                } catch (final 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) {
                    isDone = true;
                    notify.notify();
                }
                session = ((IIncomingFileTransferReceiveDoneEvent) event).getSource();
            }
        }
    };
    final IFileID fileID = FileIDFactory.getDefault().createFileID(transferInstance.getRetrieveNamespace(), url);
    IFileRangeSpecification rangeSpecification = null;
    if (start != -1) {
        rangeSpecification = new IFileRangeSpecification() {

            public long getEndPosition() {
                return end;
            }

            public long getStartPosition() {
                return start;
            }
        };
    }
    transferInstance.sendRetrieveRequest(fileID, rangeSpecification, listener, null);
    if (!isDone) {
        synchronized (notify) {
            notify.wait();
        }
    }
    final Exception e = session.getException();
    if (e != null)
        throw e;
    incomingFile = new File(FILENAME);
    final long fileLength = incomingFile.length();
    final long bytesReceived = session.getBytesReceived();
    System.out.println("start=" + start);
    System.out.println("end=" + end);
    System.out.println("bytes received=" + bytesReceived);
    System.out.println("fileLength=" + fileLength);
    if (start != -1) {
        assertTrue(fileLength == bytesReceived);
        if (end != -1) {
            assertTrue(fileLength == (end - start + 1));
        }
    }
}
Also used : IIncomingFileTransferReceiveResumedEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveResumedEvent) IFileRangeSpecification(org.eclipse.ecf.filetransfer.IFileRangeSpecification) 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) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException) IFileTransferEvent(org.eclipse.ecf.filetransfer.events.IFileTransferEvent) IFileID(org.eclipse.ecf.filetransfer.identity.IFileID) FileOutputStream(java.io.FileOutputStream) IIncomingFileTransferReceiveDoneEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent) IIncomingFileTransferReceivePausedEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceivePausedEvent) IIncomingFileTransferReceiveDataEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDataEvent) File(java.io.File)

Example 3 with IIncomingFileTransferReceiveDoneEvent

use of org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent in project ecf by eclipse.

the class AbstractRetrieveTestCase method assertDoneCancelled.

protected void assertDoneCancelled() {
    IIncomingFileTransferReceiveDoneEvent doneEvent = getDoneEvent();
    assertTrue(doneEvent.getException().getClass().getName(), doneEvent.getException() instanceof UserCancelledException);
}
Also used : IIncomingFileTransferReceiveDoneEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent) UserCancelledException(org.eclipse.ecf.filetransfer.UserCancelledException)

Example 4 with IIncomingFileTransferReceiveDoneEvent

use of org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent in project ecf by eclipse.

the class AbstractRetrieveTestCase method getDoneEvent.

protected IIncomingFileTransferReceiveDoneEvent getDoneEvent() {
    assertHasEvent(doneEvents, IIncomingFileTransferReceiveDoneEvent.class);
    IIncomingFileTransferReceiveDoneEvent doneEvent = (IIncomingFileTransferReceiveDoneEvent) doneEvents.get(0);
    assertNotNull(doneEvent);
    assertTrue(doneEvent.getSource().isDone());
    assertSame(doneEvent.getException(), doneEvent.getSource().getException());
    return doneEvent;
}
Also used : IIncomingFileTransferReceiveDoneEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent)

Example 5 with IIncomingFileTransferReceiveDoneEvent

use of org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent in project ecf by eclipse.

the class AbstractRetrieveTestCase method assertDoneOK.

protected void assertDoneOK() {
    IIncomingFileTransferReceiveDoneEvent doneEvent = getDoneEvent();
    assertNull(doneEvent.getException());
}
Also used : IIncomingFileTransferReceiveDoneEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent)

Aggregations

IIncomingFileTransferReceiveDoneEvent (org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent)10 IOException (java.io.IOException)5 IFileTransferListener (org.eclipse.ecf.filetransfer.IFileTransferListener)4 IncomingFileTransferException (org.eclipse.ecf.filetransfer.IncomingFileTransferException)4 UserCancelledException (org.eclipse.ecf.filetransfer.UserCancelledException)4 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3 IFileTransferEvent (org.eclipse.ecf.filetransfer.events.IFileTransferEvent)3 IFileTransferPausable (org.eclipse.ecf.filetransfer.IFileTransferPausable)2 IIncomingFileTransfer (org.eclipse.ecf.filetransfer.IIncomingFileTransfer)2 IIncomingFileTransferReceiveDataEvent (org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDataEvent)2 IIncomingFileTransferReceivePausedEvent (org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceivePausedEvent)2 IIncomingFileTransferReceiveResumedEvent (org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveResumedEvent)2 IIncomingFileTransferReceiveStartEvent (org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveStartEvent)2 FileNotFoundException (java.io.FileNotFoundException)1 OutputStream (java.io.OutputStream)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 HttpRequestHandler (org.apache.commons.httpclient.server.HttpRequestHandler)1