Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Added hex and binary support to HTTP agent

Rich Turner52c32bb47a5e
diff --git a/agent/src/main/java/org/openremote/agent/protocol/http/HTTPAgent.java b/agent/src/main/java/org/openremote/agent/protocol/http/HTTPAgent.java
index 81b26a154..092bd0f19 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/http/HTTPAgent.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/http/HTTPAgent.java
@@ -98,6 +98,24 @@ public class HTTPAgent extends Agent<HTTPAgent, HTTPProtocol, HTTPAgentLink> {
return this;
}
+ public Optional<Boolean> getMessageConvertHex() {
+ return getAttributes().getValue(MESSAGE_CONVERT_HEX);
+ }
+
+ public HTTPAgent setMessageConvertHex(Boolean value) {
+ getAttributes().getOrCreate(MESSAGE_CONVERT_HEX).setValue(value);
+ return this;
+ }
+
+ public Optional<Boolean> getMessageConvertBinary() {
+ return getAttributes().getValue(MESSAGE_CONVERT_BINARY);
+ }
+
+ public HTTPAgent setMessageConvertBinary(Boolean value) {
+ getAttributes().getOrCreate(MESSAGE_CONVERT_BINARY).setValue(value);
+ return this;
+ }
+
@Override
public HTTPProtocol getProtocolInstance() {
return new HTTPProtocol(this);
diff --git a/agent/src/main/java/org/openremote/agent/protocol/http/HTTPAgentLink.java b/agent/src/main/java/org/openremote/agent/protocol/http/HTTPAgentLink.java
index 3a48974bc..12cc8d191 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/http/HTTPAgentLink.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/http/HTTPAgentLink.java
@@ -33,7 +33,7 @@ public class HTTPAgentLink extends AgentLink<HTTPAgentLink> {
" supplied a new header will be added with the key name and specified string value")
protected Map<String, List<String>> headers;
@JsonPropertyDescription("A JSON object of query parameters to be added to HTTP request URL; the key represents the name of the query parameter and for each string value" +
- " supplied a new query parameter will be added with the key name and specified string value (e.g. 'https://..../?test=1&test2")
+ " supplied a new query parameter will be added with the key name and specified string value (e.g. 'https://..../?test=1&test2'")
protected Map<String, List<String>> queryParameters;
@JsonPropertyDescription("Indicates that this HTTP request is used to update the linked attribute; this value indicates how frequently the HTTP request is made in order" +
" to update the linked attribute value")
@@ -48,6 +48,10 @@ public class HTTPAgentLink extends AgentLink<HTTPAgentLink> {
protected String contentType;
@JsonPropertyDescription("Allows the polled response to be written to another attribute with the specified name on the same asset as the linked attribute")
protected String pollingAttribute;
+ @JsonPropertyDescription("Indicates that the HTTP response is binary and should be converted to binary string representation")
+ protected boolean messageConvertBinary;
+ @JsonPropertyDescription("Indicates that the HTTP response is binary and should be converted to hexidecimal string representation")
+ protected boolean messageConvertHex;
// For Hydrators
protected HTTPAgentLink() {
@@ -128,4 +132,22 @@ public class HTTPAgentLink extends AgentLink<HTTPAgentLink> {
this.pollingAttribute = pollingAttribute;
return this;
}
+
+ public boolean isMessageConvertBinary() {
+ return messageConvertBinary;
+ }
+
+ public HTTPAgentLink setMessageConvertBinary(boolean messageConvertBinary) {
+ this.messageConvertBinary = messageConvertBinary;
+ return this;
+ }
+
+ public boolean isMessageConvertHex() {
+ return messageConvertHex;
+ }
+
+ public HTTPAgentLink setMessageConvertHex(boolean messageConvertHex) {
+ this.messageConvertHex = messageConvertHex;
+ return this;
+ }
}
diff --git a/agent/src/main/java/org/openremote/agent/protocol/http/HTTPProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/http/HTTPProtocol.java
index 55bbb89f4..e812d0997 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/http/HTTPProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/http/HTTPProtocol.java
@@ -29,12 +29,16 @@ import org.openremote.agent.protocol.AbstractProtocol;
import org.openremote.container.web.QueryParameterInjectorFilter;
import org.openremote.container.web.WebTargetBuilder;
import org.openremote.model.Container;
-import org.openremote.model.asset.agent.Agent;
+import org.openremote.model.asset.agent.AgentLink;
import org.openremote.model.asset.agent.ConnectionStatus;
import org.openremote.model.asset.agent.Protocol;
-import org.openremote.model.attribute.*;
+import org.openremote.model.attribute.Attribute;
+import org.openremote.model.attribute.AttributeEvent;
+import org.openremote.model.attribute.AttributeRef;
+import org.openremote.model.attribute.AttributeState;
import org.openremote.model.auth.OAuthGrant;
import org.openremote.model.auth.UsernamePassword;
+import org.openremote.model.protocol.ProtocolUtil;
import org.openremote.model.syslog.SyslogCategory;
import org.openremote.model.util.TextUtil;
import org.openremote.model.util.ValueUtil;
@@ -71,20 +75,20 @@ import static org.openremote.model.syslog.SyslogCategory.PROTOCOL;
* <h1>Response filtering</h1>
* <p>
* Any {@link Attribute} whose value is to be set by the HTTP server response (i.e. it has an {@link
- * HTTPAgent#META_REQUEST_POLLING_MILLIS} {@link MetaItem}) can use the standard {@link Agent#META_VALUE_FILTERS} in
- * order to filter the received HTTP response.
+ * HTTPAgentLink#getPollingMillis()} value can use the standard {@link AgentLink#getValueFilters()} in order to filter
+ * the received HTTP response.
* <p>
* <b>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</b>
* <h1>Dynamic value injection</h1>
- * This allows the {@link HTTPAgent#META_REQUEST_PATH} and/or {@link Agent#META_WRITE_VALUE} to contain the linked
- * {@link Attribute} value when sending requests. To dynamically inject the attribute value use
- * {@value Protocol#DYNAMIC_VALUE_PLACEHOLDER} as a placeholder and this will be dynamically replaced at request time.
+ * This allows the {@link HTTPAgentLink#getPath()}} and/or {@link AgentLink#getWriteValue()} to contain the linked
+ * {@link Attribute} value when sending requests. To dynamically inject the attribute value use {@value
+ * Protocol#DYNAMIC_VALUE_PLACEHOLDER} as a placeholder and this will be dynamically replaced at request time.
* <h2>Path example</h2>
- * {@link HTTPAgent#META_REQUEST_PATH} = "volume/set/{$value}" and request received to set attribute value to 100. Actual path
- * used for the request = "volume/set/100"
+ * {@link HTTPAgentLink#getPath()} = "volume/set/{$value}" and request received to set attribute value to 100. Actual
+ * path used for the request = "volume/set/100"
* <h2>Query parameter example</h2>
- * {@link HTTPAgent#META_REQUEST_QUERY_PARAMETERS} =
+ * {@link HTTPAgentLink#getQueryParameters()} =
* <blockquote><pre>
* {@code
* {
@@ -97,10 +101,10 @@ import static org.openremote.model.syslog.SyslogCategory.PROTOCOL;
* Request received to set attribute value to true. Actual query parameters injected into the request =
* "param1=val1&param1=val2&param2=12232&param3=true"
* <h2>Body examples</h2>
- * {@link Agent#META_WRITE_VALUE} = '<?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}"
+ * {@link 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}"
* <p>
- * {@link Agent#META_WRITE_VALUE} = '{myObject: "{$value}"}' and request received to set attribute value to:
+ * {@link AgentLink#getWriteValue()} = '{myObject: "{$value}"}' and request received to set attribute value to:
* <blockquote><pre>
* {@code
* {
@@ -150,14 +154,14 @@ public class HTTPProtocol extends AbstractProtocol<HTTPAgent, HTTPAgentLink> {
this.pagingEnabled = pagingEnabled;
this.contentType = contentType != null ? contentType : DEFAULT_CONTENT_TYPE;
dynamicQueryParameters = queryParameters != null
- && queryParameters
- .entrySet()
- .stream()
- .anyMatch(paramNameAndValues ->
- paramNameAndValues.getValue() != null
- && paramNameAndValues.getValue()
- .stream()
- .anyMatch(val -> val.contains(DYNAMIC_VALUE_PLACEHOLDER)));
+ && queryParameters
+ .entrySet()
+ .stream()
+ .anyMatch(paramNameAndValues ->
+ paramNameAndValues.getValue() != null
+ && paramNameAndValues.getValue()
+ .stream()
+ .anyMatch(val -> val.contains(DYNAMIC_VALUE_PLACEHOLDER)));
boolean dynamicPath = !TextUtil.isNullOrEmpty(path) && path.contains(DYNAMIC_VALUE_PLACEHOLDER);
if (!dynamicPath) {
@@ -274,17 +278,17 @@ public class HTTPProtocol extends AbstractProtocol<HTTPAgent, HTTPAgentLink> {
public static final String DEFAULT_CONTENT_TYPE = MediaType.TEXT_PLAIN;
protected static final Logger LOG = SyslogCategory.getLogger(PROTOCOL, HTTPProtocol.class);
public static int MIN_POLLING_MILLIS = 5000;
-
- protected ResteasyWebTarget webTarget;
- protected final Map<AttributeRef, HttpClientRequest> requestMap = new HashMap<>();
- protected final Map<AttributeRef, ScheduledFuture<?>> pollingMap = new HashMap<>();
- protected final Map<AttributeRef, Set<AttributeRef>> pollingLinkedAttributeMap = new HashMap<>();
protected static ResteasyClient client;
static {
client = createClient(org.openremote.container.Container.EXECUTOR_SERVICE);
}
+ protected final Map<AttributeRef, HttpClientRequest> requestMap = new HashMap<>();
+ protected final Map<AttributeRef, ScheduledFuture<?>> pollingMap = new HashMap<>();
+ protected final Map<AttributeRef, Set<AttributeRef>> pollingLinkedAttributeMap = new HashMap<>();
+ protected ResteasyWebTarget webTarget;
+
public HTTPProtocol(HTTPAgent agent) {
super(agent);
}
@@ -300,7 +304,7 @@ public class HTTPProtocol extends AbstractProtocol<HTTPAgent, HTTPAgentLink> {
protected void doStart(Container container) throws Exception {
String baseUri = agent.getBaseURI().orElseThrow(() ->
- new IllegalArgumentException("Missing or invalid base URI attribute: " + this));
+ new IllegalArgumentException("Missing or invalid base URI attribute: " + this));
if (baseUri.endsWith("/")) {
baseUri = baseUri.substring(0, baseUri.length() - 1);
@@ -339,7 +343,7 @@ public class HTTPProtocol extends AbstractProtocol<HTTPAgent, HTTPAgentLink> {
usernameAndPassword.ifPresent(userPass -> {
LOG.info("Adding Basic Authentication");
webTargetBuilder.setBasicAuthentication(userPass.getUsername(),
- userPass.getPassword());
+ userPass.getPassword());
});
}
@@ -383,16 +387,30 @@ public class HTTPProtocol extends AbstractProtocol<HTTPAgent, HTTPAgentLink> {
String body = agentLink.getWriteValue().orElse(null);
- addHttpClientRequest(
- attributeRef,
+ if (client == null) {
+ LOG.warning("Client is undefined: " + this);
+ return;
+ }
+
+ HttpClientRequest clientRequest = buildClientRequest(
path,
method,
- body,
- headers != null ? WebTargetBuilder.mapToMultivaluedMap(headers, new MultivaluedHashMap<String, Object>()) : null,
- queryParams != null ? WebTargetBuilder.mapToMultivaluedMap(queryParams, new MultivaluedHashMap<String, String>()) : null,
+ headers != null ? WebTargetBuilder.mapToMultivaluedMap(headers, new MultivaluedHashMap<>()) : null,
+ queryParams != null ? WebTargetBuilder.mapToMultivaluedMap(queryParams, new MultivaluedHashMap<>()) : null,
pagingEnabled,
- contentType,
- pollingMillis);
+ contentType);
+
+ LOG.fine("Creating HTTP request for attributeRef '" + clientRequest + "': " + attributeRef);
+
+ requestMap.put(attributeRef, clientRequest);
+
+ Optional.ofNullable(pollingMillis).ifPresent(seconds ->
+ pollingMap.put(attributeRef, schedulePollingRequest(
+ attributeRef,
+ agentLink,
+ clientRequest,
+ body,
+ seconds)));
}
@Override
@@ -417,15 +435,14 @@ public class HTTPProtocol extends AbstractProtocol<HTTPAgent, HTTPAgentLink> {
if (request != null) {
executeAttributeWriteRequest(request,
- processedValue,
- response -> onAttributeWriteResponse(request, response));
+ processedValue,
+ response -> onAttributeWriteResponse(request, response));
} else {
LOG.finest("Ignoring attribute write request as either attribute or agent is not linked: " + event);
}
}
-
@Override
public String getProtocolName() {
return PROTOCOL_DISPLAY_NAME;
@@ -436,71 +453,37 @@ public class HTTPProtocol extends AbstractProtocol<HTTPAgent, HTTPAgentLink> {
return webTarget != null ? webTarget.getUri().toString() : agent.getBaseURI().orElse("");
}
- protected void addHttpClientRequest(AttributeRef attributeRef,
- String path,
- String method,
- String body,
- MultivaluedMap<String, Object> headers,
- MultivaluedMap<String, String> queryParams,
- boolean pagingEnabled,
- String contentType,
- Integer pollingMillis) {
-
- if (client == null) {
- LOG.warning("Client is undefined: " + this);
- return;
- }
-
- HttpClientRequest clientRequest = buildClientRequest(
+ protected HttpClientRequest buildClientRequest(String path, String method, MultivaluedMap<String, Object> headers, MultivaluedMap<String, String> queryParams, boolean pagingEnabled, String contentType) {
+ return new HttpClientRequest(
+ webTarget,
path,
method,
headers,
queryParams,
pagingEnabled,
contentType);
-
- LOG.fine("Creating HTTP request for attributeRef '" + clientRequest + "': " + attributeRef);
-
- requestMap.put(attributeRef, clientRequest);
-
- Optional.ofNullable(pollingMillis).ifPresent(seconds -> {
- pollingMap.put(attributeRef, schedulePollingRequest(
- attributeRef,
- clientRequest,
- body,
- seconds));
- });
- }
-
- protected HttpClientRequest buildClientRequest(String path, String method, MultivaluedMap<String, Object> headers, MultivaluedMap<String, String> queryParams, boolean pagingEnabled, String contentType) {
- return new HttpClientRequest(
- webTarget,
- path,
- method,
- headers,
- queryParams,
- pagingEnabled,
- contentType);
}
protected ScheduledFuture<?> schedulePollingRequest(AttributeRef attributeRef,
- HttpClientRequest clientRequest,
- String body,
- int pollingMillis) {
+ HTTPAgentLink agentLink,
+ HttpClientRequest clientRequest,
+ String body,
+ int pollingMillis) {
LOG.fine("Scheduling polling request '" + clientRequest + "' to execute every " + pollingMillis + " ms for attribute: " + attributeRef);
return executorService.scheduleWithFixedDelay(() ->
- executePollingRequest(clientRequest, body, response -> {
- try {
- onPollingResponse(
- clientRequest,
- response,
- attributeRef);
- } catch (Exception e) {
- LOG.log(Level.WARNING, prefixLogMessage("Exception thrown whilst processing polling response [" + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()) + "]: " + clientRequest.requestTarget.getUriBuilder().build().toString()));
- }
- }), 0, pollingMillis, TimeUnit.MILLISECONDS);
+ executePollingRequest(clientRequest, body, response -> {
+ try {
+ onPollingResponse(
+ clientRequest,
+ response,
+ attributeRef,
+ agentLink);
+ } catch (Exception e) {
+ LOG.log(Level.WARNING, prefixLogMessage("Exception thrown whilst processing polling response [" + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()) + "]: " + clientRequest.requestTarget.getUriBuilder().build().toString()));
+ }
+ }), 0, pollingMillis, TimeUnit.MILLISECONDS);
}
protected void executePollingRequest(HttpClientRequest clientRequest, String body, Consumer<Response> responseConsumer) {
@@ -560,14 +543,23 @@ public class HTTPProtocol extends AbstractProtocol<HTTPAgent, HTTPAgentLink> {
protected void onPollingResponse(HttpClientRequest request,
Response response,
- AttributeRef attributeRef) {
+ AttributeRef attributeRef,
+ HTTPAgentLink agentLink) {
int responseCode = response != null ? response.getStatus() : 500;
Object value = null;
if (response != null && response.hasEntity() && response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) {
try {
- value = response.readEntity(String.class);
+ boolean binaryMode = agent.getMessageConvertBinary().orElse(agentLink.isMessageConvertBinary());
+ boolean hexMode = agent.getMessageConvertHex().orElse(agentLink.isMessageConvertHex());
+
+ if (hexMode || binaryMode) {
+ byte[] bytes = response.readEntity(byte[].class);
+ value = hexMode ? ProtocolUtil.bytesToHexString(bytes) : ProtocolUtil.bytesToBinaryString(bytes);
+ } else {
+ value = response.readEntity(String.class);
+ }
} catch (Exception e) {
LOG.log(Level.WARNING, "Error occurred whilst trying to read response body", e);
response.close();
diff --git a/model/src/main/java/org/openremote/model/protocol/ProtocolUtil.java b/model/src/main/java/org/openremote/model/protocol/ProtocolUtil.java
index 7608f421c..8c94b4bf7 100644
--- a/model/src/main/java/org/openremote/model/protocol/ProtocolUtil.java
+++ b/model/src/main/java/org/openremote/model/protocol/ProtocolUtil.java
@@ -23,6 +23,7 @@ import com.fasterxml.jackson.databind.node.JsonNodeType;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.commons.codec.binary.BinaryCodec;
import org.apache.commons.codec.binary.Hex;
+import org.apache.commons.lang3.ArrayUtils;
import org.openremote.model.asset.agent.AgentLink;
import org.openremote.model.asset.agent.Protocol;
import org.openremote.model.attribute.Attribute;
@@ -55,7 +56,7 @@ public final class ProtocolUtil {
}
public static String bytesToHexString(byte[] bytes) {
- return Hex.encodeHexString(bytes);
+ return Hex.encodeHexString(bytes).toUpperCase(Locale.ROOT);
}
public static byte[] bytesFromHexString(String hex) {
@@ -68,6 +69,8 @@ public final class ProtocolUtil {
}
public static String bytesToBinaryString(byte[] bytes) {
+ // Need to reverse the array to get a sensible string out
+ ArrayUtils.reverse(bytes);
return BinaryCodec.toAsciiString(bytes);
}
@@ -164,6 +167,8 @@ public final class ProtocolUtil {
return ignoreAndConvertedValue;
}
+ valRef.set(ignoreAndConvertedValue.value);
+
if (valRef.get() == null) {
return new Pair<>(false, null);
}
@@ -179,7 +184,6 @@ public final class ProtocolUtil {
if (valRef.get() == null) {
Protocol.LOG.warning("Failed to convert value: " + fromType + " -> " + toType);
Protocol.LOG.warning("Cannot send linked attribute update");
- return new Pair<>(true, null);
}
}
diff --git a/test/src/test/groovy/org/openremote/test/model/AssetModelTest.groovy b/test/src/test/groovy/org/openremote/test/model/AssetModelTest.groovy
index 45060da57..1693aea32 100644
--- a/test/src/test/groovy/org/openremote/test/model/AssetModelTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/model/AssetModelTest.groovy
@@ -195,6 +195,6 @@ class AssetModelTest extends Specification implements ManagerContainerTrait {
def assetStateObjectNode = ValueUtil.parse(assetStateStr, ObjectNode.class).get()
assetStateObjectNode.get("name").asText() == LightAsset.COLOUR_RGB.name
assetStateObjectNode.get("value").isTextual()
- assetStateObjectNode.get("value").asText() == "#3264c8"
+ assetStateObjectNode.get("value").asText() == "#3264C8"
}
}
diff --git a/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy
index dde581052..8cf6784ac 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy
@@ -39,9 +39,10 @@ import org.openremote.model.attribute.MetaItem
import org.openremote.model.auth.OAuthGrant
import org.openremote.model.auth.OAuthPasswordGrant
import org.openremote.model.auth.OAuthRefreshTokenGrant
+import org.openremote.model.util.ValueUtil
import org.openremote.model.value.RegexValueFilter
+import org.openremote.model.value.SubStringValueFilter
import org.openremote.model.value.ValueFilter
-import org.openremote.model.util.ValueUtil
import org.openremote.test.ManagerContainerTrait
import spock.lang.Shared
import spock.lang.Specification
@@ -213,6 +214,13 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTr
case "https://mockapi/redirect":
requestContext.abortWith(Response.temporaryRedirect(new URI("https://redirected.mockapi/get_success_200")).build())
return
+ case "https://mockapi/binary":
+ requestContext.abortWith(
+ Response.ok(
+ new byte[] {(byte)0x1F & 0xFF, (byte)0x56 & 0xFF, (byte)0x01 & 0xFF, (byte)0xAE & 0xFF, (byte)0x12 & 0xFF}, MediaType.APPLICATION_OCTET_STREAM_TYPE
+ ).build()
+ )
+ return
}
requestContext.abortWith(Response.serverError().build())
@@ -321,7 +329,7 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTr
.addMeta(
new MetaItem<>(AGENT_LINK, new HTTPAgentLink(agent.id)
.setPath("get_poll_slow")
- .setPollingMillis(50)
+ .setPollingMillis(200)
.setValueFilters(
[
new RegexValueFilter(Pattern.compile("\\d+"))
@@ -334,13 +342,49 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTr
.addMeta(
new MetaItem<>(AGENT_LINK, new HTTPAgentLink(agent.id)
.setPath("get_poll_fast")
- .setPollingMillis(40)
+ .setPollingMillis(100)
.setValueFilters(
[
new RegexValueFilter(Pattern.compile("\\d+")).setMatchIndex(1)
] as ValueFilter[]
)
)
+ ),
+ // attribute that expects binary data using GET and uses sub string on response
+ new Attribute<>("getBinary", TEXT)
+ .addMeta(
+ new MetaItem<>(AGENT_LINK, new HTTPAgentLink(agent.id)
+ .setPath("binary")
+ .setPollingMillis(100)
+ .setMessageConvertBinary(true)
+ .setValueFilters(
+ [
+ new SubStringValueFilter(22, 24)
+ ] as ValueFilter[]
+ )
+ .setValueConverter(ValueUtil.JSON.createObjectNode()
+ .put("00", "OFF")
+ .put("01", "ON")
+ )
+ )
+ ),
+ // attribute that expects HEX data using GET and uses sub string on response
+ new Attribute<>("getHex", TEXT)
+ .addMeta(
+ new MetaItem<>(AGENT_LINK, new HTTPAgentLink(agent.id)
+ .setPath("binary")
+ .setPollingMillis(100)
+ .setMessageConvertHex(true)
+ .setValueFilters(
+ [
+ new SubStringValueFilter(4, 6)
+ ] as ValueFilter[]
+ )
+ .setValueConverter(ValueUtil.JSON.createObjectNode()
+ .put("00", "OFF")
+ .put("01", "ON")
+ )
+ )
)
)
@@ -349,7 +393,7 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTr
then: "new request maps should be created in the HTTP client protocol for the linked attributes"
conditions.eventually {
- assert ((HTTPProtocol)agentService.getProtocolInstance(agent.id)).requestMap.size() == 4
+ assert ((HTTPProtocol)agentService.getProtocolInstance(agent.id)).requestMap.size() == 6
}
and: "the polling attributes should be polling the server"
@@ -364,6 +408,8 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTr
asset = assetStorageService.find(asset.getId(), true)
assert asset.getAttribute("getPollSlow").flatMap({it.value}).orElse(null) == 100
assert asset.getAttribute("getPollFast").flatMap({it.value}).orElse(null) == 60
+ assert asset.getAttribute("getBinary").flatMap({it.value}).orElse(null) == "ON"
+ assert asset.getAttribute("getHex").flatMap({it.value}).orElse(null) == "ON"
}
when: "a linked attribute value is updated"
@@ -445,7 +491,7 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTr
.addMeta(
new MetaItem<>(AGENT_LINK, new HTTPAgentLink(agent3.id)
.setPath("get_failure_401")
- .setPollingMillis(50)
+ .setPollingMillis(100)
)
),
new Attribute<>("getSuccess2", TEXT)