use of org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader in project milo by eclipse.
the class DiscoveryClient method findServers.
/**
* Query the FindServers service at the {@code endpointUrl}.
* <p>
* The endpoint URL(s) for each server {@link ApplicationDescription} in the response can then be used in a
* {@link #getEndpoints(String)} call to discover the endpoints for that server.
*
* @param endpointUrl the endpoint URL to find servers at.
* @param localeIds list of locales to use. The server should return the applicationName in the
* ApplicationDescription using one of locales specified. If the server supports more than one of
* the requested locales then the server shall use the locale that appears first in this list. If
* the server does not support any of the requested locales it chooses an appropriate default
* locale. The server chooses an appropriate default locale if this list is empty.
* @param serverUris list of servers to return. All known servers are returned if the list is empty.
* @return the {@link FindServersResponse}s returned by the FindServers service.
*/
public CompletableFuture<FindServersResponse> findServers(String endpointUrl, String[] localeIds, String[] serverUris) {
RequestHeader requestHeader = stackClient.newRequestHeader(NodeId.NULL_VALUE, stackClient.getConfig().getRequestTimeout());
FindServersRequest request = new FindServersRequest(requestHeader, endpointUrl, localeIds, serverUris);
return stackClient.sendRequest(request).thenApply(FindServersResponse.class::cast);
}
use of org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader in project milo by eclipse.
the class UaStackClient method sendRequest.
/**
* Send a {@link UaRequestMessage} to the connected server.
* <p>
* The {@link RequestHeader} of {@code request} must have a unique request handle. Use the
* {@code newRequestHeader} helper functions to create headers for {@link UaRequestMessage}s.
*
* @param request the {@link UaRequestMessage} to send.
* @return a {@link CompletableFuture} containing the eventual {@link UaResponseMessage} from the server.
* @see #newRequestHeader()
* @see #newRequestHeader(NodeId)
* @see #newRequestHeader(NodeId, UInteger)
*/
public CompletableFuture<UaResponseMessage> sendRequest(UaRequestMessage request) {
RequestHeader requestHeader = request.getRequestHeader();
UInteger requestHandle = requestHeader.getRequestHandle();
final CompletableFuture<UaResponseMessage> future = new CompletableFuture<>();
pending.put(requestHandle, future);
transport.sendRequest(request).whenComplete((response, ex) -> {
pending.remove(requestHandle);
deliverResponse(request, response, ex, future);
});
return future;
}
use of org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader 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.core.types.structured.RequestHeader 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.RequestHeader 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()));
}
Aggregations