use of org.eclipse.milo.opcua.stack.core.UaRuntimeException in project netxms by netxms.
the class ServerConnection method getNodeValue.
/**
* Get value of given node, connecting to server as necessary
*
* @param name node symbolic name
* @return node value or null to indicate unsupported node
* @throws Exception
*/
public synchronized String getNodeValue(String name) throws Exception {
connect();
NodeId nodeId;
try {
nodeId = NodeId.parse(name);
} catch (UaRuntimeException e) {
Platform.writeDebugLog(6, String.format("OPCUA: error parsing node ID \"%s\"", name));
return null;
}
try {
return readNodeValue(nodeId);
} catch (ExecutionException e) {
return handleExecutionException(e, () -> {
return readNodeValue(nodeId);
});
} catch (Exception e) {
Platform.writeDebugLog(6, String.format("OPCUA: exception in getNodeValue(%s) call for %s (%s)", name, url, e.getMessage()));
Platform.writeDebugLog(6, "OPCUA: ", e);
return null;
}
}
use of org.eclipse.milo.opcua.stack.core.UaRuntimeException in project netxms by netxms.
the class ServerConnection method writeNode.
/**
* @param node
* @param value
* @return
* @throws Exception
*/
public boolean writeNode(String node, String value) throws Exception {
connect();
NodeId nodeId;
try {
nodeId = NodeId.parse(node);
} catch (UaRuntimeException e) {
Platform.writeDebugLog(6, String.format("OPCUA: error parsing node ID \"%s\"", node));
return false;
}
try {
return writeNodeValue(nodeId, value);
} catch (ExecutionException e) {
return handleExecutionException(e, () -> {
return writeNodeValue(nodeId, value);
});
} catch (Exception e) {
Platform.writeDebugLog(6, String.format("OPCUA: exception in writeNode(%s,%s) call for %s (%s)", node, value, url, e.getMessage()));
Platform.writeDebugLog(6, "OPCUA: ", e);
return false;
}
}
use of org.eclipse.milo.opcua.stack.core.UaRuntimeException in project milo by eclipse.
the class PShaUtil method createKey.
private static byte[] createKey(String transformation, byte[] secret, byte[] seed, int offset, int length) {
try {
Mac mac = Mac.getInstance(transformation);
byte[] tempBytes = hash(transformation, secret, seed, mac, offset + length);
byte[] key = new byte[length];
System.arraycopy(tempBytes, offset, key, 0, key.length);
return key;
} catch (Exception e) {
throw new UaRuntimeException(StatusCodes.Bad_InternalError, e);
}
}
use of org.eclipse.milo.opcua.stack.core.UaRuntimeException in project milo by eclipse.
the class ExpandedNodeId method parse.
/**
* Parse {@code s} into an {@link ExpandedNodeId}.
*
* @param s the String to parse.
* @return an {@link ExpandedNodeId}.
* @throws UaRuntimeException if parsing fails.
*/
public static ExpandedNodeId parse(String s) {
try {
String[] parts = s.split(";");
NodeId nodeId = NodeId.parse(parts[parts.length - 1]);
UInteger serverIndex = UInteger.MIN;
UShort namespaceIndex = UShort.MIN;
String namespaceUri = null;
Object identifier = nodeId.getIdentifier();
for (String part : parts) {
String[] ss = part.split("=", 2);
if ("svr".equals(ss[0])) {
serverIndex = uint(Integer.parseInt(ss[1]));
} else if ("ns".equals(ss[0])) {
namespaceIndex = ushort(Integer.parseInt(ss[1]));
} else if ("nsu".equals(ss[0])) {
namespaceUri = ss[1];
}
}
return new ExpandedNodeId(namespaceIndex, namespaceUri, identifier, serverIndex);
} catch (Throwable t) {
throw new UaRuntimeException(StatusCodes.Bad_NodeIdInvalid, t);
}
}
use of org.eclipse.milo.opcua.stack.core.UaRuntimeException in project milo by eclipse.
the class SessionManager method getServerSignature.
private SignatureData getServerSignature(SecurityPolicy securityPolicy, KeyPair keyPair, ByteString clientNonce, ByteString clientCertificate) throws UaException {
if (securityPolicy == SecurityPolicy.None) {
return new SignatureData(null, null);
} else {
try {
SecurityAlgorithm algorithm = securityPolicy.getAsymmetricSignatureAlgorithm();
byte[] data = Bytes.concat(clientCertificate.bytes(), clientNonce.bytes());
byte[] signature = SignatureUtil.sign(algorithm, keyPair.getPrivate(), ByteBuffer.wrap(data));
return new SignatureData(algorithm.getUri(), ByteString.of(signature));
} catch (UaRuntimeException e) {
throw new UaException(StatusCodes.Bad_SecurityChecksFailed);
}
}
}
Aggregations