Class HTTPProtocol

All Implemented Interfaces:
org.openremote.model.asset.agent.Protocol<HTTPAgent>

public class HTTPProtocol extends AbstractProtocol<HTTPAgent,HTTPAgentLink>
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 placeholder injection

This allows the path, query params, headers and/or AgentLink.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() =
 
 {
     param1: ["val1", "val2"],
     param2: 12232,
     param3: "%TIME%"
 }
 
 
Request received to set attribute value to true. Actual query parameters injected into the request = "param1=val1&param1=val2&param2=12232&param3=true"

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:

 
 {
   prop1: true,
   prop2: "test",
   prop3: {
       prop4: 1234.4223
   }
 }
 
 
Actual body used for the request = "{myObject: {prop1: true, prop2: "test", prop3: {prop4: 1234.4223}}}"
  • Field Details

    • PROTOCOL_DISPLAY_NAME

      public static final String PROTOCOL_DISPLAY_NAME
      See Also:
    • DEFAULT_HTTP_METHOD

      public static final String DEFAULT_HTTP_METHOD
      See Also:
    • DEFAULT_CONTENT_TYPE

      public static final String DEFAULT_CONTENT_TYPE
      See Also:
    • LOG

      protected static final Logger LOG
    • MIN_POLLING_MILLIS

      public static int MIN_POLLING_MILLIS
    • client

      protected static final AtomicReference<org.jboss.resteasy.client.jaxrs.ResteasyClient> client
    • requestMap

      protected final Map<org.openremote.model.attribute.AttributeRef,HTTPProtocol.HttpClientRequest> requestMap
    • pollingMap

      protected final Map<org.openremote.model.attribute.AttributeRef,ScheduledFuture<?>> pollingMap
    • pollingLinkedAttributeMap

      protected final Map<org.openremote.model.attribute.AttributeRef,Set<org.openremote.model.attribute.AttributeRef>> pollingLinkedAttributeMap
    • webTarget

      protected org.jboss.resteasy.client.jaxrs.ResteasyWebTarget webTarget
  • Constructor Details

    • HTTPProtocol

      public HTTPProtocol(HTTPAgent agent)
  • Method Details

    • doStop

      protected void doStop(org.openremote.model.Container container)
      Description copied from class: AbstractProtocol
      Stop this protocol instance
      Specified by:
      doStop in class AbstractProtocol<HTTPAgent,HTTPAgentLink>
    • doStart

      protected void doStart(org.openremote.model.Container container) throws Exception
      Description copied from class: AbstractProtocol
      Start this protocol instance
      Specified by:
      doStart in class AbstractProtocol<HTTPAgent,HTTPAgentLink>
      Throws:
      Exception
    • doLinkAttribute

      protected void doLinkAttribute(String assetId, org.openremote.model.attribute.Attribute<?> attribute, HTTPAgentLink agentLink)
      Description copied from class: AbstractProtocol
      Link an Attribute to its linked Agent.
      Specified by:
      doLinkAttribute in class AbstractProtocol<HTTPAgent,HTTPAgentLink>
    • doUnlinkAttribute

      protected void doUnlinkAttribute(String assetId, org.openremote.model.attribute.Attribute<?> attribute, HTTPAgentLink agentLink)
      Description copied from class: AbstractProtocol
      Unlink an Attribute from its linked Agent.
      Specified by:
      doUnlinkAttribute in class AbstractProtocol<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 (see ProtocolUtil.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 class AbstractProtocol<HTTPAgent,HTTPAgentLink>
    • getProtocolName

      public String getProtocolName()
      Description copied from interface: org.openremote.model.asset.agent.Protocol
      Get the name for this protocol
    • getProtocolInstanceUri

      public String 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

      protected 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)
    • 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)