use of org.eclipse.milo.opcua.stack.client.UaStackClient 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.client.UaStackClient in project milo by eclipse.
the class ClientServerTest method testClientServerRoundTrip_TestStack_Basic128Rsa15_SignAndEncrypt.
@Test(dataProvider = "getVariants")
public void testClientServerRoundTrip_TestStack_Basic128Rsa15_SignAndEncrypt(Variant input) throws Exception {
EndpointDescription endpoint = endpoints[4];
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_SignAndEncrypt.
@Test(dataProvider = "getVariants")
public void testClientServerRoundTrip_TestStack_Basic256_SignAndEncrypt(Variant input) throws Exception {
EndpointDescription endpoint = endpoints[5];
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 SessionFsmFactory method activateSession.
@SuppressWarnings("Duplicates")
private static CompletableFuture<OpcUaSession> activateSession(FsmContext<State, Event> ctx, OpcUaClient client, CreateSessionResponse csr) {
UaStackClient stackClient = client.getStackClient();
try {
EndpointDescription endpoint = client.getConfig().getEndpoint();
ByteString csrNonce = csr.getServerNonce();
SignedIdentityToken signedIdentityToken = client.getConfig().getIdentityProvider().getIdentityToken(endpoint, csrNonce);
UserIdentityToken userIdentityToken = signedIdentityToken.getToken();
SignatureData userTokenSignature = signedIdentityToken.getSignature();
ActivateSessionRequest request = new ActivateSessionRequest(client.newRequestHeader(csr.getAuthenticationToken()), buildClientSignature(client.getConfig(), csrNonce), new SignedSoftwareCertificate[0], new String[0], ExtensionObject.encode(client.getStaticSerializationContext(), userIdentityToken), userTokenSignature);
LOGGER.debug("[{}] Sending ActivateSessionRequest...", ctx.getInstanceId());
return stackClient.sendRequest(request).thenApply(ActivateSessionResponse.class::cast).thenCompose(asr -> {
ByteString asrNonce = asr.getServerNonce();
// TODO check for repeated nonce?
OpcUaSession session = new OpcUaSession(csr.getAuthenticationToken(), csr.getSessionId(), client.getConfig().getSessionName().get(), csr.getRevisedSessionTimeout(), csr.getMaxRequestMessageSize(), csr.getServerCertificate(), csr.getServerSoftwareCertificates());
session.setServerNonce(asrNonce);
return completedFuture(session);
});
} catch (Exception ex) {
return failedFuture(ex);
}
}
use of org.eclipse.milo.opcua.stack.client.UaStackClient in project milo by eclipse.
the class SessionFsmFactory method closeSession.
private static CompletableFuture<Unit> closeSession(FsmContext<State, Event> ctx, OpcUaClient client, OpcUaSession session) {
CompletableFuture<Unit> closeFuture = new CompletableFuture<>();
UaStackClient stackClient = client.getStackClient();
RequestHeader requestHeader = stackClient.newRequestHeader(session.getAuthenticationToken(), uint(5000));
CloseSessionRequest request = new CloseSessionRequest(requestHeader, true);
LOGGER.debug("[{}] Sending CloseSessionRequest...", ctx.getInstanceId());
stackClient.sendRequest(request).whenCompleteAsync((csr, ex2) -> closeFuture.complete(Unit.VALUE), client.getConfig().getExecutor());
return closeFuture;
}
Aggregations