public class RestAdapter extends Adapter
Adapter implementation for RESTful servers.
In addition to implementing the Adapter interface,
RestAdapter contains a single RestContract to map
remote methods to custom HTTP routes. This is only required if the HTTP
settings have been customized on the server. When in doubt, try without.RestContractAdapter.BinaryCallback, Adapter.Callback, Adapter.JsonArrayCallback, Adapter.JsonCallback, Adapter.JsonObjectCallback| Constructor and Description |
|---|
RestAdapter(android.content.Context context,
java.lang.String url) |
| Modifier and Type | Method and Description |
|---|---|
void |
connect(android.content.Context context,
java.lang.String url)
Connects the Adapter to `url`.
|
protected com.loopj.android.http.AsyncHttpClient |
getClient()
Get the underlying HTTP client.
|
RestContract |
getContract()
Gets this adapter's
RestContract, a custom contract for
fine-grained route configuration. |
void |
invokeInstanceMethod(java.lang.String method,
java.util.Map<java.lang.String,? extends java.lang.Object> constructorParameters,
java.util.Map<java.lang.String,? extends java.lang.Object> parameters,
Adapter.BinaryCallback callback)
Invokes a remotable method exposed within a prototype on the server,
parses the response as binary data.
|
void |
invokeInstanceMethod(java.lang.String method,
java.util.Map<java.lang.String,? extends java.lang.Object> constructorParameters,
java.util.Map<java.lang.String,? extends java.lang.Object> parameters,
Adapter.Callback callback)
Invokes a remotable method exposed within a prototype on the server.
|
void |
invokeStaticMethod(java.lang.String method,
java.util.Map<java.lang.String,? extends java.lang.Object> parameters,
Adapter.BinaryCallback callback)
Invokes a remotable method exposed statically on the server,
parses the response as binary data.
|
void |
invokeStaticMethod(java.lang.String method,
java.util.Map<java.lang.String,? extends java.lang.Object> parameters,
Adapter.Callback callback)
Invokes a remotable method exposed statically on the server.
|
boolean |
isConnected()
Gets whether this adapter is connected to a server.
|
void |
setContract(RestContract contract)
Sets this adapter's
RestContract, a custom contract for
fine-grained route configuration. |
public RestAdapter(android.content.Context context,
java.lang.String url)
public RestContract getContract()
RestContract, a custom contract for
fine-grained route configuration.protected com.loopj.android.http.AsyncHttpClient getClient()
public void setContract(RestContract contract)
RestContract, a custom contract for
fine-grained route configuration.contract - The contract.public void connect(android.content.Context context,
java.lang.String url)
Adapterpublic boolean isConnected()
AdapterisConnected in class Adaptertrue if connected, false otherwise.public void invokeStaticMethod(java.lang.String method,
java.util.Map<java.lang.String,? extends java.lang.Object> parameters,
Adapter.Callback callback)
Unlike Adapter.invokeInstanceMethod(String, Map, Map, Callback), no
object needs to be created on the server.
invokeStaticMethod in class Adaptermethod - The method to invoke, e.g.
"module.doSomething".parameters - The parameters to invoke with.callback - The callback to invoke when the execution finishes.java.lang.IllegalStateException - if the contract is not set
(see setContract(RestContract))
or the adapter is not connected.public void invokeStaticMethod(java.lang.String method,
java.util.Map<java.lang.String,? extends java.lang.Object> parameters,
Adapter.BinaryCallback callback)
Unlike Adapter.invokeInstanceMethod(String, Map, Map, BinaryCallback), no
object needs to be created on the server.
invokeStaticMethod in class Adaptermethod - The method to invoke, e.g.
"module.doSomething".parameters - The parameters to invoke with.callback - The callback to invoke when the execution finishes.java.lang.IllegalStateException - if the contract is not set
(see setContract(RestContract))
or the adapter is not connected.public void invokeInstanceMethod(java.lang.String method,
java.util.Map<java.lang.String,? extends java.lang.Object> constructorParameters,
java.util.Map<java.lang.String,? extends java.lang.Object> parameters,
Adapter.Callback callback)
This should be thought of as a two-step process. First, the server loads or creates an object with the appropriate type. Then and only then is the method invoked on that object. The two parameter dictionaries correspond to these two steps: `creationParameters` for the former, and `parameters` for the latter.
invokeInstanceMethod in class Adaptermethod - The method to invoke, e.g.
"MyClass.prototype.doSomething".constructorParameters - The parameters the virtual object should be
created with.parameters - The parameters to invoke with.callback - The callback to invoke when the execution finishes.java.lang.IllegalStateException - if the contract is not set
(see setContract(RestContract))
or the adapter is not connected.public void invokeInstanceMethod(java.lang.String method,
java.util.Map<java.lang.String,? extends java.lang.Object> constructorParameters,
java.util.Map<java.lang.String,? extends java.lang.Object> parameters,
Adapter.BinaryCallback callback)
This should be thought of as a two-step process. First, the server loads or creates an object with the appropriate type. Then and only then is the method invoked on that object. The two parameter dictionaries correspond to these two steps: `creationParameters` for the former, and `parameters` for the latter.
invokeInstanceMethod in class Adaptermethod - The method to invoke, e.g.
"MyClass.prototype.doSomething".constructorParameters - The parameters the virtual object should be
created with.parameters - The parameters to invoke with.callback - The callback to invoke when the execution finishes.java.lang.IllegalStateException - if the contract is not set
(see setContract(RestContract))
or the adapter is not connected.