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