Class DAO
java.lang.Object
org.deltava.dao.http.DAO
- Direct Known Subclasses:
FlightAwareDAO
,GetATIS
,GetExternalCharts
,GetFAACharts
,GetGoogleCAPTCHA
,GetGoogleGeocode
,GetNOAAWeather
,GetSimBrief
,GetURL
,GetVATSIMData
,GetWeatherTileLayers
,SendVAPIDPush
,SetVATSIMData
,TrackDAO
An abstract class to supports Data Access Objects that read from an HTTP URL. This differs from a stream-based Data Access Object only
that HTTP DAOs create their own stream to a URL. This is used in situations where request-specific data is encoded into the URL.
- Since:
- 2.4
- Version:
- 11.2
- Author:
- Luke
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the response compression type.protected String
getHeaderField
(String name) Returns an HTTP response header.protected InputStream
getIn()
Retrieves an input stream to the URL.protected OutputStream
getOut()
Retrieves an output stream to the URL.protected int
Returns the HTTP response code for this request.protected void
Helper method to open the connection.void
reset()
Resets the connection for subsequent reuse.protected void
setAuthentication
(String userID, String pwd) Sets an authentication request header.void
setCompression
(Compression... cmps) Updates the allowed compression for this request.void
setConnectTimeout
(int timeout) Sets the HTTP connect timeout.void
Sets the HTTP method to use if not GET.void
setReadTimeout
(int timeout) Sets the HTTP connect timeout.protected void
setRequestHeader
(String name, String value) Sets a request header.void
setReturnErrorStream
(boolean returnErrStream) Sets whether the error stream should be returned when connecting and an error occurs.
-
Constructor Details
-
DAO
DAO()
-
-
Method Details
-
getCompression
Returns the response compression type.- Returns:
- a Compression enumeration value
-
setMethod
Sets the HTTP method to use if not GET.- Parameters:
method
- the method name
-
setConnectTimeout
public void setConnectTimeout(int timeout) Sets the HTTP connect timeout.- Parameters:
timeout
- the timeout in milliseconds
-
setReadTimeout
public void setReadTimeout(int timeout) Sets the HTTP connect timeout.- Parameters:
timeout
- the timeout in milliseconds
-
setReturnErrorStream
public void setReturnErrorStream(boolean returnErrStream) Sets whether the error stream should be returned when connecting and an error occurs.- Parameters:
returnErrStream
- TRUE if the error stream should be returned, otherwise FALSE- See Also:
-
setCompression
Updates the allowed compression for this request.- Parameters:
cmps
- the Compression values
-
init
Helper method to open the connection.- Parameters:
url
- the URI to connect to- Throws:
IOException
- if an error occurs
-
setRequestHeader
-
setAuthentication
-
getResponseCode
Returns the HTTP response code for this request.- Returns:
- the response code
- Throws:
IOException
- if an error occuredHTTPDAOException
- if the read times out, with stack dump disabled
-
getHeaderField
-
getIn
Retrieves an input stream to the URL.- Returns:
- an InputStream to the data
- Throws:
HTTPDAOException
- if the read times out, with stack dump disabledIOException
- if an error occurs
-
getOut
Retrieves an output stream to the URL.- Returns:
- an OutputStream to the data
- Throws:
IOException
- if an error occurs
-
reset
public void reset()Resets the connection for subsequent reuse.
-