aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDamian Minkov <damencho@jitsi.org>2014-06-30 16:44:04 +0300
committerDamian Minkov <damencho@jitsi.org>2014-06-30 16:45:52 +0300
commit0dff89bf2dd1347d7ef71640cb79c5287be0d0a9 (patch)
tree36271aab5a57c0f2501dac620199fef91f43c7ae /src
parenta8453f66f1d40fb6683e022a8263246aee0b62af (diff)
downloadjitsi-0dff89bf2dd1347d7ef71640cb79c5287be0d0a9.zip
jitsi-0dff89bf2dd1347d7ef71640cb79c5287be0d0a9.tar.gz
jitsi-0dff89bf2dd1347d7ef71640cb79c5287be0d0a9.tar.bz2
Adds method to post http requests using httputil and specifying custom http headers.
Diffstat (limited to 'src')
-rw-r--r--src/net/java/sip/communicator/service/httputil/HttpUtils.java86
1 files changed, 83 insertions, 3 deletions
diff --git a/src/net/java/sip/communicator/service/httputil/HttpUtils.java b/src/net/java/sip/communicator/service/httputil/HttpUtils.java
index be1151b..ae1cc85 100644
--- a/src/net/java/sip/communicator/service/httputil/HttpUtils.java
+++ b/src/net/java/sip/communicator/service/httputil/HttpUtils.java
@@ -381,13 +381,77 @@ public class HttpUtils
* credentials ask if any was canceled.
*/
public static HTTPResponseResult postForm(String address,
+ String usernamePropertyName,
+ String passwordPropertyName,
+ ArrayList<String> formParamNames,
+ ArrayList<String> formParamValues,
+ int usernameParamIx,
+ int passwordParamIx,
+ RedirectHandler redirectHandler)
+ throws Throwable
+ {
+ return postForm(
+ address,
+ usernamePropertyName, passwordPropertyName,
+ formParamNames, formParamValues,
+ usernameParamIx, passwordParamIx,
+ redirectHandler,
+ null, null);
+ }
+
+ /**
+ * Posting form to <tt>address</tt>. For submission we use POST method
+ * which is "application/x-www-form-urlencoded" encoded.
+ * @param address HTTP address.
+ * @param headerParamNames additional header name to include
+ * @param headerParamValues corresponding header value to include
+ * @return the result or null if send was not possible or
+ * credentials ask if any was canceled.
+ */
+ public static HTTPResponseResult postForm(String address,
+ List<String> headerParamNames,
+ List<String> headerParamValues)
+ throws Throwable
+ {
+ return postForm(address, null, null, null, null, -1, -1, null,
+ headerParamNames, headerParamValues);
+ }
+
+ /**
+ * Posting form to <tt>address</tt>. For submission we use POST method
+ * which is "application/x-www-form-urlencoded" encoded.
+ * @param address HTTP address.
+ * @param usernamePropertyName the property to use to retrieve/store
+ * username value if protected site is hit, for username
+ * ConfigurationService service is used.
+ * @param passwordPropertyName the property to use to retrieve/store
+ * password value if protected site is hit, for password
+ * CredentialsStorageService service is used.
+ * @param formParamNames the parameter names to include in post.
+ * @param formParamValues the corresponding parameter values to use.
+ * @param usernameParamIx the index of the username parameter in the
+ * <tt>formParamNames</tt> and <tt>formParamValues</tt>
+ * if any, otherwise -1.
+ * @param passwordParamIx the index of the password parameter in the
+ * <tt>formParamNames</tt> and <tt>formParamValues</tt>
+ * if any, otherwise -1.
+ * @param redirectHandler handles redirection, should we redirect and
+ * the actual redirect.
+ * @param headerParamNames additional header name to include
+ * @param headerParamValues corresponding header value to include
+ * @return the result or null if send was not possible or
+ * credentials ask if any was canceled.
+ */
+ public static HTTPResponseResult postForm(String address,
String usernamePropertyName,
String passwordPropertyName,
ArrayList<String> formParamNames,
ArrayList<String> formParamValues,
int usernameParamIx,
int passwordParamIx,
- RedirectHandler redirectHandler)
+ RedirectHandler redirectHandler,
+ List<String> headerParamNames,
+ List<String> headerParamValues)
throws Throwable
{
DefaultHttpClient httpClient;
@@ -416,7 +480,9 @@ public class HttpUtils
formParamValues,
usernameParamIx,
passwordParamIx,
- redirectHandler);
+ redirectHandler,
+ headerParamNames,
+ headerParamValues);
authEx = null;
}
@@ -464,6 +530,8 @@ public class HttpUtils
* @param passwordParamIx the index of the password parameter in the
* <tt>formParamNames</tt> and <tt>formParamValues</tt>
* if any, otherwise -1.
+ * @param headerParamNames additional header name to include
+ * @param headerParamValues corresponding header value to include
* @return the result or null if send was not possible or
* credentials ask if any was canceled.
*/
@@ -475,7 +543,9 @@ public class HttpUtils
ArrayList<String> formParamValues,
int usernameParamIx,
int passwordParamIx,
- RedirectHandler redirectHandler)
+ RedirectHandler redirectHandler,
+ List<String> headerParamNames,
+ List<String> headerParamValues)
throws Throwable
{
// if we have username and password in the parameters, lets
@@ -554,6 +624,16 @@ public class HttpUtils
// insert post values encoded.
postMethod.setEntity(entity);
+ if(headerParamNames != null)
+ {
+ for(int i = 0; i < headerParamNames.size(); i++)
+ {
+ postMethod.addHeader(
+ headerParamNames.get(i),
+ headerParamValues.get(i));
+ }
+ }
+
// execute post
return executeMethod(
httpClient, postMethod, redirectHandler, parameters);