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 IFileID
fileid
protected static String
HTTP
protected static int
HTTP_PORT
protected static String
HTTPS
protected static int
HTTPS_PORT
protected int
httpVersion
protected static int
MAX_RETRY
protected JREProxyHelper
proxyHelper
protected 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 void
cancel()
Cancel this file transfer.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).protected void
connectUsingJob(FileTransferJob cjob)
protected String
createConnectJobName()
protected boolean
doPause()
Subclass overridable version ofAbstractRetrieveFileTransfer.pause()
.protected boolean
doResume()
Subclass overridable version ofAbstractRetrieveFileTransfer.resume()
.protected void
fireConnectStartEvent()
protected void
fireReceiveResumedEvent()
protected void
fireTransferReceiveDataEvent()
protected void
fireTransferReceiveDoneEvent()
protected void
fireTransferReceivePausedEvent()
<T> T
getAdapter(Class<T> adapter)
protected int
getConnectTimeout()
protected org.apache.hc.client5.http.auth.Credentials
getFileRequestCredentials()
protected static String
getHostFromURL(String url)
ID
getID()
Return the ID for this 'identifiable' object.protected static int
getPortFromURL(String url)
String
getRemoteFileName()
Obtains the name of the remote file if possible.int
getResponseCode()
protected void
getResponseHeaderValues()
protected void
getResumeResponseHeaderValues()
protected int
getSocketReadTimeout()
protected void
hardClose()
protected boolean
isConnected()
protected void
openStreams()
Open incoming and outgoing streams associated with this file transfer.protected FileTransferJob
prepareConnectJob(FileTransferJob cjob)
protected void
resetDoneAndException()
void
setConnectContextForAuthentication(IConnectContext connectContext)
Set connect context for authentication upon subsequentIRetrieveFileTransferContainerAdapter.sendRetrieveRequest(IFileID, IFileTransferListener, Map)
.protected void
setInputStream(InputStream ins)
protected void
setRequestHeaderValues()
protected void
setResumeRequestHeaderValues()
protected void
setupAuthentication(String urlString)
protected void
setupProxies()
protected void
setupProxy(Proxy proxy)
Setup ECF proxy.static boolean
supportsProtocol(String protocolString)
protected static boolean
urlUsesHttps(String url)
protected InputStream
wrapTransferReadInputStream(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:IIncomingFileTransfer
Obtains 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:
getRemoteFileName
in interfaceIIncomingFileTransfer
- Overrides:
getRemoteFileName
in classAbstractRetrieveFileTransfer
- Returns:
- The name of the remote file or
null
if no such name can be determined.
-
cancel
public void cancel()
Description copied from interface:IFileTransfer
Cancel 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 anIFileTransferEvent
being delivered to theIFileTransferListener
indicating that transfer is done (IFileTransfer.isDone()
returns true), and some exception will be made available- Specified by:
cancel
in interfaceIFileTransfer
- Overrides:
cancel
in classAbstractRetrieveFileTransfer
-
hardClose
protected void hardClose()
- Overrides:
hardClose
in 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:
setupProxies
in classAbstractRetrieveFileTransfer
-
resetDoneAndException
protected void resetDoneAndException()
- Overrides:
resetDoneAndException
in 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:IIdentifiable
Return the ID for this 'identifiable' object. The returned ID should be unique within its namespace. May returnnull
.- Specified by:
getID
in interfaceIIdentifiable
- Overrides:
getID
in 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:
setInputStream
in classAbstractRetrieveFileTransfer
-
wrapTransferReadInputStream
protected InputStream wrapTransferReadInputStream(InputStream inputStream, org.eclipse.core.runtime.IProgressMonitor monitor)
- Overrides:
wrapTransferReadInputStream
in classAbstractRetrieveFileTransfer
-
getSocketReadTimeout
protected int getSocketReadTimeout()
- Overrides:
getSocketReadTimeout
in classAbstractRetrieveFileTransfer
-
getConnectTimeout
protected int getConnectTimeout()
- Returns:
- int connect timeout
- Since:
- 4.0
-
openStreams
protected void openStreams() throws IncomingFileTransferException
Description copied from class:AbstractRetrieveFileTransfer
Open incoming and outgoing streams associated with this file transfer. Subclasses must implement this method to open input and output streams. TheremoteFileContents
andlocalFileContent
must be non-null
after successful completion of the implementation of this method.- Specified by:
openStreams
in classAbstractRetrieveFileTransfer
- Throws:
IncomingFileTransferException
- if some problem
-
setConnectContextForAuthentication
public void setConnectContextForAuthentication(IConnectContext connectContext)
Description copied from interface:IRetrieveFileTransferContainerAdapter
Set 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:
setConnectContextForAuthentication
in interfaceIRetrieveFileTransferContainerAdapter
- Overrides:
setConnectContextForAuthentication
in 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:AbstractRetrieveFileTransfer
Subclass overridable version ofAbstractRetrieveFileTransfer.pause()
. Subclasses must provide an implementation of this method to supportIFileTransferPausable
.- Specified by:
doPause
in classAbstractRetrieveFileTransfer
- Returns:
- true if the pause is successful.
false
otherwise.
-
doResume
protected boolean doResume()
Description copied from class:AbstractRetrieveFileTransfer
Subclass overridable version ofAbstractRetrieveFileTransfer.resume()
. Subclasses must provide an implementation of this method to supportIFileTransferPausable
.- Specified by:
doResume
in classAbstractRetrieveFileTransfer
- Returns:
- true if the resume is successful.
false
otherwise.
-
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:
getAdapter
in interfaceorg.eclipse.core.runtime.IAdaptable
- Overrides:
getAdapter
in classAbstractRetrieveFileTransfer
-
setupProxy
protected void setupProxy(Proxy proxy)
Description copied from class:AbstractRetrieveFileTransfer
Setup 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:
setupProxy
in 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:
fireReceiveResumedEvent
in classAbstractRetrieveFileTransfer
-
fireTransferReceiveDataEvent
protected void fireTransferReceiveDataEvent()
- Overrides:
fireTransferReceiveDataEvent
in classAbstractRetrieveFileTransfer
-
fireTransferReceiveDoneEvent
protected void fireTransferReceiveDoneEvent()
- Overrides:
fireTransferReceiveDoneEvent
in classAbstractRetrieveFileTransfer
-
fireTransferReceivePausedEvent
protected void fireTransferReceivePausedEvent()
- Overrides:
fireTransferReceivePausedEvent
in classAbstractRetrieveFileTransfer
-
-