Search in sources :

Example 1 with IURLConnectionModifier

use of org.eclipse.ecf.internal.provider.filetransfer.IURLConnectionModifier in project ecf by eclipse.

the class UrlConnectionRetrieveFileTransfer method connect.

protected void connect() throws IOException {
    setupTimeouts();
    urlConnection = getRemoteFileURL().openConnection();
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=235933
    if (getRemoteFileURL().getProtocol().equalsIgnoreCase("jar")) {
        // $NON-NLS-1$
        urlConnection.setUseCaches(false);
    }
    IURLConnectionModifier connectionModifier = Activator.getDefault().getURLConnectionModifier();
    if (connectionModifier != null) {
        connectionModifier.setSocketFactoryForConnection(urlConnection);
    }
}
Also used : IURLConnectionModifier(org.eclipse.ecf.internal.provider.filetransfer.IURLConnectionModifier)

Example 2 with IURLConnectionModifier

use of org.eclipse.ecf.internal.provider.filetransfer.IURLConnectionModifier 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)

Aggregations

IURLConnectionModifier (org.eclipse.ecf.internal.provider.filetransfer.IURLConnectionModifier)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URLConnection (java.net.URLConnection)1 UnsupportedCallbackException (org.eclipse.ecf.core.security.UnsupportedCallbackException)1 BrowseFileTransferException (org.eclipse.ecf.filetransfer.BrowseFileTransferException)1 IncomingFileTransferException (org.eclipse.ecf.filetransfer.IncomingFileTransferException)1