Package org.faceless.publisher.type
Class URL2ConnectionBase
java.lang.Object
org.faceless.publisher.type.URL2ConnectionBase
- All Implemented Interfaces:
URL2Connection
A base class implementing an instance of
URL2Connection
-
Constructor Summary
ConstructorsConstructorDescriptionURL2ConnectionBase
(int code, URL2 uri, InputStream in) Create a URL2Connection with no headers and which will return the specified InputStream whengetInputStream()
is calledURL2ConnectionBase
(URL2 uri, URLConnection con) Create a URL2Connection which will wrap the specifiedURLConnection
-
Method Summary
Modifier and TypeMethodDescriptionvoid
connect()
"Connect" to the URL.Return the CallbackHandler set byURL2Connection.setCallbackHandler(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 connectionReturn the InputStream for the response.If this instance wraps aURLConnection
, return that, otherwise return nullfinal Date
Return a request header as a Date (if set and a valid date), or null otherwise.final String
getRequestHeader
(String key) Return a previously-set Request headerReturn a modifiable map of the Request headers It's usually preferable to callURL2Connection.getRequestHeader(java.lang.String)
to retrieve a single header, as that handles case folding.final Date
Return a response header as a Date if set and a valid date, or null otherwise.final String
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
Set the InputStream to return fromgetInputStream()
, overriding the parameter passed into the constructorfinal void
setRequestDateHeader
(String key, Date value) Set a request header as a Date.void
setRequestHeader
(String key, String value) Set a request header.final void
setResponseDateHeader
(String key, Date value) Set a response header as a Date.void
setResponseHeader
(String key, String value) Set a response header.void
Set the URL, overriding the parameter passed into the constructorMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.faceless.publisher.type.URL2Connection
getIfModifiedSince, getLastModified, getMethod, getRequestInputStream
-
Constructor Details
-
URL2ConnectionBase
Create a URL2Connection with no headers and which will return the specified InputStream whengetInputStream()
is called- Parameters:
code
- the code to return fromgetCode()
, which should be between 1 and 999uri
- the URL - the origin of which must be set to the referrer URL that would be sent, with referrer-policy and include-credentialsin
- the InputStream to return fromgetInputStream()
- may be null (although that method should be overridden if it is)
-
URL2ConnectionBase
Create a URL2Connection which will wrap the specifiedURLConnection
- Parameters:
uri
- the URL - the origin of which must be set to the referrer URL that would be sent, with referrer-policy and include-credentialscon
- the URLConnection to wrap (required)
-
-
Method Details
-
connect
"Connect" to the URL. This populates the responseHeaders. It's called automatically when the responseHeaders or InputStream is requested- Specified by:
connect
in interfaceURL2Connection
- Throws:
IOException
-
isConnected
public boolean isConnected()Description copied from interface:URL2Connection
Return true if the connection has been made- Specified by:
isConnected
in interfaceURL2Connection
-
setCallbackHandler
Description copied from interface:URL2Connection
Set the CallbackHandler that should be used for any authorization callbacks required on this connection- Specified by:
setCallbackHandler
in interfaceURL2Connection
-
getCallbackHandler
Description copied from interface:URL2Connection
Return the CallbackHandler set byURL2Connection.setCallbackHandler(javax.security.auth.callback.CallbackHandler)
- Specified by:
getCallbackHandler
in interfaceURL2Connection
-
setURL
Set the URL, overriding the parameter passed into the constructor- Parameters:
uri
- the URL
-
setInputStream
Set the InputStream to return fromgetInputStream()
, overriding the parameter passed into the constructor- Parameters:
in
- the InputStream
-
getURL
Description copied from interface:URL2Connection
Get the URL. Note the origin's ReferrerPolicy is used- Specified by:
getURL
in interfaceURL2Connection
-
getInputStream
Description copied from interface:URL2Connection
Return the InputStream for the response. Will trigger a connection- Specified by:
getInputStream
in interfaceURL2Connection
- Throws:
IOException
-
getResponseHeaders
Description copied from interface:URL2Connection
Return a modifiable map of the Response headers. It's usually preferable to callURL2Connection.getResponseHeader(java.lang.String)
to retrieve a single header, as that handles case folding. Will trigger a connection.- Specified by:
getResponseHeaders
in interfaceURL2Connection
- Throws:
IOException
-
setResponseHeader
Set a response 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 connectedIOException
- See Also:
-
getRequestHeaders
Description copied from interface:URL2Connection
Return a modifiable map of the Request headers It's usually preferable to callURL2Connection.getRequestHeader(java.lang.String)
to retrieve a single header, as that handles case folding.- Specified by:
getRequestHeaders
in interfaceURL2Connection
-
setRequestHeader
Description copied from interface:URL2Connection
Set a request header. Replaces all other headers with this name.- Specified by:
setRequestHeader
in interfaceURL2Connection
- Parameters:
key
- the header name, which is case-insensitivevalue
- the value name, or null to remove the header.
-
getLegacyURLConnection
Description copied from interface:URL2Connection
If this instance wraps aURLConnection
, return that, otherwise return null- Specified by:
getLegacyURLConnection
in interfaceURL2Connection
- Throws:
IOException
-
getCode
Description copied from interface:URL2Connection
Return the response code, the logic for this will depend on the scheme but which ideally should match HTTP Will trigger a connection- Specified by:
getCode
in interfaceURL2Connection
- Throws:
IOException
-
getRequestHeader
Description copied from interface:URL2Connection
Return a previously-set Request header- Specified by:
getRequestHeader
in interfaceURL2Connection
-
getResponseHeader
Description copied from interface:URL2Connection
Return a response header if set, or null otherwise. If multiple headers, returns the first.- Specified by:
getResponseHeader
in interfaceURL2Connection
- Parameters:
key
- the header name, which is case-insensitive- Throws:
IOException
-
getResponseDateHeader
Description copied from interface:URL2Connection
Return a response header as a Date if set and a valid date, or null otherwise. If multiple headers, returns the first.- Specified by:
getResponseDateHeader
in interfaceURL2Connection
- Parameters:
key
- the header name, which is case-insensitive- Throws:
IOException
-
getRequestDateHeader
Description copied from interface:URL2Connection
Return a request header as a Date (if set and a valid date), or null otherwise. If multiple headers, returns the first.- Specified by:
getRequestDateHeader
in interfaceURL2Connection
- Parameters:
key
- the header name, which is case-insensitive
-
setRequestDateHeader
Description copied from interface:URL2Connection
Set a request header as a Date.- Specified by:
setRequestDateHeader
in interfaceURL2Connection
- Parameters:
key
- the header name, which is case-insensitivevalue
- the date value
-
setResponseDateHeader
Set a response header as a Date.- Parameters:
key
- the header name, which is case-insensitivevalue
- the date value- Throws:
IllegalStateException
- if we're already connectedIOException
- See Also:
-