Class HTTPProtocol
java.lang.Object
org.openremote.agent.protocol.AbstractProtocol<HTTPAgent,HTTPAgentLink>
org.openremote.agent.protocol.http.HTTPProtocol
- All Implemented Interfaces:
org.openremote.model.asset.agent.Protocol<HTTPAgent>
This is a HTTP client protocol for communicating with HTTP servers; it uses the
WebTargetBuilder
factory to
generate JAX-RS WebTarget
s that can be used to make arbitrary calls to endpoints on a HTTP
server but it can also be extended and used as a JAX-RS client proxy.
Response filtering
Any Attribute
whose value is to be set by the HTTP server response (i.e. it has an HTTPAgentLink.getPollingMillis()
value can use the standard AgentLink.getValueFilters()
in order to filter
the received HTTP response.
NOTE: if an exception is thrown during the request that means no response is returned then this is treated as if a 500 response has been received
Dynamic placeholder injection
This allows the path, query params, headers and/orAgentLink.getWriteValue()
to contain the linked
Attribute
value when sending requests.
Path example
HTTPAgentLink.getPath()
= "volume/set/%VALUE%" and request received to set attribute value to 100. Actual
path used for the request = "volume/set/100"
Query parameter example
HTTPAgentLink.getQueryParameters()
=
Request received to set attribute value to true. Actual query parameters injected into the request = "param1=val1¶m1=val2¶m2=12232¶m3=true"{ param1: ["val1", "val2"], param2: 12232, param3: "%TIME%" }
Body examples
AgentLink.getWriteValue()
= <?xml version="1.0" encoding="UTF-8"?>%VALUE%</xml> and request received to
set attribute value to 100. Actual body used for the request = "{volume: 100}"
AgentLink.getWriteValue()
= '{myObject: "%VALUE%"}' and request received to set attribute value to:
Actual body used for the request = "{myObject: {prop1: true, prop2: "test", prop3: {prop4: 1234.4223}}}"{ prop1: true, prop2: "test", prop3: { prop4: 1234.4223 } }
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
protected static class
protected static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final AtomicReference<org.jboss.resteasy.client.jaxrs.ResteasyClient>
static final String
static final String
protected static final Logger
static int
protected final Map<org.openremote.model.attribute.AttributeRef,
Set<org.openremote.model.attribute.AttributeRef>> protected final Map<org.openremote.model.attribute.AttributeRef,
ScheduledFuture<?>> static final String
protected final Map<org.openremote.model.attribute.AttributeRef,
HTTPProtocol.HttpClientRequest> protected org.jboss.resteasy.client.jaxrs.ResteasyWebTarget
Fields inherited from class org.openremote.agent.protocol.AbstractProtocol
agent, assetService, datapointService, dynamicAttributes, executorService, linkedAttributes, messageBrokerContext, predictedDatapointService, processorLock, producerTemplate, scheduledExecutorService, timerService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected HTTPProtocol.HttpClientRequest
buildClientRequest
(String path, String method, jakarta.ws.rs.core.MultivaluedMap<String, ?> headers, jakarta.ws.rs.core.MultivaluedMap<String, ?> queryParams, boolean pagingEnabled, String contentType, org.openremote.container.timer.TimerService timerService) protected void
cancelPolling
(org.openremote.model.attribute.AttributeRef attributeRef) protected void
doLinkAttribute
(String assetId, org.openremote.model.attribute.Attribute<?> attribute, HTTPAgentLink agentLink) Link anAttribute
to its linkedAgent
.protected void
doLinkedAttributeWrite
(HTTPAgentLink agentLink, org.openremote.model.attribute.AttributeEvent event, Object processedValue) An Attribute event (write) has been requested for an attribute linked to this protocol.protected void
doStart
(org.openremote.model.Container container) Start this protocol instanceprotected void
doStop
(org.openremote.model.Container container) Stop this protocol instanceprotected void
doUnlinkAttribute
(String assetId, org.openremote.model.attribute.Attribute<?> attribute, HTTPAgentLink agentLink) Unlink anAttribute
from its linkedAgent
.protected void
executeAttributeWriteRequest
(HTTPProtocol.HttpClientRequest clientRequest, Object attributeValue, Consumer<jakarta.ws.rs.core.Response> responseConsumer) protected jakarta.ws.rs.core.Response
executePagingRequest
(HTTPProtocol.HttpClientRequest clientRequest, jakarta.ws.rs.core.Response response) protected void
executePollingRequest
(HTTPProtocol.HttpClientRequest clientRequest, String body, Consumer<jakarta.ws.rs.core.Response> responseConsumer) Get a URI that describes this specific protocol instanceGet the name for this protocolprotected static void
protected void
onAttributeWriteResponse
(HTTPProtocol.HttpClientRequest request, jakarta.ws.rs.core.Response response) protected void
onPollingResponse
(HTTPProtocol.HttpClientRequest request, jakarta.ws.rs.core.Response response, org.openremote.model.attribute.AttributeRef attributeRef, HTTPAgentLink agentLink) protected ScheduledFuture<?>
schedulePollingRequest
(org.openremote.model.attribute.AttributeRef attributeRef, org.openremote.model.attribute.Attribute<?> attribute, HTTPAgentLink agentLink, HTTPProtocol.HttpClientRequest clientRequest, int pollingMillis) Methods inherited from class org.openremote.agent.protocol.AbstractProtocol
getAgent, getLinkedAttributes, linkAttribute, onAgentAttributeChanged, processLinkedAttributeWrite, sendAttributeEvent, sendAttributeEvent, setAssetService, setConnectionStatus, start, stop, toString, unlinkAttribute, updateLinkedAttribute, updateLinkedAttribute
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.openremote.model.asset.agent.Protocol
prefixLogMessage
-
Field Details
-
PROTOCOL_DISPLAY_NAME
- See Also:
-
DEFAULT_HTTP_METHOD
- See Also:
-
DEFAULT_CONTENT_TYPE
- See Also:
-
LOG
-
MIN_POLLING_MILLIS
public static int MIN_POLLING_MILLIS -
client
-
requestMap
protected final Map<org.openremote.model.attribute.AttributeRef,HTTPProtocol.HttpClientRequest> requestMap -
pollingMap
-
pollingLinkedAttributeMap
-
webTarget
protected org.jboss.resteasy.client.jaxrs.ResteasyWebTarget webTarget
-
-
Constructor Details
-
HTTPProtocol
-
-
Method Details
-
doStop
protected void doStop(org.openremote.model.Container container) Description copied from class:AbstractProtocol
Stop this protocol instance- Specified by:
doStop
in classAbstractProtocol<HTTPAgent,
HTTPAgentLink>
-
doStart
Description copied from class:AbstractProtocol
Start this protocol instance- Specified by:
doStart
in classAbstractProtocol<HTTPAgent,
HTTPAgentLink> - Throws:
Exception
-
doLinkAttribute
protected void doLinkAttribute(String assetId, org.openremote.model.attribute.Attribute<?> attribute, HTTPAgentLink agentLink) Description copied from class:AbstractProtocol
Link anAttribute
to its linkedAgent
.- Specified by:
doLinkAttribute
in classAbstractProtocol<HTTPAgent,
HTTPAgentLink>
-
doUnlinkAttribute
protected void doUnlinkAttribute(String assetId, org.openremote.model.attribute.Attribute<?> attribute, HTTPAgentLink agentLink) Description copied from class:AbstractProtocol
Unlink anAttribute
from its linkedAgent
.- Specified by:
doUnlinkAttribute
in classAbstractProtocol<HTTPAgent,
HTTPAgentLink>
-
doLinkedAttributeWrite
protected void doLinkedAttributeWrite(HTTPAgentLink agentLink, org.openremote.model.attribute.AttributeEvent event, Object processedValue) Description copied from class:AbstractProtocol
An Attribute event (write) has been requested for an attribute linked to this protocol. The processedValue is the resulting value after applying standard outbound value processing (seeProtocolUtil.doOutboundValueProcessing(org.openremote.model.attribute.AttributeRef, org.openremote.model.asset.agent.AgentLink<?>, java.lang.Object, boolean, java.time.Instant)
). Protocol implementations should generally use the processedValue but may also choose to use the original value for some purpose if required.- Specified by:
doLinkedAttributeWrite
in classAbstractProtocol<HTTPAgent,
HTTPAgentLink>
-
getProtocolName
Description copied from interface:org.openremote.model.asset.agent.Protocol
Get the name for this protocol -
getProtocolInstanceUri
Description copied from interface:org.openremote.model.asset.agent.Protocol
Get a URI that describes this specific protocol instance -
initClient
protected static void initClient() -
buildClientRequest
-
schedulePollingRequest
protected ScheduledFuture<?> schedulePollingRequest(org.openremote.model.attribute.AttributeRef attributeRef, org.openremote.model.attribute.Attribute<?> attribute, HTTPAgentLink agentLink, HTTPProtocol.HttpClientRequest clientRequest, int pollingMillis) -
executePollingRequest
protected void executePollingRequest(HTTPProtocol.HttpClientRequest clientRequest, String body, Consumer<jakarta.ws.rs.core.Response> responseConsumer) -
executePagingRequest
protected jakarta.ws.rs.core.Response executePagingRequest(HTTPProtocol.HttpClientRequest clientRequest, jakarta.ws.rs.core.Response response) -
executeAttributeWriteRequest
protected void executeAttributeWriteRequest(HTTPProtocol.HttpClientRequest clientRequest, Object attributeValue, Consumer<jakarta.ws.rs.core.Response> responseConsumer) -
onPollingResponse
protected void onPollingResponse(HTTPProtocol.HttpClientRequest request, jakarta.ws.rs.core.Response response, org.openremote.model.attribute.AttributeRef attributeRef, HTTPAgentLink agentLink) -
onAttributeWriteResponse
protected void onAttributeWriteResponse(HTTPProtocol.HttpClientRequest request, jakarta.ws.rs.core.Response response) -
cancelPolling
protected void cancelPolling(org.openremote.model.attribute.AttributeRef attributeRef)
-