use of org.eclipse.milo.opcua.stack.core.types.structured.ReadRequest in project milo by eclipse.
the class ClientServerTest method testClientStateMachine.
@Test
public void testClientStateMachine() throws Exception {
EndpointDescription endpoint = endpoints[0];
Variant input = new Variant(42);
logger.info("SecurityPolicy={}, MessageSecurityMode={}, input={}", SecurityPolicy.fromUri(endpoint.getSecurityPolicyUri()), endpoint.getSecurityMode(), input);
UaStackClient client = createClient(endpoint);
for (int i = 0; i < 1000; i++) {
client.connect().get();
RequestHeader header = new RequestHeader(NodeId.NULL_VALUE, DateTime.now(), uint(i), uint(0), null, DEFAULT_TIMEOUT_HINT, null);
ReadRequest request = new ReadRequest(header, 0.0, TimestampsToReturn.Neither, new ReadValueId[] { new ReadValueId(NodeId.NULL_VALUE, AttributeId.Value.uid(), null, null) });
logger.debug("sending request: {}", request);
UaResponseMessage response = client.sendRequest(request).get();
logger.debug("got response: {}", response);
client.disconnect().get();
}
}
use of org.eclipse.milo.opcua.stack.core.types.structured.ReadRequest in project milo by eclipse.
the class DataTypeDictionaryReader method readNodes.
private CompletableFuture<List<DataValue>> readNodes(List<ReadValueId> readValueIds) {
RequestHeader requestHeader = stackClient.newRequestHeader(session.getAuthenticationToken(), stackClient.getConfig().getRequestTimeout());
ReadRequest readRequest = new ReadRequest(requestHeader, 0.0, TimestampsToReturn.Neither, readValueIds.toArray(new ReadValueId[0]));
return stackClient.sendRequest(readRequest).thenApply(ReadResponse.class::cast).thenApply(r -> l(r.getResults()));
}
use of org.eclipse.milo.opcua.stack.core.types.structured.ReadRequest in project milo by eclipse.
the class DataTypeDictionaryReaderTest method testReadDataTypeDictionaryBytes.
private void testReadDataTypeDictionaryBytes(ByteString dictionary, int fragmentSize) throws Exception {
Mockito.when(stackClient.sendRequest(ArgumentMatchers.any(ReadRequest.class))).then(invocationOnMock -> {
ReadRequest readRequest = invocationOnMock.getArgument(0);
List<ReadValueId> readValueIds = Arrays.stream(Objects.requireNonNull(readRequest.getNodesToRead())).collect(Collectors.toList());
ReadValueId readValueId = readValueIds.get(0);
NumericRange numericRange = NumericRange.parse(readValueId.getIndexRange());
try {
Object fragment = NumericRange.readFromValueAtRange(new Variant(dictionary), numericRange);
return completedFuture(new ReadResponse(null, new DataValue[] { new DataValue(new Variant(fragment)) }, null));
} catch (UaException e) {
return completedFuture(new ReadResponse(null, new DataValue[] { new DataValue(e.getStatusCode()) }, null));
}
});
ByteString typeDictionaryBs = dictionaryReader.readDataTypeDictionaryBytes(NodeId.NULL_VALUE, fragmentSize).get();
Assertions.assertEquals(typeDictionaryBs, dictionary);
}
use of org.eclipse.milo.opcua.stack.core.types.structured.ReadRequest in project milo by eclipse.
the class DataTypeTreeBuilder method readNamespaceTable.
private static CompletableFuture<NamespaceTable> readNamespaceTable(UaStackClient client, OpcUaSession session) {
RequestHeader requestHeader = client.newRequestHeader(session.getAuthenticationToken(), client.getConfig().getRequestTimeout());
CompletableFuture<UaResponseMessage> readFuture = client.sendRequest(new ReadRequest(requestHeader, 0.0, TimestampsToReturn.Neither, new ReadValueId[] { new ReadValueId(Identifiers.Server_NamespaceArray, AttributeId.Value.uid(), null, QualifiedName.NULL_VALUE) }));
return readFuture.thenApply(ReadResponse.class::cast).thenApply(response -> {
DataValue dataValue = response.getResults()[0];
String[] namespaceUris = (String[]) dataValue.getValue().getValue();
NamespaceTable namespaceTable = new NamespaceTable();
for (String namespaceUri : namespaceUris) {
namespaceTable.addUri(namespaceUri);
}
return namespaceTable;
});
}
use of org.eclipse.milo.opcua.stack.core.types.structured.ReadRequest in project milo by eclipse.
the class ClientServerTest method testClientReconnect.
@Test
public void testClientReconnect() throws Exception {
EndpointDescription endpoint = endpoints[0];
Variant input = new Variant(42);
logger.info("SecurityPolicy={}, MessageSecurityMode={}, input={}", SecurityPolicy.fromUri(endpoint.getSecurityPolicyUri()), endpoint.getSecurityMode(), input);
UaStackClient client = createClient(endpoint);
client.connect().get();
RequestHeader header = new RequestHeader(NodeId.NULL_VALUE, DateTime.now(), uint(0), uint(0), null, DEFAULT_TIMEOUT_HINT, null);
ReadRequest request = new ReadRequest(header, 0.0, TimestampsToReturn.Neither, new ReadValueId[] { new ReadValueId(NodeId.NULL_VALUE, AttributeId.Value.uid(), null, null) });
logger.info("sending request: {}", request);
UaResponseMessage response0 = client.sendRequest(request).get();
logger.info("got response: {}", response0);
logger.info("initiating a reconnect by closing channel in server...");
server.getConnectedChannels().forEach(c -> {
try {
c.close().await();
} catch (InterruptedException e) {
e.printStackTrace();
}
});
logger.info("sending request: {}", request);
try {
UaResponseMessage response1 = client.sendRequest(request).get();
logger.info("got response: {}", response1);
} catch (Exception e) {
// try again because close() above is a race condition
UaResponseMessage response1 = client.sendRequest(request).get();
logger.info("got response: {}", response1);
}
client.disconnect().get();
}
Aggregations