use of org.eclipse.ecf.filetransfer.IncomingFileTransferException in project ecf by eclipse.
the class HttpClientRetrieveFileTransfer method openStreams.
/* (non-Javadoc)
* @see org.eclipse.ecf.provider.filetransfer.retrieve.AbstractRetrieveFileTransfer#openStreams()
*/
protected void openStreams() throws IncomingFileTransferException {
// $NON-NLS-1$
Trace.entering(Activator.PLUGIN_ID, DebugOptions.METHODS_ENTERING, this.getClass(), "openStreams");
final String urlString = getRemoteFileURL().toString();
this.doneFired = false;
int code = -1;
try {
httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, getSocketReadTimeout());
int connectTimeout = getConnectTimeout();
httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectTimeout);
setupAuthentication(urlString);
getMethod = new HttpGet(urlString);
// Define a CredentialsProvider - found that possibility while debugging in org.apache.commons.httpclient.HttpMethodDirector.processProxyAuthChallenge(HttpMethod)
// Seems to be another way to select the credentials.
setRequestHeaderValues();
// $NON-NLS-1$
Trace.trace(Activator.PLUGIN_ID, "retrieve=" + urlString);
// 2) The target remote file does *not* end in .gz (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=280205)
if (getFileRangeSpecification() == null && !targetHasGzSuffix(super.getRemoteFileName())) {
// $NON-NLS-1$
Trace.trace(Activator.PLUGIN_ID, "Accept-Encoding: gzip,deflate added to request header");
// Add the interceptors to provide the gzip
httpClient.addRequestInterceptor(new RequestAcceptEncoding());
httpClient.addResponseInterceptor(new ResponseContentEncoding());
} else {
// $NON-NLS-1$
Trace.trace(Activator.PLUGIN_ID, "Accept-Encoding NOT added to header");
}
fireConnectStartEvent();
if (checkAndHandleDone()) {
return;
}
connectingSockets.clear();
// redirect response code handled internally
if (connectJob == null) {
performConnect(new NullProgressMonitor());
} else {
connectJob.schedule();
connectJob.join();
connectJob = null;
}
if (checkAndHandleDone()) {
return;
}
code = responseCode;
responseHeaders = getResponseHeaders();
// $NON-NLS-1$
Trace.trace(Activator.PLUGIN_ID, "retrieve resp=" + code);
// Check for NTLM proxy in response headers
// This check is to deal with bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=252002
boolean ntlmProxyFound = NTLMProxyDetector.detectNTLMProxy(httpContext);
if (ntlmProxyFound && !hasForceNTLMProxyOption())
// $NON-NLS-1$
throw new IncomingFileTransferException("HttpClient Provider is not configured to support NTLM proxy authentication.", HttpClientOptions.NTLM_PROXY_RESPONSE_CODE);
if (NTLMProxyDetector.detectSPNEGOProxy(httpContext))
// $NON-NLS-1$
throw new BrowseFileTransferException("HttpClient Provider does not support the use of SPNEGO proxy authentication.");
if (code == HttpURLConnection.HTTP_PARTIAL || code == HttpURLConnection.HTTP_OK) {
getResponseHeaderValues();
setInputStream(httpResponse.getEntity().getContent());
fireReceiveStartEvent();
} else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
EntityUtils.consume(httpResponse.getEntity());
// $NON-NLS-1$
throw new IncomingFileTransferException(NLS.bind("File not found: {0}", urlString), code);
} 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());
// $NON-NLS-1$
throw new IncomingFileTransferException("Forbidden", code);
} 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()));
// EntityUtils.consume(httpResponse.getEntity());
throw new IncomingFileTransferException(NLS.bind(Messages.HttpClientRetrieveFileTransfer_ERROR_GENERAL_RESPONSE_CODE, new Integer(code)), code);
}
} catch (final Exception e) {
// $NON-NLS-1$
Trace.throwing(Activator.PLUGIN_ID, DebugOptions.EXCEPTIONS_THROWING, this.getClass(), "openStreams", e);
if (code == -1) {
if (!isDone()) {
setDoneException(e);
}
fireTransferReceiveDoneEvent();
} else {
IncomingFileTransferException ex = (IncomingFileTransferException) ((e instanceof IncomingFileTransferException) ? e : new IncomingFileTransferException(NLS.bind(Messages.HttpClientRetrieveFileTransfer_EXCEPTION_COULD_NOT_CONNECT, urlString), e, code));
throw ex;
}
}
// $NON-NLS-1$
Trace.exiting(Activator.PLUGIN_ID, DebugOptions.METHODS_EXITING, this.getClass(), "openStreams");
}
use of org.eclipse.ecf.filetransfer.IncomingFileTransferException in project ecf by eclipse.
the class ScpRetrieveFileTransfer method openStreams.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ecf.provider.filetransfer.outgoing.AbstractOutgoingFileTransfer
* #openStreams()
*/
protected void openStreams() throws IncomingFileTransferException {
try {
// Set input stream from local file
final URL url = getRemoteFileURL();
this.username = url.getUserInfo();
scpUtil = new ScpUtil(this);
final Session s = scpUtil.getSession();
s.connect();
final String command = SCP_COMMAND + scpUtil.trimTargetFile(url.getPath());
channel = s.openChannel(SCP_EXEC);
((ChannelExec) channel).setCommand(command);
channel.connect();
final InputStream ins = channel.getInputStream();
responseStream = channel.getOutputStream();
scpUtil.sendZeroToStream(responseStream);
final int c = checkAck(ins);
if (c != 'C')
throw new IOException(Messages.ScpRetrieveFileTransfer_EXCEPTION_SCP_PROTOCOL);
// read '0644 '
final byte[] buf = new byte[1024];
ins.read(buf, 0, 5);
setFileLength(readFileSize(ins, buf));
readFileName(ins, buf);
// set input stream for reading rest of file
remoteFileContents = ins;
scpUtil.sendZeroToStream(responseStream);
fireReceiveStartEvent();
} catch (final Exception e) {
channel = null;
username = null;
throw new IncomingFileTransferException(NLS.bind(Messages.ScpRetrieveFileTransfer_EXCEPTION_CONNECTING, getRemoteFileURL().toString()), e);
}
}
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.IFileRangeSpecification,
* org.eclipse.ecf.filetransfer.IFileTransferListener, java.util.Map)
*/
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);
// 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);
}
use of org.eclipse.ecf.filetransfer.IncomingFileTransferException in project ecf by eclipse.
the class UrlConnectionRetrieveFileTransfer method openStreamsForResume.
/**
* @return <code>true</code> if streams successfully, <code>false</code>
* otherwise.
*/
private boolean openStreamsForResume() {
final URL theURL = getRemoteFileURL();
int code = -1;
try {
remoteFileURL = new URL(theURL.toString());
setupAuthentication();
connect();
setResumeRequestHeaderValues();
// Make actual GET request
setInputStream(urlConnection.getInputStream());
code = getResponseCode();
responseHeaders = getResponseHeaders();
if (code == HttpURLConnection.HTTP_PARTIAL || code == HttpURLConnection.HTTP_OK) {
getResumeResponseHeaderValues();
this.paused = false;
fireReceiveResumedEvent();
return true;
} 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);
}
} catch (final Exception e) {
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();
fireTransferReceiveDoneEvent();
return false;
}
}
use of org.eclipse.ecf.filetransfer.IncomingFileTransferException in project ecf by eclipse.
the class HttpClientRetrieveFileTransfer method openStreamsForResume.
private boolean openStreamsForResume() {
// $NON-NLS-1$
Trace.entering(Activator.PLUGIN_ID, DebugOptions.METHODS_ENTERING, this.getClass(), "openStreamsForResume");
final String urlString = getRemoteFileURL().toString();
this.doneFired = false;
int code = -1;
try {
httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, getSocketReadTimeout());
int connectTimeout = getConnectTimeout();
httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectTimeout);
setupAuthentication(urlString);
getMethod = new HttpGet(urlString);
// Define a CredentialsProvider - found that possibility while debugging in org.apache.commons.httpclient.HttpMethodDirector.processProxyAuthChallenge(HttpMethod)
// Seems to be another way to select the credentials.
setResumeRequestHeaderValues();
// $NON-NLS-1$
Trace.trace(Activator.PLUGIN_ID, "resume=" + urlString);
// Gzip encoding is not an option for resume
fireConnectStartEvent();
if (checkAndHandleDone()) {
return false;
}
connectingSockets.clear();
// redirect response code handled internally
if (connectJob == null) {
performConnect(new NullProgressMonitor());
} else {
connectJob.schedule();
connectJob.join();
connectJob = null;
}
if (checkAndHandleDone()) {
return false;
}
code = responseCode;
responseHeaders = getResponseHeaders();
// $NON-NLS-1$
Trace.trace(Activator.PLUGIN_ID, "retrieve resp=" + code);
if (code == HttpURLConnection.HTTP_PARTIAL || code == HttpURLConnection.HTTP_OK) {
getResumeResponseHeaderValues();
setInputStream(httpResponse.getEntity().getContent());
this.paused = false;
fireReceiveResumedEvent();
} else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
EntityUtils.consume(httpResponse.getEntity());
// $NON-NLS-1$
throw new IncomingFileTransferException(NLS.bind("File not found: {0}", urlString), code, responseHeaders);
} 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());
// $NON-NLS-1$
throw new IncomingFileTransferException("Forbidden", code, responseHeaders);
} 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);
}
// $NON-NLS-1$
Trace.exiting(Activator.PLUGIN_ID, DebugOptions.METHODS_EXITING, this.getClass(), "openStreamsForResume", Boolean.TRUE);
return true;
} catch (final Exception e) {
// $NON-NLS-1$
Trace.catching(Activator.PLUGIN_ID, DebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "openStreamsForResume", e);
if (code == -1) {
if (!isDone()) {
setDoneException(e);
}
} else {
setDoneException((e instanceof IncomingFileTransferException) ? e : new IncomingFileTransferException(NLS.bind(Messages.HttpClientRetrieveFileTransfer_EXCEPTION_COULD_NOT_CONNECT, urlString), e, code, responseHeaders));
}
fireTransferReceiveDoneEvent();
// $NON-NLS-1$
Trace.exiting(Activator.PLUGIN_ID, DebugOptions.METHODS_EXITING, this.getClass(), "openStreamsForResume", Boolean.FALSE);
return false;
}
}
Aggregations