Class HttpRequest
java.lang.Object
ee.jakarta.tck.ws.rs.common.webclient.http.HttpRequest
- Direct Known Subclasses:
AdaptiveHttpRequest
,ApacheRequestAdapter
Represents an HTTP client Request
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Basic authenticationprotected org.apache.commons.httpclient.HttpClient
static int
Default HTTP port.static final int
Default HTTP SSL port.static final int
Digest authencticationstatic final int
No authentication -
Constructor Summary
ConstructorsConstructorDescriptionHttpRequest
(String requestLine, String host, int port) Creates new HttpRequest based of the passed request line. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addRequestHeader
(String header) void
addRequestHeader
(String headerName, String headerValue) addRequestHeader
adds a request header to this request.execute()
execute
will dispatch the current request to the target server.boolean
getFollowRedirects
indicates whether HTTP redirects are followed.getRequestMethod
returns the request type, i.e., GET, POST, etc.getRequestPath
returns the request path for this particular request.org.apache.commons.httpclient.HttpState
getState()
Returns the current state for this request.boolean
isSecureConnection()
indicates if the Request is secure or not.void
setAuthenticationCredentials
(String username, String password, int authType, String realm) setAuthenticationCredentials configures the request to perform authentication.
void
setContent
(String content) setContent
will set the body for this request.void
setFollowRedirects
(boolean followRedirects) setFollowRedirects
indicates whether HTTP redirects are followed.void
setRequestHeader
(String headerName, String headerValue) setRequestHeader
sets a request header for this request overwritting any previously existing header/values with the same name.void
setSecureRequest
(boolean secure) setSecureRequest
configures this request to use SSL.void
setState
(org.apache.commons.httpclient.HttpState state) setState
will set the HTTP state for the current request (i.e.toString()
-
Field Details
-
DEFAULT_HTTP_PORT
public static int DEFAULT_HTTP_PORTDefault HTTP port. -
DEFAULT_SSL_PORT
public static final int DEFAULT_SSL_PORTDefault HTTP SSL port.- See Also:
-
NO_AUTHENTICATION
public static final int NO_AUTHENTICATIONNo authentication- See Also:
-
BASIC_AUTHENTICATION
public static final int BASIC_AUTHENTICATIONBasic authentication- See Also:
-
DIGEST_AUTHENTICATION
public static final int DIGEST_AUTHENTICATIONDigest authenctication- See Also:
-
client
protected org.apache.commons.httpclient.HttpClient client
-
-
Constructor Details
-
HttpRequest
Creates new HttpRequest based of the passed request line. The request line provied must be in the form of:
METHOD PATH HTTP-VERSION Ex. GET /index.html HTTP/1.0
-
-
Method Details
-
getRequestPath
getRequestPath
returns the request path for this particular request.- Returns:
- String request path
-
getRequestMethod
getRequestMethod
returns the request type, i.e., GET, POST, etc.- Returns:
- String request type
-
isSecureRequest
public boolean isSecureRequest()isSecureConnection()
indicates if the Request is secure or not.- Returns:
- boolean whether Request is using SSL or not.
-
setSecureRequest
public void setSecureRequest(boolean secure) setSecureRequest
configures this request to use SSL.- Parameters:
secure
- - whether the Request uses SSL or not.
-
setContent
setContent
will set the body for this request. Note, this is only valid for POST and PUT operations, however, if called and the request represents some other HTTP method, it will be no-op'd.- Parameters:
content
- request content
-
setAuthenticationCredentials
public void setAuthenticationCredentials(String username, String password, int authType, String realm) setAuthenticationCredentials configures the request to perform authentication.
username
andpassword
cannot be null.It is legal for
realm
to be null.- Parameters:
username
- the userpassword
- the user's passwordauthType
- authentication typerealm
- authentication realm
-
addRequestHeader
addRequestHeader
adds a request header to this request. If a request header of the same name already exists, the new value, will be added to the set of already existing values. NOTE: that header names are not case-sensitive.- Parameters:
headerName
- request header nameheaderValue
- request header value
-
addRequestHeader
-
setRequestHeader
setRequestHeader
sets a request header for this request overwritting any previously existing header/values with the same name. NOTE: Header names are not case-sensitive.- Parameters:
headerName
- request header nameheaderValue
- request header value
-
setFollowRedirects
public void setFollowRedirects(boolean followRedirects) setFollowRedirects
indicates whether HTTP redirects are followed. By default, redirects are not followed. -
getFollowRedirects
public boolean getFollowRedirects()getFollowRedirects
indicates whether HTTP redirects are followed. -
setState
public void setState(org.apache.commons.httpclient.HttpState state) setState
will set the HTTP state for the current request (i.e. session tracking). This has the side affect -
execute
execute
will dispatch the current request to the target server.- Returns:
- HttpResponse the server's response.
- Throws:
IOException
- if an I/O error occurs during dispatch.org.apache.commons.httpclient.HttpException
-
getState
public org.apache.commons.httpclient.HttpState getState()Returns the current state for this request.- Returns:
- HttpState current state
-
toString
-