Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.service.httputil
Class HttpUtils

java.lang.Object
  extended by net.java.sip.communicator.service.httputil.HttpUtils

public class HttpUtils
extends Object

Common http utils querying http locations, handling redirects, self-signed certificates, host verify on certificates, password protection and storing and reusing credentials for password protected sites.

Author:
Damian Minkov

Nested Class Summary
static class HttpUtils.HTTPResponseResult
          Utility class wraps the http requests result and some utility methods for retrieving info and content for the result.
 
Constructor Summary
HttpUtils()
           
 
Method Summary
static HttpUtils.HTTPResponseResult openURLConnection(String address)
          Opens a connection to the address.
static HttpUtils.HTTPResponseResult openURLConnection(String address, String[] headerParamNames, String[] headerParamValues)
          Opens a connection to the address.
static HttpUtils.HTTPResponseResult openURLConnection(String address, String usernamePropertyName, String passwordPropertyName, String[] headerParamNames, String[] headerParamValues)
          Opens a connection to the address.
static HttpUtils.HTTPResponseResult postFile(String address, String fileParamName, File file)
          Posts a file to the address.
static HttpUtils.HTTPResponseResult postFile(String address, String fileParamName, File file, String usernamePropertyName, String passwordPropertyName)
          Posts a file to the address.
static HttpUtils.HTTPResponseResult postForm(String address, String usernamePropertyName, String passwordPropertyName, String[] formParamNames, String[] formParamValues, int usernameParamIx, int passwordParamIx)
          Posting form to address.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpUtils

public HttpUtils()
Method Detail

openURLConnection

public static HttpUtils.HTTPResponseResult openURLConnection(String address)
Opens a connection to the address.

Parameters:
address - the address to contact.
Returns:
the result if any or null if connection was not possible or canceled by user.

openURLConnection

public static HttpUtils.HTTPResponseResult openURLConnection(String address,
                                                             String[] headerParamNames,
                                                             String[] headerParamValues)
Opens a connection to the address.

Parameters:
address - the address to contact.
headerParamNames - additional header name to include
headerParamValues - corresponding header value to include
Returns:
the result if any or null if connection was not possible or canceled by user.

openURLConnection

public static HttpUtils.HTTPResponseResult openURLConnection(String address,
                                                             String usernamePropertyName,
                                                             String passwordPropertyName,
                                                             String[] headerParamNames,
                                                             String[] headerParamValues)
Opens a connection to the address.

Parameters:
address - the address to contact.
usernamePropertyName - the property to use to retrieve/store username value if protected site is hit, for username ConfigurationService service is used.
passwordPropertyName - the property to use to retrieve/store password value if protected site is hit, for password CredentialsStorageService service is used.
headerParamNames - additional header name to include
headerParamValues - corresponding header value to include
Returns:
the result if any or null if connection was not possible or canceled by user.

postFile

public static HttpUtils.HTTPResponseResult postFile(String address,
                                                    String fileParamName,
                                                    File file)
Posts a file to the address.

Parameters:
address - the address to post the form to.
fileParamName - the name of the param for the file.
file - the file we will send.
Returns:
the result or null if send was not possible or credentials ask if any was canceled.

postFile

public static HttpUtils.HTTPResponseResult postFile(String address,
                                                    String fileParamName,
                                                    File file,
                                                    String usernamePropertyName,
                                                    String passwordPropertyName)
Posts a file to the address.

Parameters:
address - the address to post the form to.
fileParamName - the name of the param for the file.
file - the file we will send.
usernamePropertyName - the property to use to retrieve/store username value if protected site is hit, for username ConfigurationService service is used.
passwordPropertyName - the property to use to retrieve/store password value if protected site is hit, for password CredentialsStorageService service is used.
Returns:
the result or null if send was not possible or credentials ask if any was canceled.

postForm

public static HttpUtils.HTTPResponseResult postForm(String address,
                                                    String usernamePropertyName,
                                                    String passwordPropertyName,
                                                    String[] formParamNames,
                                                    String[] formParamValues,
                                                    int usernameParamIx,
                                                    int passwordParamIx)
Posting form to address. For submission we use POST method which is "application/x-www-form-urlencoded" encoded.

Parameters:
address - HTTP address.
usernamePropertyName - the property to use to retrieve/store username value if protected site is hit, for username ConfigurationService service is used.
passwordPropertyName - the property to use to retrieve/store password value if protected site is hit, for password CredentialsStorageService service is used.
formParamNames - the parameter names to include in post.
formParamValues - the corresponding parameter values to use.
usernameParamIx - the index of the username parameter in the formParamNames and formParamValues if any, otherwise -1.
passwordParamIx - the index of the password parameter in the formParamNames and formParamValues if any, otherwise -1.
Returns:
the result or null if send was not possible or credentials ask if any was canceled.

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.