Search in sources :

Example 1 with IncomingFileTransferException

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");
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) BrowseFileTransferException(org.eclipse.ecf.filetransfer.BrowseFileTransferException) HttpGet(org.apache.http.client.methods.HttpGet) ResponseContentEncoding(org.apache.http.client.protocol.ResponseContentEncoding) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException) RequestAcceptEncoding(org.apache.http.client.protocol.RequestAcceptEncoding) ECFRuntimeException(org.eclipse.ecf.core.util.ECFRuntimeException) BrowseFileTransferException(org.eclipse.ecf.filetransfer.BrowseFileTransferException) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) UnsupportedCallbackException(org.eclipse.ecf.core.security.UnsupportedCallbackException) InvalidFileRangeSpecificationException(org.eclipse.ecf.filetransfer.InvalidFileRangeSpecificationException)

Example 2 with IncomingFileTransferException

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);
    }
}
Also used : IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException) URL(java.net.URL) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException)

Example 3 with IncomingFileTransferException

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);
}
Also used : MalformedURLException(java.net.MalformedURLException) IRetrieveFileTransferContainerAdapter(org.eclipse.ecf.filetransfer.IRetrieveFileTransferContainerAdapter) URISyntaxException(java.net.URISyntaxException) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException)

Example 4 with IncomingFileTransferException

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;
    }
}
Also used : IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException) URL(java.net.URL) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedCallbackException(org.eclipse.ecf.core.security.UnsupportedCallbackException) InvalidFileRangeSpecificationException(org.eclipse.ecf.filetransfer.InvalidFileRangeSpecificationException)

Example 5 with IncomingFileTransferException

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;
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) HttpGet(org.apache.http.client.methods.HttpGet) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException) ECFRuntimeException(org.eclipse.ecf.core.util.ECFRuntimeException) BrowseFileTransferException(org.eclipse.ecf.filetransfer.BrowseFileTransferException) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) UnsupportedCallbackException(org.eclipse.ecf.core.security.UnsupportedCallbackException) InvalidFileRangeSpecificationException(org.eclipse.ecf.filetransfer.InvalidFileRangeSpecificationException)

Aggregations

IncomingFileTransferException (org.eclipse.ecf.filetransfer.IncomingFileTransferException)12 IOException (java.io.IOException)7 UnsupportedCallbackException (org.eclipse.ecf.core.security.UnsupportedCallbackException)5 FileNotFoundException (java.io.FileNotFoundException)4 InvalidFileRangeSpecificationException (org.eclipse.ecf.filetransfer.InvalidFileRangeSpecificationException)4 BrowseFileTransferException (org.eclipse.ecf.filetransfer.BrowseFileTransferException)3 IRetrieveFileTransferContainerAdapter (org.eclipse.ecf.filetransfer.IRetrieveFileTransferContainerAdapter)3 File (java.io.File)2 ConnectException (java.net.ConnectException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 UnknownHostException (java.net.UnknownHostException)2 HttpGet (org.apache.http.client.methods.HttpGet)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ECFRuntimeException (org.eclipse.ecf.core.util.ECFRuntimeException)2 IFileTransferListener (org.eclipse.ecf.filetransfer.IFileTransferListener)2 IFileTransferEvent (org.eclipse.ecf.filetransfer.events.IFileTransferEvent)2 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1