public abstract class AbstractRestOperation
extends java.lang.Object
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
IServiceDelegate
'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 and POST calls. To mark the
operation as a POST, set the data to be sent by using postData
.
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 name,
java.lang.String[] values)
Adds a new query parameter with multiple values.
|
void |
addServiceDelegate(IServiceDelegate delegate)
Adds a new
IServiceDelegate to watch the state of this operation. |
byte[] |
getByteResult()
Returns the result of this operation as an byte array.
|
java.lang.String[] |
getCookies()
Returns all cookies sent by the server after a successfully
communication.
|
java.lang.String[] |
getHeader()
Returns the header parameters.
|
int |
getResponseCode()
Returns the response code of the underlying
HttpConnection . |
java.lang.String |
getResult()
Returns the result of this operation as a String.
|
java.lang.String |
getResult(java.lang.String encoding)
Returns the result of this operation as a String by passing an encoding.
|
java.lang.String |
getUrl()
Returns the used URL in combination with all query parameters.
|
void |
removeServiceDelegate(IServiceDelegate delegate)
Removes the delivered
IServiceDelegate . |
void |
setUrl(java.lang.String url)
Sets the url.
|
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 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 final java.lang.String getUrl()
public final void setUrl(java.lang.String url)
addQueryParameter(String, String)
.url
- public final void addServiceDelegate(IServiceDelegate delegate)
IServiceDelegate
to watch the state of this operation.delegate
- public final void removeServiceDelegate(IServiceDelegate delegate)
IServiceDelegate
.delegate
- public final int getResponseCode()
HttpConnection
.public final java.lang.String[] getHeader()
public final java.lang.String[] getCookies()
public final java.lang.String getResult()
getResult(String)
.getResult(String)
,
getByteResult()
public final java.lang.String getResult(java.lang.String encoding) throws java.io.UnsupportedEncodingException
UnsupportedEncodingException
if the delivered encoding
is invalid.encoding
- java.io.UnsupportedEncodingException
public final byte[] getByteResult()