use of org.eclipse.milo.opcua.stack.client.UaStackClient in project milo by eclipse.
the class DataTypeTreeBuilder method addChildren.
private static CompletableFuture<Unit> addChildren(Tree<DataTypeTree.DataType> tree, UaStackClient client, OpcUaSession session, NamespaceTable namespaceTable) {
CompletableFuture<List<ReferenceDescription>> subtypes = browseSafe(client, session, new BrowseDescription(tree.getValue().getNodeId(), BrowseDirection.Forward, Identifiers.HasSubtype, false, uint(NodeClass.DataType.getValue()), uint(BrowseResultMask.All.getValue())));
CompletableFuture<List<DataTypeTree.DataType>> dataTypesFuture = subtypes.thenCompose(references -> {
Stream<CompletableFuture<DataTypeTree.DataType>> dataTypeFutures = references.stream().map(dataTypeReference -> {
NodeId dataTypeId = dataTypeReference.getNodeId().toNodeId(namespaceTable).orElse(NodeId.NULL_VALUE);
CompletableFuture<List<ReferenceDescription>> encodings = browseSafe(client, session, new BrowseDescription(dataTypeId, BrowseDirection.Forward, Identifiers.HasEncoding, false, uint(NodeClass.Object.getValue()), uint(BrowseResultMask.All.getValue())));
return encodings.thenApply(encodingReferences -> {
NodeId binaryEncodingId = null;
NodeId xmlEncodingId = null;
for (ReferenceDescription r : encodingReferences) {
if (r.getBrowseName().equals(OpcUaDefaultBinaryEncoding.ENCODING_NAME)) {
binaryEncodingId = r.getNodeId().toNodeId(namespaceTable).orElse(null);
} else if (r.getBrowseName().equals(OpcUaDefaultXmlEncoding.ENCODING_NAME)) {
xmlEncodingId = r.getNodeId().toNodeId(namespaceTable).orElse(null);
}
}
return new DataTypeTree.DataType(dataTypeReference.getBrowseName(), dataTypeId, binaryEncodingId, xmlEncodingId);
});
});
return FutureUtils.sequence(dataTypeFutures);
});
return dataTypesFuture.thenCompose(dataTypes -> {
Stream<CompletableFuture<Unit>> futures = dataTypes.stream().map(tree::addChild).map(childNode -> addChildren(childNode, client, session, namespaceTable));
return FutureUtils.sequence(futures);
}).thenApply(v -> Unit.VALUE);
}
use of org.eclipse.milo.opcua.stack.client.UaStackClient in project milo by eclipse.
the class ClientServerTest method testClientServerRoundTrip_TestStack_Basic128Rsa15_Sign.
@Test(dataProvider = "getVariants")
public void testClientServerRoundTrip_TestStack_Basic128Rsa15_Sign(Variant input) throws Exception {
EndpointDescription endpoint = endpoints[1];
logger.info("SecurityPolicy={}, MessageSecurityMode={}, input={}", SecurityPolicy.fromUri(endpoint.getSecurityPolicyUri()), endpoint.getSecurityMode(), input);
UaStackClient client = createClient(endpoint);
connectAndTest(input, client);
}
use of org.eclipse.milo.opcua.stack.client.UaStackClient in project milo by eclipse.
the class ClientServerTest method testClientServerRoundTrip_TestStack_Basic256Sha256_SignAndEncrypt.
@Test(dataProvider = "getVariants")
public void testClientServerRoundTrip_TestStack_Basic256Sha256_SignAndEncrypt(Variant input) throws Exception {
EndpointDescription endpoint = endpoints[6];
logger.info("SecurityPolicy={}, MessageSecurityMode={}, input={}", SecurityPolicy.fromUri(endpoint.getSecurityPolicyUri()), endpoint.getSecurityMode(), input);
UaStackClient client = createClient(endpoint);
connectAndTest(input, client);
}
use of org.eclipse.milo.opcua.stack.client.UaStackClient in project milo by eclipse.
the class ClientServerTest method testClientDisconnect.
@Test
public void testClientDisconnect() 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);
client.disconnect().get();
assertThrows(() -> client.sendRequest(request).get());
}
use of org.eclipse.milo.opcua.stack.client.UaStackClient in project milo by eclipse.
the class ClientServerTest method testClientTimeout.
@Test
public void testClientTimeout() throws Exception {
EndpointDescription endpoint = endpoints[0];
logger.info("SecurityPolicy={}, MessageSecurityMode={}", SecurityPolicy.fromUri(endpoint.getSecurityPolicyUri()), endpoint.getSecurityMode());
UaStackClientConfig config = UaStackClientConfig.builder().setEndpoint(endpoint).setKeyPair(clientKeyPair).setCertificate(clientCertificate).build();
UaStackClient client = UaStackClient.create(config);
client.connect().get();
server.addServiceHandler("/test", ReadRequest.TYPE_ID, service -> {
// intentionally do nothing so the request can timeout
logger.info("received {}; ignoring...", service.getRequest());
});
RequestHeader header = new RequestHeader(NodeId.NULL_VALUE, DateTime.now(), uint(0), uint(0), null, uint(1000), null);
ReadRequest request = new ReadRequest(header, 0.0, TimestampsToReturn.Neither, new ReadValueId[] { new ReadValueId(NodeId.NULL_VALUE, AttributeId.Value.uid(), null, null) });
try {
client.sendRequest(request).get();
fail("expected response to timeout");
} catch (Throwable t) {
StatusCode statusCode = UaException.extractStatusCode(t).orElse(StatusCode.BAD);
assertEquals(statusCode.getValue(), StatusCodes.Bad_Timeout);
}
}
Aggregations