public abstract class AbstractRestOperation extends AbstractSynchronizableOperation implements IOperation
AbstractRestOperation
is an thread save, derivable
abstraction for remote communication using Representational state transfer
(REST).
This class contains the necessary implementation to establish the connection
to the remote host. Clients can register one ore more
IOperationDelegate
's to listen to the operations state.
By extending, clients need to set the URL by using setUrl(String)
.
The connection can be parameterized using query (
addQueryParameter(String, String)
or header
addHeaderParameter(String, String)
parameters.
The MD HTTP connection layer supports GET, POST, PUT and DELETE calls.
Clients have to overwrite getHTTPMethod()
to change the default HTTP
method.
The AbstractRestOperation
enables automatic HTTP Basic
authentication if the Credentials
are set in the Session
for
the calling URL. This behavior can be changed by overwriting
applyCredentials()
.
Constructor and Description |
---|
AbstractRestOperation() |
Modifier and Type | Method and Description |
---|---|
void |
addHeaderParameter(java.lang.String name,
java.lang.String value)
Adds a parameter to the HTTP header.
|
void |
addHeaderParameter(java.lang.String name,
java.lang.String[] values)
Adds a header parameter with multiple values.
|
void |
addQueryParameter(java.lang.String key,
java.lang.String value)
Adds a query parameter with a single value.
|
void |
addQueryParameter(java.lang.String name,
java.lang.String[] values)
Adds a new query parameter with multiple values.
|
java.lang.String[] |
getHeader()
Returns the header parameters.
|
java.util.Hashtable |
getHeaderParameters()
Returns all header parameters used for the request.
|
int |
getHTTPMethod()
Returns the HTTP method used for this operation.
|
java.util.Hashtable |
getQueryParameters()
Returns all query parameters used for the request.
|
java.lang.String |
getUrl()
Returns the used URL in combination with all query parameters.
|
void |
reset()
Resets the request and it's properties to it's initial state.
|
void |
setUrl(java.lang.String url)
Sets the url.
|
addOperationDelegate, execute, getRawResult, getResult, getResult, getResultCode, removeOperationDelegate
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addOperationDelegate, execute, getRawResult, getResult, getResult, getResultCode, removeOperationDelegate
public void reset()
public final void addQueryParameter(java.lang.String name, java.lang.String[] values)
addQueryParameter(String, String)
.name
- of the parametervalues
- all values for this parameter, must not be nullpublic final void addQueryParameter(java.lang.String key, java.lang.String value)
http://host:port?key=value&key2=value
key
- value
- public java.util.Hashtable getQueryParameters()
public final void addHeaderParameter(java.lang.String name, java.lang.String[] values)
addHeaderParameter(String, String)
.name
- of the parametervalues
- must not be nulladdHeaderParameter(String, String)
public final void addHeaderParameter(java.lang.String name, java.lang.String value)
name
- value
- public java.util.Hashtable getHeaderParameters()
public final java.lang.String getUrl()
public final void setUrl(java.lang.String url)
addQueryParameter(String, String)
.url
- public final java.lang.String[] getHeader()
public int getHTTPMethod()
HttpConnectionHandler.ACTION_GET
.
Supported types are (listed in HttpConnectionHandler
):
HttpConnectionHandler.ACTION_GET
HttpConnectionHandler.ACTION_POST
HttpConnectionHandler.ACTION_PUT
HttpConnectionHandler.ACTION_DELETE