return true; } else if (code == HttpURLConnection.HTTP_NOT_FOUND) { throw new IncomingFileTransferException(NLS.bind("File not found: {0}", getRemoteFileURL().toString()), code, responseHeaders); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_UNAUTHORIZED) { throw new IncomingFileTransferException("Unauthorized", code, responseHeaders); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_FORBIDDEN) { throw new IncomingFileTransferException("Forbidden", code, responseHeaders); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_PROXY_AUTH) { throw new IncomingFileTransferException("Proxy authentication required", code, responseHeaders); //$NON-NLS-1$ } else { throw new IncomingFileTransferException(NLS.bind("General connection error with response code={0}", new Integer(code)), code, responseHeaders); //$NON-NLS-1$ this.exception = (e instanceof IncomingFileTransferException) ? e : new IncomingFileTransferException(NLS.bind(Messages.UrlConnectionRetrieveFileTransfer_EXCEPTION_COULD_NOT_CONNECT, getRemoteFileURL().toString()), e, code, responseHeaders); this.done = true; hardClose();
/** * Translates exceptions representing "FileNotFound" into FileNotFoundException. * @param t the throwable to check * @param toDownload the URI the exception was thrown for * @throws FileNotFoundException if 't' represents a file not found */ public static void checkFileNotFound(Throwable t, URI toDownload) throws FileNotFoundException { if (t instanceof IncomingFileTransferException) { IncomingFileTransferException e = (IncomingFileTransferException) t; if (e.getErrorCode() == 404 || e.getErrorCode() == 403 || e.getErrorCode() == 300) throw new FileNotFoundException(toDownload.toString()); } if (t instanceof BrowseFileTransferException) { BrowseFileTransferException e = (BrowseFileTransferException) t; if (e.getErrorCode() == 404 || e.getErrorCode() == 403 || e.getErrorCode() == 300) throw new FileNotFoundException(toDownload.toString()); } if (t instanceof FileNotFoundException) throw (FileNotFoundException) t; if (t instanceof CoreException) { IStatus status = ((CoreException) t).getStatus(); Throwable e = status == null ? null : status.getException(); if (e instanceof FileNotFoundException) throw (FileNotFoundException) e; } }
if (((IncomingFileTransferException) t).getErrorCode() == 401) throw new AuthenticationFailedException(); IStatus status = ((IncomingFileTransferException) t).getStatus(); t = status == null ? t : status.getException();
/** * Translates exceptions representing "FileNotFound" into FileNotFoundException. * @param t the throwable to check * @param toDownload the URI the exception was thrown for * @throws FileNotFoundException if 't' represents a file not found */ public static void checkFileNotFound(Throwable t, URI toDownload) throws FileNotFoundException { if (t instanceof IncomingFileTransferException) { IncomingFileTransferException e = (IncomingFileTransferException) t; if (e.getErrorCode() == 404 || e.getErrorCode() == 403 || e.getErrorCode() == 300) throw new FileNotFoundException(toDownload.toString()); } if (t instanceof BrowseFileTransferException) { BrowseFileTransferException e = (BrowseFileTransferException) t; if (e.getErrorCode() == 404 || e.getErrorCode() == 403 || e.getErrorCode() == 300) throw new FileNotFoundException(toDownload.toString()); } if (t instanceof FileNotFoundException) throw (FileNotFoundException) t; if (t instanceof CoreException) { IStatus status = ((CoreException) t).getStatus(); Throwable e = status == null ? null : status.getException(); if (e instanceof FileNotFoundException) throw (FileNotFoundException) e; } }
if (((IncomingFileTransferException) t).getErrorCode() == 401) throw new AuthenticationFailedException(); IStatus status = ((IncomingFileTransferException) t).getStatus(); t = status == null ? t : status.getException();
fireReceiveStartEvent(); } else if (code == HttpURLConnection.HTTP_NOT_FOUND) { throw new IncomingFileTransferException(NLS.bind("File not found: {0}", getRemoteFileURL().toString()), code, responseHeaders); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_UNAUTHORIZED) { throw new IncomingFileTransferException("Unauthorized", code, responseHeaders); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_FORBIDDEN) { throw new IncomingFileTransferException("Forbidden", code, responseHeaders); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_PROXY_AUTH) { throw new IncomingFileTransferException("Proxy authentication required", code, responseHeaders); //$NON-NLS-1$ } else { throw new IncomingFileTransferException(NLS.bind("General connection error with response code={0}", new Integer(code)), code, responseHeaders); //$NON-NLS-1$ throw new IncomingFileTransferException(NLS.bind("File not found: {0}", getRemoteFileURL().toString()), 404); //$NON-NLS-1$ } 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;
/** * Translates exceptions representing "FileNotFound" into FileNotFoundException. * @param t the throwable to check * @param toDownload the URI the exception was thrown for * @throws FileNotFoundException if 't' represents a file not found */ public static void checkFileNotFound(Throwable t, URI toDownload) throws FileNotFoundException { if (t instanceof IncomingFileTransferException) { IncomingFileTransferException e = (IncomingFileTransferException) t; if (e.getErrorCode() == 404 || e.getErrorCode() == 403 || e.getErrorCode() == 300) throw new FileNotFoundException(toDownload.toString()); } if (t instanceof BrowseFileTransferException) { BrowseFileTransferException e = (BrowseFileTransferException) t; if (e.getErrorCode() == 404 || e.getErrorCode() == 403 || e.getErrorCode() == 300) throw new FileNotFoundException(toDownload.toString()); } if (t instanceof FileNotFoundException) throw (FileNotFoundException) t; if (t instanceof CoreException) { IStatus status = ((CoreException) t).getStatus(); Throwable e = status == null ? null : status.getException(); if (e instanceof FileNotFoundException) throw (FileNotFoundException) e; } }
if (((IncomingFileTransferException) t).getErrorCode() == 401) throw new AuthenticationFailedException(); IStatus status = ((IncomingFileTransferException) t).getStatus(); t = status == null ? t : status.getException();
remoteFiles[0] = new URLRemoteFile(urlConnection.getLastModified(), urlConnection.getContentLength(), fileID); } catch (final FileNotFoundException e) { throw new IncomingFileTransferException(NLS.bind("File not found: {0}", directoryOrFile.toString()), 404); //$NON-NLS-1$ } catch (Exception e) { Exception except = (e instanceof BrowseFileTransferException) ? e : new BrowseFileTransferException(NLS.bind("Could not connect to {0}", directoryOrFile), e, code); //$NON-NLS-1$
/** * Check if the given exception represents that a switch to the JRE HTTP Client * is required. ECF sets the HTTP status code 477 to indicate this. * If the JRE HTTP client is required a JREHttpClientRequiredException is thrown. */ public static void checkJREHttpClientRequired(Throwable t) throws JREHttpClientRequiredException { if (t instanceof IncomingFileTransferException) { if (((IncomingFileTransferException) t).getErrorCode() == 477) throw new JREHttpClientRequiredException(); } else if (t instanceof BrowseFileTransferException) { if (((BrowseFileTransferException) t).getErrorCode() == 477) throw new JREHttpClientRequiredException(); } }
} else if (code == HttpURLConnection.HTTP_NOT_FOUND) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(NLS.bind("File not found: {0}", urlString), code, responseHeaders); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_UNAUTHORIZED) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(Messages.HttpClientRetrieveFileTransfer_Unauthorized, code, responseHeaders); } else if (code == HttpURLConnection.HTTP_FORBIDDEN) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException("Forbidden", code, responseHeaders); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_PROXY_AUTH) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(Messages.HttpClientRetrieveFileTransfer_Proxy_Auth_Required, code, responseHeaders); } else { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(NLS.bind(Messages.HttpClientRetrieveFileTransfer_ERROR_GENERAL_RESPONSE_CODE, new Integer(code)), code, responseHeaders); setDoneException((e instanceof IncomingFileTransferException) ? e : new IncomingFileTransferException(NLS.bind(Messages.HttpClientRetrieveFileTransfer_EXCEPTION_COULD_NOT_CONNECT, urlString), e, code, responseHeaders));
/** * Check if the given exception represents that a switch to the JRE HTTP Client * is required. ECF sets the HTTP status code 477 to indicate this. * If the JRE HTTP client is required a JREHttpClientRequiredException is thrown. */ public static void checkJREHttpClientRequired(Throwable t) throws JREHttpClientRequiredException { if (t instanceof IncomingFileTransferException) { if (((IncomingFileTransferException) t).getErrorCode() == 477) throw new JREHttpClientRequiredException(); } else if (t instanceof BrowseFileTransferException) { if (((BrowseFileTransferException) t).getErrorCode() == 477) throw new JREHttpClientRequiredException(); } }
} else if (code == HttpURLConnection.HTTP_NOT_FOUND) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(NLS.bind("File not found: {0}", urlString), code, responseHeaders); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_UNAUTHORIZED) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(Messages.HttpClientRetrieveFileTransfer_Unauthorized, code, responseHeaders); } else if (code == HttpURLConnection.HTTP_FORBIDDEN) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException("Forbidden", code, responseHeaders); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_PROXY_AUTH) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(Messages.HttpClientRetrieveFileTransfer_Proxy_Auth_Required, code, responseHeaders); } else { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(NLS.bind(Messages.HttpClientRetrieveFileTransfer_ERROR_GENERAL_RESPONSE_CODE, new Integer(code)), code, responseHeaders); setDoneException((e instanceof IncomingFileTransferException) ? e : new IncomingFileTransferException(NLS.bind(Messages.HttpClientRetrieveFileTransfer_EXCEPTION_COULD_NOT_CONNECT, urlString), e, code, responseHeaders));
/** * Check if the given exception represents that a switch to the JRE HTTP Client * is required. ECF sets the HTTP status code 477 to indicate this. * If the JRE HTTP client is required a JREHttpClientRequiredException is thrown. */ public static void checkJREHttpClientRequired(Throwable t) throws JREHttpClientRequiredException { if (t instanceof IncomingFileTransferException) { if (((IncomingFileTransferException) t).getErrorCode() == 477) throw new JREHttpClientRequiredException(); } else if (t instanceof BrowseFileTransferException) { if (((BrowseFileTransferException) t).getErrorCode() == 477) throw new JREHttpClientRequiredException(); } }
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); // We will default to JRE-provided file transfer if nothing else // available // 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); }
if (t instanceof FileNotFoundException || (t instanceof IncomingFileTransferException && ((IncomingFileTransferException) t).getErrorCode() == 404)) return new DownloadStatus(IStatus.ERROR, Activator.ID, ProvisionException.ARTIFACT_NOT_FOUND, NLS.bind(Messages.artifact_not_found, toDownload), t); if (t instanceof ConnectException) code = ((IncomingFileTransferException) t).getErrorCode(); else if (t instanceof BrowseFileTransferException) code = ((BrowseFileTransferException) t).getErrorCode();
public void sendRetrieveRequest(IFileID remoteFileID, IFileRangeSpecification rangeSpecification, 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); // We will default to JRE-provided file transfer if nothing else // available // 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, rangeSpecification, transferListener, options); }
if (t instanceof FileNotFoundException || (t instanceof IncomingFileTransferException && ((IncomingFileTransferException) t).getErrorCode() == 404)) return new DownloadStatus(IStatus.ERROR, Activator.ID, ProvisionException.ARTIFACT_NOT_FOUND, NLS.bind(Messages.artifact_not_found, toDownload), t); if (t instanceof ConnectException) code = ((IncomingFileTransferException) t).getErrorCode(); else if (t instanceof BrowseFileTransferException) code = ((BrowseFileTransferException) t).getErrorCode();
throw new IncomingFileTransferException("HttpClient Provider is not configured to support NTLM proxy authentication.", HttpClientOptions.NTLM_PROXY_RESPONSE_CODE); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_NOT_FOUND) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(NLS.bind("File not found: {0}", urlString), code); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_UNAUTHORIZED) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(Messages.HttpClientRetrieveFileTransfer_Unauthorized, code); } else if (code == HttpURLConnection.HTTP_FORBIDDEN) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException("Forbidden", code); //$NON-NLS-1$ } else if (code == HttpURLConnection.HTTP_PROXY_AUTH) { EntityUtils.consume(httpResponse.getEntity()); throw new IncomingFileTransferException(Messages.HttpClientRetrieveFileTransfer_Proxy_Auth_Required, code); } else { Trace.trace(Activator.PLUGIN_ID, EntityUtils.toString(httpResponse.getEntity())); throw new IncomingFileTransferException(NLS.bind(Messages.HttpClientRetrieveFileTransfer_ERROR_GENERAL_RESPONSE_CODE, new Integer(code)), code); IncomingFileTransferException ex = (IncomingFileTransferException) ((e instanceof IncomingFileTransferException) ? e : new IncomingFileTransferException(NLS.bind(Messages.HttpClientRetrieveFileTransfer_EXCEPTION_COULD_NOT_CONNECT, urlString), e, code)); throw ex;
public static DownloadStatus forException(Throwable t, URI toDownload) { if (t instanceof FileNotFoundException || (t instanceof IncomingFileTransferException && ((IncomingFileTransferException) t).getErrorCode() == 404)) return new DownloadStatus(IStatus.ERROR, Activator.ID, ProvisionException.ARTIFACT_NOT_FOUND, NLS.bind(Messages.artifact_not_found, toDownload), t); if (t instanceof ConnectException) code = ((IncomingFileTransferException) t).getErrorCode(); else if (t instanceof BrowseFileTransferException) code = ((BrowseFileTransferException) t).getErrorCode();