Class HttpClientRetrieveFileTransfer
- java.lang.Object
-
- org.eclipse.ecf.provider.filetransfer.retrieve.AbstractRetrieveFileTransfer
-
- org.eclipse.ecf.provider.filetransfer.httpclient5.HttpClientRetrieveFileTransfer
-
- All Implemented Interfaces:
org.eclipse.core.runtime.IAdaptable,IIdentifiable,IFileTransfer,IFileTransferPausable,IIncomingFileTransfer,IRetrieveFileTransferContainerAdapter,IRetrieveFileTransfer
public class HttpClientRetrieveFileTransfer extends AbstractRetrieveFileTransfer
-
-
Field Summary
Fields Modifier and Type Field Description protected IFileIDfileidprotected static StringHTTPprotected static intHTTP_PORTprotected static StringHTTPSprotected static intHTTPS_PORTprotected inthttpVersionprotected static intMAX_RETRYprotected JREProxyHelperproxyHelperprotected static String[]supportedProtocols-
Fields inherited from class org.eclipse.ecf.provider.filetransfer.retrieve.AbstractRetrieveFileTransfer
buff_length, bytesReceived, CLOSE_TIMEOUT, closeOutputStream, connectContext, DEFAULT_BUF_LENGTH, done, downloadRateBytesPerSecond, exception, fileLength, job, jobLock, lastModifiedTime, listener, localFileContents, options, paused, POLLING_RETRY_ATTEMPTS, proxy, rangeSpecification, READ_TIMEOUT, remoteFileContents, remoteFileID, remoteFileURL, responseHeaders, TIMEOUT_INPUTSTREAM_BUFFER_SIZE, transferStartTime
-
-
Constructor Summary
Constructors Constructor Description HttpClientRetrieveFileTransfer(org.apache.hc.client5.http.impl.classic.CloseableHttpClient client)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()Cancel this file transfer.protected voidclearProxy()This method will clear out the proxy information (so that if this is reused for a request without a proxy, it will work correctly).protected voidconnectUsingJob(FileTransferJob cjob)protected StringcreateConnectJobName()protected booleandoPause()Subclass overridable version ofAbstractRetrieveFileTransfer.pause().protected booleandoResume()Subclass overridable version ofAbstractRetrieveFileTransfer.resume().protected voidfireConnectStartEvent()protected voidfireReceiveResumedEvent()protected voidfireTransferReceiveDataEvent()protected voidfireTransferReceiveDoneEvent()protected voidfireTransferReceivePausedEvent()<T> TgetAdapter(Class<T> adapter)protected intgetConnectTimeout()protected org.apache.hc.client5.http.auth.CredentialsgetFileRequestCredentials()protected static StringgetHostFromURL(String url)IDgetID()Return the ID for this 'identifiable' object.protected static intgetPortFromURL(String url)StringgetRemoteFileName()Obtains the name of the remote file if possible.intgetResponseCode()protected voidgetResponseHeaderValues()protected voidgetResumeResponseHeaderValues()protected intgetSocketReadTimeout()protected voidhardClose()protected booleanisConnected()protected voidopenStreams()Open incoming and outgoing streams associated with this file transfer.protected FileTransferJobprepareConnectJob(FileTransferJob cjob)protected voidresetDoneAndException()voidsetConnectContextForAuthentication(IConnectContext connectContext)Set connect context for authentication upon subsequentIRetrieveFileTransferContainerAdapter.sendRetrieveRequest(IFileID, IFileTransferListener, Map).protected voidsetInputStream(InputStream ins)protected voidsetRequestHeaderValues()protected voidsetResumeRequestHeaderValues()protected voidsetupAuthentication(String urlString)protected voidsetupProxies()protected voidsetupProxy(Proxy proxy)Setup ECF proxy.static booleansupportsProtocol(String protocolString)protected static booleanurlUsesHttps(String url)protected InputStreamwrapTransferReadInputStream(InputStream inputStream, org.eclipse.core.runtime.IProgressMonitor monitor)-
Methods inherited from class org.eclipse.ecf.provider.filetransfer.retrieve.AbstractRetrieveFileTransfer
createJobName, createRangeName, fireReceiveStartEvent, getBytesReceived, getException, getFileLength, getFileRangeSpecification, getFinalStatus, getListener, getOptions, getPercentComplete, getRemoteFileURL, getRemoteLastModified, getRetrieveNamespace, getSocketCloseTimeout, handleReceivedData, isCanceled, isDone, isPaused, newUserCancelledException, pause, resume, selectProxyFromProxies, sendRetrieveRequest, sendRetrieveRequest, setCloseOutputStream, setDone, setDoneCanceled, setDoneCanceled, setDoneException, setFileLength, setLastModifiedTime, setOutputStream, setProxy, setupAndScheduleJob, targetHasGzSuffix, toHumanReadableBytes
-
-
-
-
Field Detail
-
HTTP_PORT
protected static final int HTTP_PORT
- See Also:
- Constant Field Values
-
HTTPS_PORT
protected static final int HTTPS_PORT
- See Also:
- Constant Field Values
-
MAX_RETRY
protected static final int MAX_RETRY
- See Also:
- Constant Field Values
-
HTTPS
protected static final String HTTPS
- See Also:
- Constant Field Values
-
HTTP
protected static final String HTTP
- See Also:
- Constant Field Values
-
supportedProtocols
protected static final String[] supportedProtocols
-
httpVersion
protected int httpVersion
-
fileid
protected IFileID fileid
-
proxyHelper
protected JREProxyHelper proxyHelper
-
-
Method Detail
-
getRemoteFileName
public String getRemoteFileName()
Description copied from interface:IIncomingFileTransferObtains the name of the remote file if possible. The name will typically but not necessarily be the same as the leaf part of the path to the remote file.- Specified by:
getRemoteFileNamein interfaceIIncomingFileTransfer- Overrides:
getRemoteFileNamein classAbstractRetrieveFileTransfer- Returns:
- The name of the remote file or
nullif no such name can be determined.
-
cancel
public void cancel()
Description copied from interface:IFileTransferCancel this file transfer. If file transfer has already been completed, then this method has no effect. If the file transfer has not been completed then calling this method will result in anIFileTransferEventbeing delivered to theIFileTransferListenerindicating that transfer is done (IFileTransfer.isDone()returns true), and some exception will be made available- Specified by:
cancelin interfaceIFileTransfer- Overrides:
cancelin classAbstractRetrieveFileTransfer
-
hardClose
protected void hardClose()
- Overrides:
hardClosein classAbstractRetrieveFileTransfer
-
getFileRequestCredentials
protected org.apache.hc.client5.http.auth.Credentials getFileRequestCredentials() throws UnsupportedCallbackException, IOException- Returns:
- Credentials file request credentials
- Throws:
UnsupportedCallbackException- if some problemIOException- if some problem- Since:
- 5.0
-
setupProxies
protected void setupProxies()
- Overrides:
setupProxiesin classAbstractRetrieveFileTransfer
-
resetDoneAndException
protected void resetDoneAndException()
- Overrides:
resetDoneAndExceptionin classAbstractRetrieveFileTransfer
-
setupAuthentication
protected void setupAuthentication(String urlString) throws UnsupportedCallbackException, IOException
-
setRequestHeaderValues
protected void setRequestHeaderValues() throws InvalidFileRangeSpecificationException
-
getResponseCode
public int getResponseCode()
-
getID
public ID getID()
Description copied from interface:IIdentifiableReturn the ID for this 'identifiable' object. The returned ID should be unique within its namespace. May returnnull.- Specified by:
getIDin interfaceIIdentifiable- Overrides:
getIDin classAbstractRetrieveFileTransfer- Returns:
- the ID for this identifiable object. May return
null.
-
getResponseHeaderValues
protected void getResponseHeaderValues() throws IOException- Throws:
IOException
-
setInputStream
protected void setInputStream(InputStream ins)
- Overrides:
setInputStreamin classAbstractRetrieveFileTransfer
-
wrapTransferReadInputStream
protected InputStream wrapTransferReadInputStream(InputStream inputStream, org.eclipse.core.runtime.IProgressMonitor monitor)
- Overrides:
wrapTransferReadInputStreamin classAbstractRetrieveFileTransfer
-
getSocketReadTimeout
protected int getSocketReadTimeout()
- Overrides:
getSocketReadTimeoutin classAbstractRetrieveFileTransfer
-
getConnectTimeout
protected int getConnectTimeout()
- Returns:
- int connect timeout
- Since:
- 4.0
-
openStreams
protected void openStreams() throws IncomingFileTransferExceptionDescription copied from class:AbstractRetrieveFileTransferOpen incoming and outgoing streams associated with this file transfer. Subclasses must implement this method to open input and output streams. TheremoteFileContentsandlocalFileContentmust be non-nullafter successful completion of the implementation of this method.- Specified by:
openStreamsin classAbstractRetrieveFileTransfer- Throws:
IncomingFileTransferException- if some problem
-
setConnectContextForAuthentication
public void setConnectContextForAuthentication(IConnectContext connectContext)
Description copied from interface:IRetrieveFileTransferContainerAdapterSet connect context for authentication upon subsequentIRetrieveFileTransferContainerAdapter.sendRetrieveRequest(IFileID, IFileTransferListener, Map). This method should be called with a non-null connectContext in order to allow authentication to occur during call toIRetrieveFileTransferContainerAdapter.sendRetrieveRequest(IFileID, IFileTransferListener, Map).- Specified by:
setConnectContextForAuthenticationin interfaceIRetrieveFileTransferContainerAdapter- Overrides:
setConnectContextForAuthenticationin classAbstractRetrieveFileTransfer- Parameters:
connectContext- the connect context to use for authenticating during subsequent call toIRetrieveFileTransferContainerAdapter.sendRetrieveRequest(IFileID, IFileTransferListener, Map). Ifnull, then no authentication will be attempted.
-
getPortFromURL
protected static int getPortFromURL(String url)
-
urlUsesHttps
protected static boolean urlUsesHttps(String url)
-
supportsProtocol
public static boolean supportsProtocol(String protocolString)
-
isConnected
protected boolean isConnected()
-
doPause
protected boolean doPause()
Description copied from class:AbstractRetrieveFileTransferSubclass overridable version ofAbstractRetrieveFileTransfer.pause(). Subclasses must provide an implementation of this method to supportIFileTransferPausable.- Specified by:
doPausein classAbstractRetrieveFileTransfer- Returns:
- true if the pause is successful.
falseotherwise.
-
doResume
protected boolean doResume()
Description copied from class:AbstractRetrieveFileTransferSubclass overridable version ofAbstractRetrieveFileTransfer.resume(). Subclasses must provide an implementation of this method to supportIFileTransferPausable.- Specified by:
doResumein classAbstractRetrieveFileTransfer- Returns:
- true if the resume is successful.
falseotherwise.
-
setResumeRequestHeaderValues
protected void setResumeRequestHeaderValues() throws IOException, InvalidFileRangeSpecificationException
-
getResumeResponseHeaderValues
protected void getResumeResponseHeaderValues() throws IOException- Throws:
IOException
-
getAdapter
public <T> T getAdapter(Class<T> adapter)
- Specified by:
getAdapterin interfaceorg.eclipse.core.runtime.IAdaptable- Overrides:
getAdapterin classAbstractRetrieveFileTransfer
-
setupProxy
protected void setupProxy(Proxy proxy)
Description copied from class:AbstractRetrieveFileTransferSetup ECF proxy. Subclasses must override this method to do appropriate proxy setup. This method will be called from withinAbstractRetrieveFileTransfer.sendRetrieveRequest(IFileID, IFileTransferListener, Map)andAbstractRetrieveFileTransfer.sendRetrieveRequest(IFileID, IFileRangeSpecification, IFileTransferListener, Map), prior to the actual call toAbstractRetrieveFileTransfer.openStreams().- Specified by:
setupProxyin classAbstractRetrieveFileTransfer- Parameters:
proxy- the proxy to be setup. Will not benull.
-
clearProxy
protected void clearProxy()
This method will clear out the proxy information (so that if this is reused for a request without a proxy, it will work correctly).- Since:
- 5.0
-
fireConnectStartEvent
protected void fireConnectStartEvent()
-
createConnectJobName
protected String createConnectJobName()
-
prepareConnectJob
protected FileTransferJob prepareConnectJob(FileTransferJob cjob)
-
connectUsingJob
protected void connectUsingJob(FileTransferJob cjob)
-
fireReceiveResumedEvent
protected void fireReceiveResumedEvent()
- Overrides:
fireReceiveResumedEventin classAbstractRetrieveFileTransfer
-
fireTransferReceiveDataEvent
protected void fireTransferReceiveDataEvent()
- Overrides:
fireTransferReceiveDataEventin classAbstractRetrieveFileTransfer
-
fireTransferReceiveDoneEvent
protected void fireTransferReceiveDoneEvent()
- Overrides:
fireTransferReceiveDoneEventin classAbstractRetrieveFileTransfer
-
fireTransferReceivePausedEvent
protected void fireTransferReceivePausedEvent()
- Overrides:
fireTransferReceivePausedEventin classAbstractRetrieveFileTransfer
-
-