Package com.nimbusds.jose.util
Class DefaultResourceRetriever
- java.lang.Object
-
- com.nimbusds.jose.util.AbstractRestrictedResourceRetriever
-
- com.nimbusds.jose.util.DefaultResourceRetriever
-
- All Implemented Interfaces:
ResourceRetriever
,RestrictedResourceRetriever
@ThreadSafe public class DefaultResourceRetriever extends AbstractRestrictedResourceRetriever implements RestrictedResourceRetriever
The default retriever of resources specified by HTTP(S) or file based URL. Provides setting of a HTTP proxy, HTTP connect and read timeouts as well as a size limit of the retrieved entity. Caching header directives are not honoured.- Version:
- 2022-04-07
- Author:
- Vladimir Dzhuvinov, Artun Subasi, Imre Paladji
-
-
Constructor Summary
Constructors Constructor Description DefaultResourceRetriever()
Creates a new resource retriever.DefaultResourceRetriever(int connectTimeout, int readTimeout)
Creates a new resource retriever.DefaultResourceRetriever(int connectTimeout, int readTimeout, int sizeLimit)
Creates a new resource retriever.DefaultResourceRetriever(int connectTimeout, int readTimeout, int sizeLimit, boolean disconnectAfterUse)
Creates a new resource retriever.DefaultResourceRetriever(int connectTimeout, int readTimeout, int sizeLimit, boolean disconnectAfterUse, SSLSocketFactory sslSocketFactory)
Creates a new resource retriever.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
disconnectsAfterUse()
Returnstrue
if the disconnect method of the underlyingHttpURLConnection
will be called after trying to retrieve the resource.Proxy
getProxy()
Returns the HTTP proxy to use when opening the HttpURLConnection to retrieve the resource.protected HttpURLConnection
openConnection(URL url)
Deprecated.protected URLConnection
openFileConnection(URL url)
Opens a connection the specified file URL.protected HttpURLConnection
openHTTPConnection(URL url)
Opens a connection the specified HTTP(S) URL.Resource
retrieveResource(URL url)
Retrieves the resource from the specified HTTP(S) URL.void
setDisconnectsAfterUse(boolean disconnectAfterUse)
Controls calling of the disconnect method the underlyingHttpURLConnection
after trying to retrieve the resource.void
setProxy(Proxy proxy)
Sets the HTTP proxy to use when opening the HttpURLConnection to retrieve the resource.-
Methods inherited from class com.nimbusds.jose.util.AbstractRestrictedResourceRetriever
getConnectTimeout, getHeaders, getReadTimeout, getSizeLimit, setConnectTimeout, setHeaders, setReadTimeout, setSizeLimit
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.nimbusds.jose.util.RestrictedResourceRetriever
getConnectTimeout, getHeaders, getReadTimeout, getSizeLimit, setConnectTimeout, setHeaders, setReadTimeout, setSizeLimit
-
-
-
-
Constructor Detail
-
DefaultResourceRetriever
public DefaultResourceRetriever()
Creates a new resource retriever. The HTTP timeouts and entity size limit are set to zero (infinite).
-
DefaultResourceRetriever
public DefaultResourceRetriever(int connectTimeout, int readTimeout)
Creates a new resource retriever. The HTTP entity size limit is set to zero (infinite).- Parameters:
connectTimeout
- The HTTP connects timeout, in milliseconds, zero for infinite. Must not be negative.readTimeout
- The HTTP read timeout, in milliseconds, zero for infinite. Must not be negative.
-
DefaultResourceRetriever
public DefaultResourceRetriever(int connectTimeout, int readTimeout, int sizeLimit)
Creates a new resource retriever.- Parameters:
connectTimeout
- The HTTP connects timeout, in milliseconds, zero for infinite. Must not be negative.readTimeout
- The HTTP read timeout, in milliseconds, zero for infinite. Must not be negative.sizeLimit
- The HTTP entity size limit, in bytes, zero for infinite. Must not be negative.
-
DefaultResourceRetriever
public DefaultResourceRetriever(int connectTimeout, int readTimeout, int sizeLimit, boolean disconnectAfterUse)
Creates a new resource retriever.- Parameters:
connectTimeout
- The HTTP connects timeout, in milliseconds, zero for infinite. Must not be negative.readTimeout
- The HTTP read timeout, in milliseconds, zero for infinite. Must not be negative.sizeLimit
- The HTTP entity size limit, in bytes, zero for infinite. Must not be negative.disconnectAfterUse
- Iftrue
the disconnect method of the underlyingHttpURLConnection
will be called after trying to retrieve the resource. Whether the TCP socket is actually closed or reused depends on the underlying HTTP implementation and the setting of thekeep.alive
system property.
-
DefaultResourceRetriever
public DefaultResourceRetriever(int connectTimeout, int readTimeout, int sizeLimit, boolean disconnectAfterUse, SSLSocketFactory sslSocketFactory)
Creates a new resource retriever.- Parameters:
connectTimeout
- The HTTP connects timeout, in milliseconds, zero for infinite. Must not be negative.readTimeout
- The HTTP read timeout, in milliseconds, zero for infinite. Must not be negative.sizeLimit
- The HTTP entity size limit, in bytes, zero for infinite. Must not be negative.disconnectAfterUse
- Iftrue
the disconnect method of the underlyingHttpURLConnection
will be called after trying to retrieve the resource. Whether the TCP socket is actually closed or reused depends on the underlying HTTP implementation and the setting of thekeep.alive
system property.sslSocketFactory
- An SSLSocketFactory for establishing the TLS connections,null
to use the default one.
-
-
Method Detail
-
disconnectsAfterUse
public boolean disconnectsAfterUse()
Returnstrue
if the disconnect method of the underlyingHttpURLConnection
will be called after trying to retrieve the resource. Whether the TCP socket is actually closed or reused depends on the underlying HTTP implementation and the setting of thekeep.alive
system property.- Returns:
- If
true
the disconnect method of the underlyingHttpURLConnection
will be called after trying to retrieve the resource.
-
setDisconnectsAfterUse
public void setDisconnectsAfterUse(boolean disconnectAfterUse)
Controls calling of the disconnect method the underlyingHttpURLConnection
after trying to retrieve the resource. Whether the TCP socket is actually closed or reused depends on the underlying HTTP implementation and the setting of thekeep.alive
system property. Iftrue
the disconnect method of the underlyingHttpURLConnection
will be called after trying to retrieve the resource.
-
getProxy
public Proxy getProxy()
Returns the HTTP proxy to use when opening the HttpURLConnection to retrieve the resource. Note that the JVM may have a system wide proxy configured via thehttps.proxyHost
Java system property.- Returns:
- The proxy to use or
null
if no proxy should be used.
-
setProxy
public void setProxy(Proxy proxy)
Sets the HTTP proxy to use when opening the HttpURLConnection to retrieve the resource. Note that the JVM may have a system wide proxy configured via thehttps.proxyHost
Java system property.- Parameters:
proxy
- The proxy to use ornull
if no proxy should be used.
-
retrieveResource
public Resource retrieveResource(URL url) throws IOException
Description copied from interface:ResourceRetriever
Retrieves the resource from the specified HTTP(S) URL.- Specified by:
retrieveResource
in interfaceResourceRetriever
- Parameters:
url
- The URL of the resource. Its scheme must be HTTP or HTTPS. Must not benull
.- Returns:
- The retrieved resource.
- Throws:
IOException
- If the HTTP connection to the specified URL failed or the resource couldn't be retrieved.
-
openConnection
@Deprecated protected HttpURLConnection openConnection(URL url) throws IOException
Deprecated.Opens a connection the specified HTTP(S) URL. Uses the configuredProxy
if available.- Parameters:
url
- The URL of the resource. Its scheme must be HTTP or HTTPS. Must not benull
.- Returns:
- The opened HTTP(S) connection
- Throws:
IOException
- If the HTTP(S) connection to the specified URL failed.- See Also:
openHTTPConnection(java.net.URL)
-
openHTTPConnection
protected HttpURLConnection openHTTPConnection(URL url) throws IOException
Opens a connection the specified HTTP(S) URL. Uses the configuredProxy
if available.- Parameters:
url
- The URL of the resource. Its scheme must be "http" or "https". Must not benull
.- Returns:
- The opened HTTP(S) connection
- Throws:
IOException
- If the HTTP(S) connection to the specified URL failed.
-
openFileConnection
protected URLConnection openFileConnection(URL url) throws IOException
Opens a connection the specified file URL.- Parameters:
url
- The URL of the resource. Its scheme must be "file". Must not benull
.- Returns:
- The opened file connection.
- Throws:
IOException
- If the file connection to the specified URL failed.
-
-