com.meterware.httpunit

Class WebRequest

public abstract class WebRequest extends Object

A request sent to a web server.
Constructor Summary
protected WebRequest(String urlString)
Constructs a web request using an absolute URL string.
protected WebRequest(URL urlBase, String urlString)
Constructs a web request using a base URL and a relative URL string.
protected WebRequest(WebRequest baseRequest, String urlString, String target)
Constructs a web request using a base request and a relative URL string.
protected WebRequest(URL urlBase, String urlString, String target)
Constructs a web request using a base URL, a relative URL string, and a target.
protected WebRequest(URL urlBase, String urlString, FrameSelector frame, String target)
Constructs a web request using a base URL, a relative URL string, and a target.
protected WebRequest(WebForm sourceForm, ParameterHolder parameterHolder, SubmitButton button, int x, int y)
Constructs a web request from a form.
protected WebRequest(WebRequestSource requestSource, ParameterHolder parameterHolder)
Method Summary
protected voidcompleteRequest(URLConnection connection)
Performs any additional processing necessary to complete the request.
protected StringgetCharacterSet()
Returns the character set required for this request.
protected StringgetContentType()
Returns the content type of this request.
DictionarygetHeaders()
Returns a copy of the headers to be sent with this request.
abstract StringgetMethod()
Returns the HTTP method defined for this request.
StringgetParameter(String name)
Returns the value of a parameter in this web request.
protected ParameterHoldergetParameterHolder()
String[]getParameterValues(String name)
Returns the multiple default values of the named parameter.
StringgetQueryString()
Returns the query string defined for this request.
String[]getRequestParameterNames()
Returns an array of all parameter names defined as part of this web request.
StringgetTarget()
Returns the target for this web request.
URLgetURL()
Returns the final URL associated with this web request.
protected URLgetURLBase()
protected StringgetURLString()
booleanisFileParameter(String name)
Returns true if the specified parameter is a file field.
protected booleanisMimeEncoded()
Returns true if this request is to be MIME-encoded.
protected booleanmaySelectFile(String parameterName)
Returns true if selectFile may be called with this parameter.
voidremoveParameter(String name)
Removes a parameter from this web request.
voidselectFile(String parameterName, File file)
Sets the file for a parameter upload in a web request.
voidselectFile(String parameterName, File file, String contentType)
Sets the file for a parameter upload in a web request.
voidselectFile(String parameterName, String fileName, InputStream inputStream, String contentType)
Sets the file for a parameter upload in a web request.
voidsetHeaderField(String headerName, String headerValue)
Sets the value of a header to be sent with this request.
voidsetImageButtonClickPosition(int x, int y)
Specifies the click position for the submit button.
protected voidsetMimeEncoded(boolean mimeEncoded)
Selects whether MIME-encoding will be used for this request.
voidsetParameter(String name, String value)
Sets the value of a parameter in a web request.
voidsetParameter(String name, String[] values)
Sets the multiple values of a parameter in a web request.
voidsetParameter(String parameterName, UploadFileSpec[] files)
Sets the multiple values of a file upload parameter in a web request.
StringtoString()
protected voidwriteMessageBody(OutputStream stream)
Writes the contents of the message body to the specified stream.

Constructor Detail

WebRequest

protected WebRequest(String urlString)
Constructs a web request using an absolute URL string.

WebRequest

protected WebRequest(URL urlBase, String urlString)
Constructs a web request using a base URL and a relative URL string.

WebRequest

protected WebRequest(WebRequest baseRequest, String urlString, String target)
Constructs a web request using a base request and a relative URL string.

WebRequest

protected WebRequest(URL urlBase, String urlString, String target)
Constructs a web request using a base URL, a relative URL string, and a target.

WebRequest

protected WebRequest(URL urlBase, String urlString, FrameSelector frame, String target)
Constructs a web request using a base URL, a relative URL string, and a target.

WebRequest

protected WebRequest(WebForm sourceForm, ParameterHolder parameterHolder, SubmitButton button, int x, int y)
Constructs a web request from a form.

WebRequest

protected WebRequest(WebRequestSource requestSource, ParameterHolder parameterHolder)

Method Detail

completeRequest

protected void completeRequest(URLConnection connection)
Performs any additional processing necessary to complete the request.

getCharacterSet

protected final String getCharacterSet()
Returns the character set required for this request.

getContentType

protected String getContentType()
Returns the content type of this request. If null, no content is specified.

getHeaders

public Dictionary getHeaders()
Returns a copy of the headers to be sent with this request.

getMethod

public abstract String getMethod()
Returns the HTTP method defined for this request.

getParameter

public String getParameter(String name)
Returns the value of a parameter in this web request.

Returns: the value of the named parameter, or empty string if it is not set.

getParameterHolder

protected final ParameterHolder getParameterHolder()

getParameterValues

public String[] getParameterValues(String name)
Returns the multiple default values of the named parameter.

getQueryString

public String getQueryString()
Returns the query string defined for this request. The query string is sent to the HTTP server as part of the request header. This default implementation returns an empty string.

getRequestParameterNames

public String[] getRequestParameterNames()
Returns an array of all parameter names defined as part of this web request.

Since: 1.3.1

getTarget

public String getTarget()
Returns the target for this web request.

getURL

public URL getURL()
Returns the final URL associated with this web request.

getURLBase

protected final URL getURLBase()

getURLString

protected String getURLString()

isFileParameter

public boolean isFileParameter(String name)
Returns true if the specified parameter is a file field.

isMimeEncoded

protected boolean isMimeEncoded()
Returns true if this request is to be MIME-encoded.

maySelectFile

protected boolean maySelectFile(String parameterName)
Returns true if selectFile may be called with this parameter.

removeParameter

public void removeParameter(String name)
Removes a parameter from this web request.

selectFile

public void selectFile(String parameterName, File file)
Sets the file for a parameter upload in a web request.

selectFile

public void selectFile(String parameterName, File file, String contentType)
Sets the file for a parameter upload in a web request.

selectFile

public void selectFile(String parameterName, String fileName, InputStream inputStream, String contentType)
Sets the file for a parameter upload in a web request.

setHeaderField

public void setHeaderField(String headerName, String headerValue)
Sets the value of a header to be sent with this request. A header set here will override any matching header set in the WebClient when the request is actually sent.

setImageButtonClickPosition

public void setImageButtonClickPosition(int x, int y)
Specifies the click position for the submit button. When a user clioks on an image button, not only the name and value of the button, but also the position of the mouse at the time of the click is submitted with the form. This method allows the caller to override the position selected when this request was created.

Throws: IllegalRequestParameterException thrown if the request was not created from a form with an image button.

setMimeEncoded

protected void setMimeEncoded(boolean mimeEncoded)
Selects whether MIME-encoding will be used for this request. MIME-encoding changes the way the request is sent and is required for requests which include file parameters. This method may only be called for a POST request which was not created from a form.

setParameter

public void setParameter(String name, String value)
Sets the value of a parameter in a web request.

setParameter

public void setParameter(String name, String[] values)
Sets the multiple values of a parameter in a web request.

setParameter

public void setParameter(String parameterName, UploadFileSpec[] files)
Sets the multiple values of a file upload parameter in a web request.

toString

public String toString()

writeMessageBody

protected void writeMessageBody(OutputStream stream)
Writes the contents of the message body to the specified stream.