From f6c3cb9bdbc7c3b1ff2d7b643e7b91002420e0a2 Mon Sep 17 00:00:00 2001 From: Pablo Fernandez Date: Sun, 9 Jan 2011 15:34:19 -0300 Subject: [PATCH] Lazy http connection creation --- src/main/java/org/scribe/model/Request.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/scribe/model/Request.java b/src/main/java/org/scribe/model/Request.java index ddaee41..3392e4d 100644 --- a/src/main/java/org/scribe/model/Request.java +++ b/src/main/java/org/scribe/model/Request.java @@ -36,13 +36,6 @@ class Request this.url = url; this.bodyParams = new HashMap(); this.headers = new HashMap(); - 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());