|
||||||||||
| PREV CLASS NEXT CLASS | 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
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.
| Constructor Summary | |
|---|---|
FormRequest()
Creates a new FormRequest, which defaults its HTTP method to POST. |
|
FormRequest(FormRequest source)
Creates a new FormRequest based on the given FormRequest. |
|
FormRequest(String url)
Creates a new FormRequest for the specified URL. |
|
| Method Summary | |
|---|---|
protected InputStream |
getBody()
Protected method which returns the request body. |
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(byte[] body)
Sets the request body to be the specified array of bytes. |
void |
setBody(Document body)
Sets the request body to be the specified SimpleDocument. |
void |
setBody(InputStream body)
Sets the request body to be the specified InputStream. |
void |
setBody(String body)
Sets the request body to be the specified String. |
void |
setEncoding(Encoding enc)
Specifies the encoding to use with this FormRequest. |
void |
setFormParameter(Parameter param)
Adds the given parameter 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(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 |
setFormParameters(Parameter... params)
Sets the Form parameters to use with this FormRequest. |
String |
toString()
Returns a string representation of the object. |
| Methods inherited from class org.jdesktop.http.Request |
|---|
getFollowRedirects, getHeader, getHeaders, getMethod, getParameter, getParameters, getUrl, getUsername, removeHeader, removeHeader, setFollowRedirects, setHeader, setHeader, setHeader, setHeaders, setMethod, setParameter, setParameter, setParameters, setPassword, setUrl, setUsername |
| Methods inherited from class org.jdesktop.beans.AbstractBean |
|---|
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, clone, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public FormRequest()
public FormRequest(String url)
url - public FormRequest(FormRequest source)
source - cannot be null.| Method Detail |
|---|
public final Parameter getFormParameter(String name)
name - the name to look for. If null, null is returned.
public final void setFormParameter(String key,
String value)
key - must not be nullvalue -
public final void setFormParameter(String key,
File file)
key - must not be nullvalue - public void setFormParameter(Parameter param)
parem - the Parameter to add. This must not be null.public final Parameter[] getFormParameters()
public final void setFormParameters(Parameter... params)
params - the Parameters to set for this Request. May be null.public final Encoding getEncoding()
public void setEncoding(Encoding enc)
enc - public void setBody(String body)
Request
setBody in class Requestbody - the String to use for the body. May be null.public void setBody(byte[] body)
Request
setBody in class Requestbody - the byte array to use for the body. May be null.public void setBody(Document body)
RequestSimpleDocument.
setBody in class Requestbody - the DOM document to use for the body. May be null.public void setBody(InputStream body)
RequestInputStream.
setBody in class Requestbody - the InputStream to use for the body. May be null.
protected InputStream getBody()
throws Exception
Request
getBody in class RequestExceptionpublic String toString()
java.lang.ObjecttoString method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
toString in class Request
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||