Package org.faceless.publisher.type
Interface URL2Connection
- All Known Implementing Classes:
URL2ConnectionBase
,URL2ConnectionWrapper
public interface URL2Connection
An interface which is analogous to the awful
URLConnection
but designed for implementation and extension-
Method Summary
Modifier and TypeMethodDescriptionvoid
connect()
Open the network connectionReturn the CallbackHandler set bysetCallbackHandler(javax.security.auth.callback.CallbackHandler)
int
getCode()
Return the response code, the logic for this will depend on the scheme but which ideally should match HTTP Will trigger a connectiondefault long
Return the "If-Modified-Since" header as a long describing milliseconds since the UNIX epoch, or 0 if not setReturn the InputStream for the response.default long
Return the "Last-Modified" header as a long describing milliseconds since the UNIX epoch, or 0 if not setIf this instance wraps aURLConnection
, return that, otherwise return nulldefault String
Return the method - defaults to "GET"Return a request header as a Date (if set and a valid date), or null otherwise.getRequestHeader
(String key) Return a previously-set Request headerReturn a modifiable map of the Request headers It's usually preferable to callgetRequestHeader(java.lang.String)
to retrieve a single header, as that handles case folding.default InputStream
Return the InputStream for the request, which defaults to null.Return a response header as a Date if set and a valid date, or null otherwise.getResponseHeader
(String key) Return a response header if set, or null otherwise.Return a modifiable map of the Response headers.getURL()
Get the URL.boolean
Return true if the connection has been madevoid
setCallbackHandler
(CallbackHandler handler) Set the CallbackHandler that should be used for any authorization callbacks required on this connectionvoid
setRequestDateHeader
(String key, Date value) Set a request header as a Date.void
setRequestHeader
(String key, String value) Set a request header.
-
Method Details
-
isConnected
boolean isConnected()Return true if the connection has been made -
getMethod
Return the method - defaults to "GET" -
getRequestInputStream
Return the InputStream for the request, which defaults to null.- Throws:
IOException
-
getURL
URL2 getURL()Get the URL. Note the origin's ReferrerPolicy is used -
getInputStream
Return the InputStream for the response. Will trigger a connection- Throws:
IOException
-
getLegacyURLConnection
If this instance wraps aURLConnection
, return that, otherwise return null- Throws:
IOException
-
getCode
Return the response code, the logic for this will depend on the scheme but which ideally should match HTTP Will trigger a connection- Throws:
IOException
-
getResponseHeaders
Return a modifiable map of the Response headers. It's usually preferable to callgetResponseHeader(java.lang.String)
to retrieve a single header, as that handles case folding. Will trigger a connection.- Throws:
IOException
-
getRequestHeaders
Return a modifiable map of the Request headers It's usually preferable to callgetRequestHeader(java.lang.String)
to retrieve a single header, as that handles case folding. -
getRequestHeader
Return a previously-set Request header -
setRequestHeader
Set a request header. Replaces all other headers with this name.- Parameters:
key
- the header name, which is case-insensitivevalue
- the value name, or null to remove the header.- Throws:
IllegalStateException
- if we're already connected
-
getResponseHeader
Return a response header if set, or null otherwise. If multiple headers, returns the first.- Parameters:
key
- the header name, which is case-insensitive- Throws:
IOException
-
getResponseDateHeader
Return a response header as a Date if set and a valid date, or null otherwise. If multiple headers, returns the first.- Parameters:
key
- the header name, which is case-insensitive- Throws:
IOException
-
getRequestDateHeader
Return a request header as a Date (if set and a valid date), or null otherwise. If multiple headers, returns the first.- Parameters:
key
- the header name, which is case-insensitive
-
setRequestDateHeader
Set a request header as a Date.- Parameters:
key
- the header name, which is case-insensitivevalue
- the date value- Throws:
IllegalStateException
- if we're already connected
-
setCallbackHandler
Set the CallbackHandler that should be used for any authorization callbacks required on this connection -
getCallbackHandler
CallbackHandler getCallbackHandler()Return the CallbackHandler set bysetCallbackHandler(javax.security.auth.callback.CallbackHandler)
-
getLastModified
Return the "Last-Modified" header as a long describing milliseconds since the UNIX epoch, or 0 if not set- Throws:
IOException
-
getIfModifiedSince
Return the "If-Modified-Since" header as a long describing milliseconds since the UNIX epoch, or 0 if not set- Throws:
IOException
-
connect
Open the network connection- Throws:
IOException
-