public class CoapClient
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
CoapClient.Builder
The Builder can be used to build a CoapClient if the URI's pieces are
available in separate strings.
|
Constructor and Description |
---|
CoapClient()
Constructs a new CoapClient that has no destination URI yet.
|
CoapClient(java.lang.String uri)
Constructs a new CoapClient that sends requests to the specified URI.
|
CoapClient(java.lang.String scheme,
java.lang.String host,
int port,
java.lang.String... path)
Constructs a new CoapClient with the specified scheme, host, port and
path as URI.
|
CoapClient(java.net.URI uri)
Constructs a new CoapClient that sends request to the specified URI.
|
Modifier and Type | Method and Description |
---|---|
void |
advanced(CoapHandler handler,
Request request)
Sends an advanced asynchronous request that has to be configured by the
developer.
|
CoapResponse |
advanced(Request request)
Sends an advanced synchronous request that has to be configured by the developer.
|
CoapResponse |
delete()
Sends a DELETE request and waits for the response.
|
void |
delete(CoapHandler handler)
Sends a DELETE request and invokes the specified handler when a response
arrives.
|
java.util.Set<WebLink> |
discover() |
java.util.Set<WebLink> |
discover(java.lang.String query) |
CoapResponse |
get()
Sends a GET request and blocks until the response is available.
|
void |
get(CoapHandler handler)
Sends a GET request and invokes the specified handler when a response
arrives.
|
void |
get(CoapHandler handler,
int accept)
Sends aGET request with the specified Accept option and invokes the
handler when a response arrives.
|
CoapResponse |
get(int accept)
Sends a GET request with the specified Accept option and blocks
until the response is available.
|
Endpoint |
getEndpoint()
Gets the endpoint this client uses.
|
long |
getTimeout()
Gets the timeout.
|
java.lang.String |
getURI()
Gets the destination URI of this client.
|
CoapObserveRelation |
observe(CoapHandler handler)
Sends an observe request and invokes the specified handler each time
a notification arrives.
|
CoapObserveRelation |
observe(CoapHandler handler,
int accept)
Sends an observe request with the specified Accept option and invokes the
specified handler each time a notification arrives.
|
CoapObserveRelation |
observeAndWait(CoapHandler handler)
Sends an observe request and waits until it has been established
whereupon the specified handler is invoked when a notification arrives.
|
CoapObserveRelation |
observeAndWait(CoapHandler handler,
int accept)
Sends an observe request with the specified Accept option and waits until
it has been established whereupon the specified handler is invoked when a
notification arrives.
|
boolean |
ping()
Performs a CoAP ping using the default timeout for requests.
|
boolean |
ping(long timeout)
Performs a CoAP ping and gives up after the given number of milliseconds.
|
CoapResponse |
post(byte[] payload,
int format)
Sends a POST request with the specified payload and the specified content
format option and blocks until the response is available.
|
CoapResponse |
post(byte[] payload,
int format,
int accept)
Sends a POST request with the specified payload, the specified content
format and the specified Accept option and blocks until the response is
available.
|
void |
post(CoapHandler handler,
byte[] payload,
int format)
Sends a POST request with the specified payload and the specified content
format and invokes the specified handler when a response arrives.
|
void |
post(CoapHandler handler,
byte[] payload,
int format,
int accept)
Sends a POST request with the specified payload, the specified content
format and accept and invokes the specified handler when a response
arrives.
|
void |
post(CoapHandler handler,
java.lang.String payload,
int format)
Sends a POST request with the specified payload and the specified content
format and invokes the specified handler when a response arrives.
|
void |
post(CoapHandler handler,
java.lang.String payload,
int format,
int accept)
Sends a POST request with the specified payload, the specified content
format and accept and invokes the specified handler when a response
arrives.
|
CoapResponse |
post(java.lang.String payload,
int format)
Sends a POST request with the specified payload and the specified content
format option and blocks until the response is available.
|
CoapResponse |
post(java.lang.String payload,
int format,
int accept)
Sends a POST request with the specified payload, the specified content
format and the specified Accept option and blocks until the response is
available.
|
CoapResponse |
put(byte[] payload,
int format)
Sends a PUT request with payload and required Content-Format and blocks
until the response is available.
|
void |
put(CoapHandler handler,
byte[] payload,
int format)
Sends a PUT request with the specified payload and the specified content
format and invokes the specified handler when a response arrives.
|
void |
put(CoapHandler handler,
java.lang.String payload,
int format)
Sends a PUT request with the specified payload and the specified content
format and invokes the specified handler when a response arrives.
|
CoapResponse |
put(java.lang.String payload,
int format)
Sends a PUT request with payload and required Content-Format and blocks
until the response is available.
|
CoapResponse |
putIfMatch(byte[] payload,
int format,
byte[]... etags)
Sends a PUT request with with the specified ETags in the If-Match option
and blocks until the response is available.
|
void |
putIfMatch(CoapHandler handler,
byte[] payload,
int format,
byte[]... etags) |
void |
putIfMatch(CoapHandler handler,
java.lang.String payload,
int format,
byte[]... etags) |
CoapResponse |
putIfMatch(java.lang.String payload,
int format,
byte[]... etags)
Sends a PUT request with with the specified ETags in the If-Match option
and blocks until the response is available.
|
CoapResponse |
putIfNoneMatch(byte[] payload,
int format)
Sends a PUT request with the If-None-Match option set and blocks until
the response is available.
|
void |
putIfNoneMatch(CoapHandler handler,
byte[] payload,
int format) |
CoapResponse |
putIfNoneMatch(java.lang.String payload,
int format)
Sends a PUT request with the If-None-Match option set and blocks until
the response is available.
|
CoapClient |
setEndpoint(Endpoint endpoint)
Sets the endpoint this client is supposed to use.
|
CoapClient |
setExecutor(java.util.concurrent.ExecutorService executor)
Sets the executor service for this client.
|
CoapClient |
setTimeout(long timeout)
Sets the timeout how long synchronous method calls will wait until they
give up and return anyways.
|
CoapClient |
setURI(java.lang.String uri)
Sets the destination URI of this client.
|
void |
shutdown()
Stops the client-specific executor service to cleanly exit programs.
|
CoapClient |
useCONs()
Let the client use Confirmable requests.
|
CoapClient |
useEarlyNegotiation(int size)
Let the client use early negotiation for the blocksize (16, 32, 64, 128,
256, 512, or 1024).
|
CoapClient |
useExecutor()
Sets a single-threaded executor to this client.
|
CoapClient |
useLateNegotiation()
Let the client use late negotiation for the block size (default).
|
CoapClient |
useNONs()
Let the client use Non-Confirmable requests.
|
CoapResponse |
validate(byte[]... etags) |
void |
validate(CoapHandler handler,
byte[]... etags) |
public CoapClient()
public CoapClient(java.lang.String uri)
uri
- the uripublic CoapClient(java.net.URI uri)
uri
- the uripublic CoapClient(java.lang.String scheme, java.lang.String host, int port, java.lang.String... path)
scheme
- the schemehost
- the hostport
- the portpath
- the pathpublic long getTimeout()
public CoapClient setTimeout(long timeout)
timeout
- the timeoutpublic java.lang.String getURI()
public CoapClient setURI(java.lang.String uri)
uri
- the uripublic CoapClient useExecutor()
public CoapClient setExecutor(java.util.concurrent.ExecutorService executor)
executor
- the executor servicepublic Endpoint getEndpoint()
public CoapClient setEndpoint(Endpoint endpoint)
endpoint
- the endpointpublic CoapClient useCONs()
public CoapClient useNONs()
public CoapClient useEarlyNegotiation(int size)
size
- the preferred block sizepublic CoapClient useLateNegotiation()
public boolean ping()
public boolean ping(long timeout)
timeout
- the time to wait for a pong in mspublic java.util.Set<WebLink> discover()
public java.util.Set<WebLink> discover(java.lang.String query)
public CoapResponse get()
public CoapResponse get(int accept)
accept
- the Accept optionpublic void get(CoapHandler handler)
handler
- the Response handlerpublic void get(CoapHandler handler, int accept)
handler
- the Response handleraccept
- the Accept optionpublic CoapResponse post(java.lang.String payload, int format)
payload
- the payloadformat
- the Content-Formatpublic CoapResponse post(byte[] payload, int format)
payload
- the payloadformat
- the Content-Formatpublic CoapResponse post(java.lang.String payload, int format, int accept)
payload
- the payloadformat
- the Content-Formataccept
- the Accept optionpublic CoapResponse post(byte[] payload, int format, int accept)
payload
- the payloadformat
- the Content-Formataccept
- the Accept optionpublic void post(CoapHandler handler, java.lang.String payload, int format)
handler
- the Response handlerpayload
- the payloadformat
- the Content-Formatpublic void post(CoapHandler handler, byte[] payload, int format)
handler
- the Response handlerpayload
- the payloadformat
- the Content-Formatpublic void post(CoapHandler handler, java.lang.String payload, int format, int accept)
handler
- the Response handlerpayload
- the payloadformat
- the Content-Formataccept
- the Accept optionpublic void post(CoapHandler handler, byte[] payload, int format, int accept)
handler
- the Response handlerpayload
- the payloadformat
- the Content-Formataccept
- the Accept optionpublic CoapResponse put(java.lang.String payload, int format)
payload
- the payloadformat
- the Content-Formatpublic CoapResponse put(byte[] payload, int format)
payload
- the payloadformat
- the Content-Formatpublic CoapResponse putIfMatch(java.lang.String payload, int format, byte[]... etags)
payload
- the payload stringformat
- the Content-Formatetags
- the ETags for the If-Match optionpublic CoapResponse putIfMatch(byte[] payload, int format, byte[]... etags)
payload
- the payloadformat
- the Content-Formatetags
- the ETags for the If-Match optionpublic CoapResponse putIfNoneMatch(java.lang.String payload, int format)
payload
- the payload stringformat
- the Content-Formatpublic CoapResponse putIfNoneMatch(byte[] payload, int format)
payload
- the payloadformat
- the Content-Formatpublic void put(CoapHandler handler, java.lang.String payload, int format)
handler
- the Response handlerpayload
- the payloadformat
- the Content-Formatpublic void put(CoapHandler handler, byte[] payload, int format)
handler
- the Response handlerpayload
- the payloadformat
- the Content-Formatpublic void putIfMatch(CoapHandler handler, java.lang.String payload, int format, byte[]... etags)
handler
- the Response handlerpayload
- the payloadformat
- the Content-Formatetags
- the ETags for the If-Match optionpublic void putIfMatch(CoapHandler handler, byte[] payload, int format, byte[]... etags)
handler
- the Response handlerpayload
- the payloadformat
- the Content-Formatetags
- the ETags for the If-Match optionpublic void putIfNoneMatch(CoapHandler handler, byte[] payload, int format)
handler
- the Response handlerpayload
- the payloadformat
- the Content-Formatpublic CoapResponse delete()
public void delete(CoapHandler handler)
handler
- the response handlerpublic CoapResponse validate(byte[]... etags)
public void validate(CoapHandler handler, byte[]... etags)
public CoapResponse advanced(Request request)
request
- the custom requestpublic void advanced(CoapHandler handler, Request request)
handler
- the response handlerrequest
- the custom requestpublic CoapObserveRelation observeAndWait(CoapHandler handler)
handler
- the Response handlerpublic CoapObserveRelation observeAndWait(CoapHandler handler, int accept)
handler
- the Response handleraccept
- the Accept optionpublic CoapObserveRelation observe(CoapHandler handler)
handler
- the Response handlerpublic CoapObserveRelation observe(CoapHandler handler, int accept)
handler
- the Response handleraccept
- the Accept optionpublic void shutdown()
useExecutor()
or setExecutor(ExecutorService)
are used (i.e., a client-specific executor service was set).