Skip to content

Commit f6c3cb9

Browse files
Lazy http connection creation
1 parent 088fc5e commit f6c3cb9

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/main/java/org/scribe/model/Request.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ public Request(Verb verb, String url)
3636
this.url = url;
3737
this.bodyParams = new HashMap<String, String>();
3838
this.headers = new HashMap<String, String>();
39-
try
40-
{
41-
connection = (HttpURLConnection) new URL(url).openConnection();
42-
} catch (IOException ioe)
43-
{
44-
throw new OAuthException("Could not open connection to: " + url, ioe);
45-
}
4639
}
4740

4841
/**
@@ -56,13 +49,22 @@ public Response send()
5649
{
5750
try
5851
{
52+
createConnection();
5953
return doSend();
6054
} catch (IOException ioe)
6155
{
6256
throw new OAuthException("Problems while creating connection", ioe);
6357
}
6458
}
6559

60+
private void createConnection() throws IOException
61+
{
62+
if (connection == null)
63+
{
64+
connection = (HttpURLConnection) new URL(url).openConnection();
65+
}
66+
}
67+
6668
Response doSend() throws IOException
6769
{
6870
connection.setRequestMethod(this.verb.name());

0 commit comments

Comments
 (0)