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 WebTargets 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 value injection
This allows theHTTPAgentLink.getPath()} and/or AgentLink.getWriteValue() to contain the linked
Attribute value when sending requests. To dynamically inject the attribute value use "{$value}" as a placeholder and this will be dynamically replaced at request time.
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: "{$value}" }
Body examples
AgentLink.getWriteValue() = '<?xml version="1.0" encoding="UTF-8"?>{$value}' 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 classprotected static classprotected static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static org.jboss.resteasy.client.jaxrs.ResteasyClientstatic final Stringstatic final Stringprotected static final Loggerstatic intprotected final Map<org.openremote.model.attribute.AttributeRef,Set<org.openremote.model.attribute.AttributeRef>> protected final Map<org.openremote.model.attribute.AttributeRef,ScheduledFuture<?>> static final Stringprotected final Map<org.openremote.model.attribute.AttributeRef,HTTPProtocol.HttpClientRequest> protected org.jboss.resteasy.client.jaxrs.ResteasyWebTargetFields inherited from class org.openremote.agent.protocol.AbstractProtocol
agent, assetService, datapointService, dynamicAttributes, executorService, linkedAttributes, messageBrokerContext, predictedDatapointService, producerTemplate, timerServiceFields inherited from interface org.openremote.model.asset.agent.Protocol
ACTUATOR_TOPIC, ACTUATOR_TOPIC_TARGET_PROTOCOL, DYNAMIC_TIME_PLACEHOLDER_REGEXP, DYNAMIC_VALUE_PLACEHOLDER, DYNAMIC_VALUE_PLACEHOLDER_REGEXP, SENSOR_QUEUE, SENSOR_QUEUE_SOURCE_PROTOCOL -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected HTTPProtocol.HttpClientRequestbuildClientRequest(String path, String method, javax.ws.rs.core.MultivaluedMap<String, Object> headers, javax.ws.rs.core.MultivaluedMap<String, String> queryParams, boolean pagingEnabled, String contentType) protected voidcancelPolling(org.openremote.model.attribute.AttributeRef attributeRef) protected voiddoLinkAttribute(String assetId, org.openremote.model.attribute.Attribute<?> attribute, HTTPAgentLink agentLink) Link anAttributeto its linkedAgent.protected voiddoLinkedAttributeWrite(org.openremote.model.attribute.Attribute<?> attribute, 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 voiddoStart(org.openremote.model.Container container) Start this protocol instanceprotected voiddoStop(org.openremote.model.Container container) Stop this protocol instanceprotected voiddoUnlinkAttribute(String assetId, org.openremote.model.attribute.Attribute<?> attribute, HTTPAgentLink agentLink) Unlink anAttributefrom its linkedAgent.protected voidexecuteAttributeWriteRequest(HTTPProtocol.HttpClientRequest clientRequest, Object attributeValue, Consumer<javax.ws.rs.core.Response> responseConsumer) protected javax.ws.rs.core.ResponseexecutePagingRequest(HTTPProtocol.HttpClientRequest clientRequest, javax.ws.rs.core.Response response) protected voidexecutePollingRequest(HTTPProtocol.HttpClientRequest clientRequest, String body, Consumer<javax.ws.rs.core.Response> responseConsumer) Get a URI that describes this specific protocol instanceGet the name for this protocolprotected voidonAttributeWriteResponse(HTTPProtocol.HttpClientRequest request, javax.ws.rs.core.Response response) protected voidonPollingResponse(HTTPProtocol.HttpClientRequest request, javax.ws.rs.core.Response response, org.openremote.model.attribute.AttributeRef attributeRef, HTTPAgentLink agentLink) protected ScheduledFuture<?>schedulePollingRequest(org.openremote.model.attribute.AttributeRef attributeRef, HTTPAgentLink agentLink, HTTPProtocol.HttpClientRequest clientRequest, String body, int pollingMillis) Methods inherited from class org.openremote.agent.protocol.AbstractProtocol
getAgent, getLinkedAttributes, linkAttribute, processLinkedAttributeWrite, sendAttributeEvent, sendAttributeEvent, setConnectionStatus, start, stop, toString, unlinkAttribute, updateAgentAttribute, updateLinkedAttribute, updateLinkedAttributeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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
protected static org.jboss.resteasy.client.jaxrs.ResteasyClient 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:AbstractProtocolStop this protocol instance- Specified by:
doStopin classAbstractProtocol<HTTPAgent,HTTPAgentLink>
-
doStart
Description copied from class:AbstractProtocolStart this protocol instance- Specified by:
doStartin classAbstractProtocol<HTTPAgent,HTTPAgentLink> - Throws:
Exception
-
doLinkAttribute
protected void doLinkAttribute(String assetId, org.openremote.model.attribute.Attribute<?> attribute, HTTPAgentLink agentLink) Description copied from class:AbstractProtocolLink anAttributeto its linkedAgent.- Specified by:
doLinkAttributein classAbstractProtocol<HTTPAgent,HTTPAgentLink>
-
doUnlinkAttribute
protected void doUnlinkAttribute(String assetId, org.openremote.model.attribute.Attribute<?> attribute, HTTPAgentLink agentLink) Description copied from class:AbstractProtocolUnlink anAttributefrom its linkedAgent.- Specified by:
doUnlinkAttributein classAbstractProtocol<HTTPAgent,HTTPAgentLink>
-
doLinkedAttributeWrite
protected void doLinkedAttributeWrite(org.openremote.model.attribute.Attribute<?> attribute, HTTPAgentLink agentLink, org.openremote.model.attribute.AttributeEvent event, Object processedValue) Description copied from class:AbstractProtocolAn 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(java.lang.String, org.openremote.model.attribute.Attribute<?>, org.openremote.model.asset.agent.AgentLink<?>, java.lang.Object, boolean)). Protocol implementations should generally use the processedValue but may also choose to use the original value for some purpose if required.- Specified by:
doLinkedAttributeWritein classAbstractProtocol<HTTPAgent,HTTPAgentLink>
-
getProtocolName
Description copied from interface:org.openremote.model.asset.agent.ProtocolGet the name for this protocol -
getProtocolInstanceUri
Description copied from interface:org.openremote.model.asset.agent.ProtocolGet a URI that describes this specific protocol instance -
buildClientRequest
-
schedulePollingRequest
protected ScheduledFuture<?> schedulePollingRequest(org.openremote.model.attribute.AttributeRef attributeRef, HTTPAgentLink agentLink, HTTPProtocol.HttpClientRequest clientRequest, String body, int pollingMillis) -
executePollingRequest
protected void executePollingRequest(HTTPProtocol.HttpClientRequest clientRequest, String body, Consumer<javax.ws.rs.core.Response> responseConsumer) -
executePagingRequest
protected javax.ws.rs.core.Response executePagingRequest(HTTPProtocol.HttpClientRequest clientRequest, javax.ws.rs.core.Response response) -
executeAttributeWriteRequest
protected void executeAttributeWriteRequest(HTTPProtocol.HttpClientRequest clientRequest, Object attributeValue, Consumer<javax.ws.rs.core.Response> responseConsumer) -
onPollingResponse
protected void onPollingResponse(HTTPProtocol.HttpClientRequest request, javax.ws.rs.core.Response response, org.openremote.model.attribute.AttributeRef attributeRef, HTTPAgentLink agentLink) -
onAttributeWriteResponse
protected void onAttributeWriteResponse(HTTPProtocol.HttpClientRequest request, javax.ws.rs.core.Response response) -
cancelPolling
protected void cancelPolling(org.openremote.model.attribute.AttributeRef attributeRef)
-