Search in sources :

Example 6 with IncomingFileTransferException

use of org.eclipse.ecf.filetransfer.IncomingFileTransferException in project ecf by eclipse.

the class MultiProtocolRetrieveAdapter method sendRetrieveRequest.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.filetransfer.IRetrieveFileTransferContainerAdapter#sendRetrieveRequest(org.eclipse.ecf.filetransfer.identity.IFileID,
	 *      org.eclipse.ecf.filetransfer.IFileTransferListener, java.util.Map)
	 */
public void sendRetrieveRequest(IFileID remoteFileID, IFileTransferListener transferListener, Map options) throws IncomingFileTransferException {
    Assert.isNotNull(remoteFileID);
    Assert.isNotNull(transferListener);
    String protocol = null;
    try {
        protocol = remoteFileID.getURI().getScheme();
    } catch (URISyntaxException e) {
        try {
            protocol = remoteFileID.getURL().getProtocol();
        } catch (final MalformedURLException e1) {
            throw new IncomingFileTransferException(Messages.AbstractRetrieveFileTransfer_MalformedURLException);
        }
    }
    IRetrieveFileTransferContainerAdapter fileTransfer = Activator.getDefault().getFileTransfer(protocol);
    // for given protocol
    if (fileTransfer == null)
        fileTransfer = new UrlConnectionRetrieveFileTransfer();
    // Set connect context
    fileTransfer.setConnectContextForAuthentication(connectContext);
    // Set Proxy
    fileTransfer.setProxy(proxy);
    // send request using given file transfer protocol
    fileTransfer.sendRetrieveRequest(remoteFileID, transferListener, options);
}
Also used : MalformedURLException(java.net.MalformedURLException) IRetrieveFileTransferContainerAdapter(org.eclipse.ecf.filetransfer.IRetrieveFileTransferContainerAdapter) URISyntaxException(java.net.URISyntaxException) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException)

Example 7 with IncomingFileTransferException

use of org.eclipse.ecf.filetransfer.IncomingFileTransferException in project ecf by eclipse.

the class UrlConnectionRetrieveFileTransfer method openStreams.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ecf.provider.filetransfer.retrieve.AbstractRetrieveFileTransfer
	 * #openStreams()
	 */
protected void openStreams() throws IncomingFileTransferException {
    int code = -1;
    try {
        setupAuthentication();
        connect();
        setRequestHeaderValues();
        // Make actual GET request
        // need to get response header about encoding before setting stream
        setCompressionRequestHeader();
        setInputStream(getDecompressedStream());
        code = getResponseCode();
        responseHeaders = getResponseHeaders();
        if (isHTTP()) {
            if (code == HttpURLConnection.HTTP_PARTIAL || code == HttpURLConnection.HTTP_OK) {
                fireReceiveStartEvent();
            } else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
                // $NON-NLS-1$
                throw new IncomingFileTransferException(NLS.bind("File not found: {0}", getRemoteFileURL().toString()), code, responseHeaders);
            } else if (code == HttpURLConnection.HTTP_UNAUTHORIZED) {
                // $NON-NLS-1$
                throw new IncomingFileTransferException("Unauthorized", code, responseHeaders);
            } else if (code == HttpURLConnection.HTTP_FORBIDDEN) {
                // $NON-NLS-1$
                throw new IncomingFileTransferException("Forbidden", code, responseHeaders);
            } else if (code == HttpURLConnection.HTTP_PROXY_AUTH) {
                // $NON-NLS-1$
                throw new IncomingFileTransferException("Proxy authentication required", code, responseHeaders);
            } else {
                // $NON-NLS-1$
                throw new IncomingFileTransferException(NLS.bind("General connection error with response code={0}", new Integer(code)), code, responseHeaders);
            }
        } else {
            fireReceiveStartEvent();
        }
    } catch (final FileNotFoundException e) {
        // $NON-NLS-1$
        throw new IncomingFileTransferException(NLS.bind("File not found: {0}", getRemoteFileURL().toString()), 404);
    } catch (final Exception e) {
        IncomingFileTransferException except = (e instanceof IncomingFileTransferException) ? (IncomingFileTransferException) e : new IncomingFileTransferException(NLS.bind(Messages.UrlConnectionRetrieveFileTransfer_EXCEPTION_COULD_NOT_CONNECT, getRemoteFileURL().toString()), e, code, responseHeaders);
        hardClose();
        throw except;
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedCallbackException(org.eclipse.ecf.core.security.UnsupportedCallbackException) InvalidFileRangeSpecificationException(org.eclipse.ecf.filetransfer.InvalidFileRangeSpecificationException)

Example 8 with IncomingFileTransferException

use of org.eclipse.ecf.filetransfer.IncomingFileTransferException in project ecf by eclipse.

the class URLFileSystemBrowser method runRequest.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.provider.filetransfer.browse.AbstractFileSystemBrowser#runRequest()
	 */
protected void runRequest() throws Exception {
    int code = -1;
    try {
        setupProxies();
        setupAuthentication();
        setupTimeouts();
        URLConnection urlConnection = directoryOrFile.openConnection();
        // this is for addressing bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=235933
        if (directoryOrFile.getProtocol().equalsIgnoreCase("jar")) {
            // $NON-NLS-1$
            urlConnection.setUseCaches(false);
        }
        // Add http 1.1 'Connection: close' header in order to potentially avoid
        // server issue described here https://bugs.eclipse.org/bugs/show_bug.cgi?id=234916#c13
        // See bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=247197
        // also see http 1.1 rfc section 14-10 in http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
        // $NON-NLS-1$ //$NON-NLS-2$
        urlConnection.setRequestProperty("Connection", "close");
        IURLConnectionModifier connectionModifier = Activator.getDefault().getURLConnectionModifier();
        if (connectionModifier != null) {
            connectionModifier.setSocketFactoryForConnection(urlConnection);
        }
        if (urlConnection instanceof HttpURLConnection) {
            HttpURLConnection httpConnection = (HttpURLConnection) urlConnection;
            // $NON-NLS-1$
            httpConnection.setRequestMethod("HEAD");
            httpConnection.connect();
        } else {
            InputStream ins = urlConnection.getInputStream();
            ins.close();
        }
        code = getResponseCode(urlConnection);
        if (isHTTP()) {
            if (code == HttpURLConnection.HTTP_OK) {
            // do nothing
            } else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
                // $NON-NLS-1$
                throw new BrowseFileTransferException(NLS.bind("File not found: {0}", directoryOrFile.toString()), code);
            } else if (code == HttpURLConnection.HTTP_UNAUTHORIZED) {
                // $NON-NLS-1$
                throw new BrowseFileTransferException("Unauthorized", code);
            } else if (code == HttpURLConnection.HTTP_FORBIDDEN) {
                // $NON-NLS-1$
                throw new BrowseFileTransferException("Forbidden", code);
            } else if (code == HttpURLConnection.HTTP_PROXY_AUTH) {
                // $NON-NLS-1$
                throw new BrowseFileTransferException("Proxy auth required", code);
            } else {
                // $NON-NLS-1$
                throw new BrowseFileTransferException(NLS.bind("General connection error with response code={0} and header(0)={1}", new Integer(code), urlConnection.getHeaderField(0)), code);
            }
        }
        remoteFiles = new IRemoteFile[1];
        remoteFiles[0] = new URLRemoteFile(urlConnection.getLastModified(), urlConnection.getContentLength(), fileID);
    } catch (final FileNotFoundException e) {
        // $NON-NLS-1$
        throw new IncomingFileTransferException(NLS.bind("File not found: {0}", directoryOrFile.toString()), 404);
    } catch (Exception e) {
        // $NON-NLS-1$
        Exception except = (e instanceof BrowseFileTransferException) ? e : new BrowseFileTransferException(NLS.bind("Could not connect to {0}", directoryOrFile), e, code);
        throw except;
    }
}
Also used : BrowseFileTransferException(org.eclipse.ecf.filetransfer.BrowseFileTransferException) HttpURLConnection(java.net.HttpURLConnection) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException) BrowseFileTransferException(org.eclipse.ecf.filetransfer.BrowseFileTransferException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedCallbackException(org.eclipse.ecf.core.security.UnsupportedCallbackException) IURLConnectionModifier(org.eclipse.ecf.internal.provider.filetransfer.IURLConnectionModifier)

Example 9 with IncomingFileTransferException

use of org.eclipse.ecf.filetransfer.IncomingFileTransferException in project ecf by eclipse.

the class AbstractRetrieveTestCase method assertIncomingFileExceptionWithCause.

protected void assertIncomingFileExceptionWithCause(int expectedCode) {
    IncomingFileTransferException e = checkGetDoneIncomimgFileTransferException();
    int code = e.getErrorCode();
    assertTrue(code != -1);
    assertTrue(code == expectedCode);
}
Also used : IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException)

Example 10 with IncomingFileTransferException

use of org.eclipse.ecf.filetransfer.IncomingFileTransferException in project ecf by eclipse.

the class AbstractRetrieveTestCase method checkGetDoneIncomimgFileTransferException.

protected IncomingFileTransferException checkGetDoneIncomimgFileTransferException() {
    IncomingFileTransferException e = (IncomingFileTransferException) checkGetDoneException(IncomingFileTransferException.class);
    assertNotNull(e);
    return e;
}
Also used : IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException)

Aggregations

IncomingFileTransferException (org.eclipse.ecf.filetransfer.IncomingFileTransferException)12 IOException (java.io.IOException)7 UnsupportedCallbackException (org.eclipse.ecf.core.security.UnsupportedCallbackException)5 FileNotFoundException (java.io.FileNotFoundException)4 InvalidFileRangeSpecificationException (org.eclipse.ecf.filetransfer.InvalidFileRangeSpecificationException)4 BrowseFileTransferException (org.eclipse.ecf.filetransfer.BrowseFileTransferException)3 IRetrieveFileTransferContainerAdapter (org.eclipse.ecf.filetransfer.IRetrieveFileTransferContainerAdapter)3 File (java.io.File)2 ConnectException (java.net.ConnectException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 UnknownHostException (java.net.UnknownHostException)2 HttpGet (org.apache.http.client.methods.HttpGet)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ECFRuntimeException (org.eclipse.ecf.core.util.ECFRuntimeException)2 IFileTransferListener (org.eclipse.ecf.filetransfer.IFileTransferListener)2 IFileTransferEvent (org.eclipse.ecf.filetransfer.events.IFileTransferEvent)2 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1