Lazy http connection creation

This commit is contained in:
Pablo Fernandez committed 2011-01-09 15:34:19 -03:00
1 parent 088fc5e443
commit f6c3cb9bdb
1 file changed
+9 -7
+9 -7
View File
@@ -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());