Lazy http connection creation
This commit is contained in:
1 parent
088fc5e443
commit
f6c3cb9bdb
1 file changed
+9
-7
@@ -36,13 +36,6 @@ class Request
|
||||
this.url = url;
|
||||
this.bodyParams = new HashMap<String, String>();
|
||||
this.headers = new HashMap<String, String>();
|
||||
try
|
||||
{
|
||||
connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
} catch (IOException ioe)
|
||||
{
|
||||
throw new OAuthException("Could not open connection to: " + url, ioe);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,6 +49,7 @@ class Request
|
||||
{
|
||||
try
|
||||
{
|
||||
createConnection();
|
||||
return doSend();
|
||||
} catch (IOException ioe)
|
||||
{
|
||||
@@ -63,6 +57,14 @@ class Request
|
||||
}
|
||||
}
|
||||
|
||||
private void createConnection() throws IOException
|
||||
{
|
||||
if (connection == null)
|
||||
{
|
||||
connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
}
|
||||
}
|
||||
|
||||
Response doSend() throws IOException
|
||||
{
|
||||
connection.setRequestMethod(this.verb.name());
|
||||
|
||||
Reference in new issue
Block a user