abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1235857 - /abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/Session.java
Date Wed, 25 Jan 2012 18:17:04 GMT
Author: jmsnell
Date: Wed Jan 25 18:17:03 2012
New Revision: 1235857

URL: http://svn.apache.org/viewvc?rev=1235857&view=rev
Log:
Form Login modifications based on experience building real apps.. always a good thing

Modified:
    abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/Session.java

Modified: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/Session.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/Session.java?rev=1235857&r1=1235856&r2=1235857&view=diff
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/Session.java (original)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/Session.java Wed
Jan 25 18:17:03 2012
@@ -20,6 +20,7 @@ package org.apache.abdera2.protocol.clie
 import java.io.InputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.Map;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
@@ -48,6 +49,7 @@ import org.apache.http.protocol.HttpCont
 import org.apache.http.util.EntityUtils;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.ListeningExecutorService;
 import com.google.common.util.concurrent.MoreExecutors;
@@ -538,14 +540,37 @@ public class Session {
     }
     
     public boolean doFormLogin(String uri, String userfield, String userid, String passfield,
String password) {
+      return doFormLogin(uri, userfield, userid, passfield, password, (ImmutableMap<String,String>)null);
+    }
+ 
+    public boolean doFormLogin(
+        String uri, 
+        String userfield, 
+        String userid, 
+        String passfield, 
+        String password,
+        ImmutableMap.Builder<String,String> additional) {
+      return doFormLogin(uri,userfield,userid,passfield,password,additional.build());
+    }
+    
+    public boolean doFormLogin(
+      String uri, 
+      String userfield, 
+      String userid, 
+      String passfield, 
+      String password,
+      ImmutableMap<String,String> additional) {
       try {
         HttpPost httpost = new HttpPost(uri);
+        ImmutableList.Builder<BasicNameValuePair> pairs = 
+          ImmutableList.<BasicNameValuePair>builder()
+           .add(new BasicNameValuePair(userfield,userid))
+           .add(new BasicNameValuePair(passfield,password));
+        for (Map.Entry<String, String> entry : additional.entrySet())
+          pairs.add(new BasicNameValuePair(entry.getKey(),entry.getValue()));
         httpost.setEntity(
           new UrlEncodedFormEntity(
-            ImmutableList.of(
-              new BasicNameValuePair(userfield,userid),
-              new BasicNameValuePair(passfield,password)
-            ),
+            pairs.build(),
             HTTP.UTF_8));
         HttpResponse response = getClient().execute(httpost,localContext);
         HttpEntity entity = response.getEntity();



Mime
View raw message