Package com.meterware.httpunit
Class WebRequest
- java.lang.Object
-
- com.meterware.httpunit.WebRequest
-
- Direct Known Subclasses:
HeaderOnlyWebRequest,MessageBodyWebRequest
public abstract class WebRequest extends java.lang.ObjectA request sent to a web server.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Stringmethodthe HTTP method defined for this request e.g.
-
Constructor Summary
Constructors Modifier Constructor Description protectedWebRequest(WebForm sourceForm, com.meterware.httpunit.ParameterHolder parameterHolder, SubmitButton button, int x, int y)Constructs a web request from a form.protectedWebRequest(WebRequest baseRequest, java.lang.String urlString, java.lang.String target)Constructs a web request using a base request and a relative URL string.protectedWebRequest(WebRequestSource requestSource, com.meterware.httpunit.ParameterHolder parameterHolder)protectedWebRequest(WebResponse referer, org.w3c.dom.Element sourceElement, java.net.URL urlBase, java.lang.String urlString, java.lang.String target)Constructs a web request using a base URL, a relative URL string, and a target.protectedWebRequest(java.lang.String urlString)Constructs a web request using an absolute URL string.protectedWebRequest(java.net.URL urlBase, java.lang.String urlString)Constructs a web request using a base URL and a relative URL string.protectedWebRequest(java.net.URL urlBase, java.lang.String urlString, FrameSelector frame, java.lang.String target)Constructs a web request using a base URL, a relative URL string, and a target.protectedWebRequest(java.net.URL urlBase, java.lang.String urlString, java.lang.String target)Constructs a web request using a base URL, a relative URL string, and a target.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcompleteRequest(java.net.URLConnection connection)Performs any additional processing necessary to complete the request.protected java.lang.StringgetCharacterSet()Returns the character set required for this request.protected java.lang.StringgetContentType()Returns the content type of this request.java.util.DictionarygetHeaders()Returns a copy of the headers to be sent with this request.java.lang.StringgetMethod()java.lang.StringgetParameter(java.lang.String name)Returns the value of a parameter in this web request.protected com.meterware.httpunit.ParameterHoldergetParameterHolder()java.lang.String[]getParameterValues(java.lang.String name)Returns the multiple default values of the named parameter.java.lang.StringgetQueryString()Returns the query string defined for this request.java.lang.String[]getRequestParameterNames()Returns an array of all parameter names defined as part of this web request.java.lang.StringgetTarget()Returns the target for this web request.java.net.URLgetURL()Returns the final URL associated with this web request.protected java.net.URLgetURLBase()protected java.lang.StringgetURLString()booleanisFileParameter(java.lang.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(java.lang.String parameterName)Returns true if selectFile may be called with this parameter.voidremoveParameter(java.lang.String name)Removes a parameter from this web request.voidselectFile(java.lang.String parameterName, java.io.File file)Sets the file for a parameter upload in a web request.voidselectFile(java.lang.String parameterName, java.io.File file, java.lang.String contentType)Sets the file for a parameter upload in a web request.voidselectFile(java.lang.String parameterName, java.lang.String fileName, java.io.InputStream inputStream, java.lang.String contentType)Sets the file for a parameter upload in a web request.voidsetHeaderField(java.lang.String headerName, java.lang.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.voidsetParameter(java.lang.String parameterName, com.meterware.httpunit.protocol.UploadFileSpec[] files)Sets the multiple values of a file upload parameter in a web request.voidsetParameter(java.lang.String name, java.lang.String value)Sets the value of a parameter in a web request.voidsetParameter(java.lang.String name, java.lang.String[] values)Sets the multiple values of a parameter in a web request.java.lang.StringtoString()protected voidwriteMessageBody(java.io.OutputStream stream)Writes the contents of the message body to the specified stream.
-
-
-
Constructor Detail
-
WebRequest
protected WebRequest(java.lang.String urlString)
Constructs a web request using an absolute URL string.
-
WebRequest
protected WebRequest(java.net.URL urlBase, java.lang.String urlString)Constructs a web request using a base URL and a relative URL string.
-
WebRequest
protected WebRequest(WebRequest baseRequest, java.lang.String urlString, java.lang.String target) throws java.net.MalformedURLException
Constructs a web request using a base request and a relative URL string.- Throws:
java.net.MalformedURLException
-
WebRequest
protected WebRequest(java.net.URL urlBase, java.lang.String urlString, java.lang.String target)Constructs a web request using a base URL, a relative URL string, and a target.
-
WebRequest
protected WebRequest(WebResponse referer, org.w3c.dom.Element sourceElement, java.net.URL urlBase, java.lang.String urlString, java.lang.String target)
Constructs a web request using a base URL, a relative URL string, and a target.
-
WebRequest
protected WebRequest(java.net.URL urlBase, java.lang.String urlString, FrameSelector frame, java.lang.String target)Constructs a web request using a base URL, a relative URL string, and a target.
-
WebRequest
protected WebRequest(WebForm sourceForm, com.meterware.httpunit.ParameterHolder parameterHolder, SubmitButton button, int x, int y)
Constructs a web request from a form.- Parameters:
sourceForm- - the WebForm to startFromparameterHolder- - the parameter holderbutton- - the submit buttonx- - x positiony- - y position
-
WebRequest
protected WebRequest(WebRequestSource requestSource, com.meterware.httpunit.ParameterHolder parameterHolder)
-
-
Method Detail
-
setHeaderField
public void setHeaderField(java.lang.String headerName, java.lang.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.- Parameters:
headerName- - the name of the headerheaderValue- - the value to be set
-
getHeaders
public java.util.Dictionary getHeaders()
Returns a copy of the headers to be sent with this request.- Returns:
- the dictionary of headers
-
getURL
public java.net.URL getURL() throws java.net.MalformedURLExceptionReturns the final URL associated with this web request.- Returns:
- the Uniform Resource Locator for this Web request
- Throws:
java.net.MalformedURLException- if the URL is not o.k.
-
getTarget
public java.lang.String getTarget()
Returns the target for this web request.
-
getMethod
public java.lang.String getMethod()
- Returns:
- the method
-
getQueryString
public java.lang.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.
-
setParameter
public void setParameter(java.lang.String name, java.lang.String value)Sets the value of a parameter in a web request.
-
setParameter
public void setParameter(java.lang.String name, java.lang.String[] values)Sets the multiple values of a parameter in a web request.
-
setParameter
public void setParameter(java.lang.String parameterName, com.meterware.httpunit.protocol.UploadFileSpec[] files)Sets the multiple values of a file upload parameter in a web request.
-
setImageButtonClickPosition
public void setImageButtonClickPosition(int x, int y) throws IllegalRequestParameterExceptionSpecifies 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.
-
isFileParameter
public boolean isFileParameter(java.lang.String name)
Returns true if the specified parameter is a file field.
-
selectFile
public void selectFile(java.lang.String parameterName, java.io.File file)Sets the file for a parameter upload in a web request.
-
selectFile
public void selectFile(java.lang.String parameterName, java.io.File file, java.lang.String contentType)Sets the file for a parameter upload in a web request.
-
selectFile
public void selectFile(java.lang.String parameterName, java.lang.String fileName, java.io.InputStream inputStream, java.lang.String contentType)Sets the file for a parameter upload in a web request.
-
getRequestParameterNames
public java.lang.String[] getRequestParameterNames()
Returns an array of all parameter names defined as part of this web request.- Since:
- 1.3.1
-
getParameter
public java.lang.String getParameter(java.lang.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.
-
getParameterValues
public java.lang.String[] getParameterValues(java.lang.String name)
Returns the multiple default values of the named parameter.
-
removeParameter
public void removeParameter(java.lang.String name)
Removes a parameter from this web request.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
maySelectFile
protected boolean maySelectFile(java.lang.String parameterName)
Returns true if selectFile may be called with this parameter.
-
isMimeEncoded
protected boolean isMimeEncoded()
Returns true if this request is to be MIME-encoded.
-
getContentType
protected java.lang.String getContentType()
Returns the content type of this request. If null, no content is specified.
-
getCharacterSet
protected final java.lang.String getCharacterSet()
Returns the character set required for this request.
-
completeRequest
protected void completeRequest(java.net.URLConnection connection) throws java.io.IOExceptionPerforms any additional processing necessary to complete the request.- Throws:
java.io.IOException
-
writeMessageBody
protected void writeMessageBody(java.io.OutputStream stream) throws java.io.IOExceptionWrites the contents of the message body to the specified stream.- Throws:
java.io.IOException
-
getURLBase
protected final java.net.URL getURLBase()
-
getURLString
protected java.lang.String getURLString()
-
getParameterHolder
protected final com.meterware.httpunit.ParameterHolder getParameterHolder()
-
-