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);
}
}
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;
}
}
Aggregations