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 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 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();
}
use of org.eclipse.milo.opcua.stack.client.UaStackClient in project milo by eclipse.
the class ClientServerTest method testClientServerRoundTrip_TestStack_NoSecurity.
@Test(dataProvider = "getVariants")
public void testClientServerRoundTrip_TestStack_NoSecurity(Variant input) throws Exception {
EndpointDescription endpoint = endpoints[0];
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_Basic256_Sign.
@Test(dataProvider = "getVariants")
public void testClientServerRoundTrip_TestStack_Basic256_Sign(Variant input) throws Exception {
EndpointDescription endpoint = endpoints[2];
logger.info("SecurityPolicy={}, MessageSecurityMode={}, input={}", SecurityPolicy.fromUri(endpoint.getSecurityPolicyUri()), endpoint.getSecurityMode(), input);
UaStackClient client = createClient(endpoint);
connectAndTest(input, client);
}
Aggregations