|
Groovy Documentation | |||||||
| FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectorg.jdesktop.beans.AbstractBean
org.jdesktop.http.Request
org.jdesktop.html.form.FormRequest
public class FormRequest extends Request
A FormRequest is a Request specifically designed for emulating HTML forms. In particular, a FormRequest does not specifically allow the setting of the body of the Request. Instead, one of several "Form Parameters" are set, which then become the body. Since FormRequest extends request, you can also specify "normal" or "GET" parameters using the setParameter() methods.
When you create a new FormRequest, by default the HTTP method is POST instead of GET (which is the default for Request). In all other ways FormRequest has the same defaults as its parent class.
FormRequest allows you to specify the encoding used for the form. Valid entries are of type Encoding. The default value is Encoding.UrlEncoding. When uploading files to the server, you would typically want to use Encoding.MultipartFormData.
Here is a typical usage example:
FormRequest request = new FormRequest("http://www.example.com/doFileUpload");
request.setEncoding(Encoding.MultipartFormData);
request.setFormParameter("username", "richard");
request.setFormParameter("compression", "none");
request.setFormParameter("file", new File("/usr/local/desktop/photo.png"));
Session s = new Session();
Response response = s.execute(request);
In this example our fictitious doFileUpload resource is expecting a multipart/form-data upload with username, compression, and file parameters in the body of the form. Notice the use of the setFormParameter that takes a File. Invoking setFormParameter in this way constructs a FileParameter and sets it on the FormRequest. See FileParameter for more details.
Since the body of a FormRequest is comprised exclusively of the content of the Form parameters, the various setBody() methods declared in Request are overridden in this subclass to be no-ops. It is therefore only possible to specify the body by using Form parameters.
| Nested Class Summary | |
|---|---|
private static class |
FormRequest.MultipartInputStream
This InputStream allows me to construct and return an InputStream which will be efficient in terms of memory usage with large numbers of files, or with large files. |
| Field Summary | |
|---|---|
private String |
boundary
|
private Encoding |
encoding
|
private List |
formParams
|
| Fields inherited from class Request | |
|---|---|
| followRedirects, headers, method, params, password, requestBody, stringBody, url, username |
| Constructor Summary | |
FormRequest()
Creates a new FormRequest, which defaults its HTTP method to POST. |
|
FormRequest(String url)
Creates a new FormRequest for the specified URL. |
|
FormRequest(FormRequest source)
Creates a new FormRequest based on the given FormRequest. |
|
| Method Summary | |
|---|---|
protected InputStream
|
getBody()
|
Encoding
|
getEncoding()
Gets the encoding to use with this FormRequest. |
Parameter
|
getFormParameter(String name)
Returns the Form Parameter with the given name, or null if there is no such Form Parameter. |
Parameter[]
|
getFormParameters()
Gets an array of all the Form Parameters for this FormRequest. |
void
|
setBody(String body)
|
void
|
setBody(byte[] body)
|
void
|
setBody(org.w3c.dom.Document body)
|
void
|
setBody(InputStream body)
|
void
|
setEncoding(Encoding enc)
Specifies the encoding to use with this FormRequest. |
void
|
setFormParameter(String key, String value)
Creates a Form Parameter using the given key and value and then adds it to the set of form parameters. |
void
|
setFormParameter(String key, File file)
Creates a Form Parameter using the given key and File and then adds it to the set of form parameters. |
void
|
setFormParameter(Parameter param)
Adds the given parameter to the set of Form parameters. |
void
|
setFormParameters(Parameter... params)
Sets the Form parameters to use with this FormRequest. |
String
|
toString()
|
| Methods inherited from class Request | |
|---|---|
| base64Decode, base64Encode, getBody, getFollowRedirects, getHeader, getHeaders, getMethod, getParameter, getParameters, getPassword, getUrl, getUsername, removeHeader, removeHeader, resetAuthenticationHeader, setBody, setBody, setBody, setBody, setFollowRedirects, setHeader, setHeader, setHeader, setHeaders, setMethod, setParameter, setParameter, setParameters, setPassword, setUrl, setUrlImpl, setUsername, toString |
| Methods inherited from class org.jdesktop.beans.AbstractBean | |
|---|---|
| org.jdesktop.beans.AbstractBean#clone(), org.jdesktop.beans.AbstractBean#addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#addPropertyChangeListener(java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#removePropertyChangeListener(java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#getPropertyChangeListeners(java.lang.String), org.jdesktop.beans.AbstractBean#getPropertyChangeListeners(), org.jdesktop.beans.AbstractBean#addVetoableChangeListener(java.lang.String, java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#addVetoableChangeListener(java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#removeVetoableChangeListener(java.lang.String, java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#removeVetoableChangeListener(java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#getVetoableChangeListeners(java.lang.String), org.jdesktop.beans.AbstractBean#getVetoableChangeListeners(), org.jdesktop.beans.AbstractBean#wait(), org.jdesktop.beans.AbstractBean#wait(long), org.jdesktop.beans.AbstractBean#wait(long, int), org.jdesktop.beans.AbstractBean#equals(java.lang.Object), org.jdesktop.beans.AbstractBean#toString(), org.jdesktop.beans.AbstractBean#hashCode(), org.jdesktop.beans.AbstractBean#getClass(), org.jdesktop.beans.AbstractBean#notify(), org.jdesktop.beans.AbstractBean#notifyAll() |
| Field Detail |
|---|
private String boundary
private Encoding encoding
private List formParams
| Constructor Detail |
|---|
public FormRequest()
public FormRequest(String url)
public FormRequest(FormRequest source)
source - cannot be null.
| Method Detail |
|---|
protected InputStream getBody()
public final Encoding getEncoding()
public final Parameter getFormParameter(String name)
name - the name to look for. If null, null is returned.
public final Parameter[] getFormParameters()
// the public void setBody(String body)
final public void setBody(byte[] body)
for (i public void setBody(org.w3c.dom.Document body)
pa public void setBody(InputStream body)
public void setEncoding(Encoding enc)
public final void setFormParameter(String key, String value)
key - must not be null
public final void setFormParameter(String key, File file)
key - must not be null
public void setFormParameter(Parameter param)
parem - the Parameter to add. This must not be null.
public final void setFormParameters(Parameter... params)
params - the Parameters to set for this Request. May be null.
public String toString()
Groovy Documentation