private URI getBinding(final String protocol, final String socketBinding) {
try {
//TODO: resolve socket binding group correctly
final String socketBindingGroupName = rootNode.get("socket-binding-group").keys().iterator().next();
final ModelNode operation = new ModelNode();
operation.get(OP_ADDR).get("socket-binding-group").set(socketBindingGroupName);
operation.get(OP_ADDR).get("socket-binding").set(socketBinding);
operation.get(OP).set(READ_ATTRIBUTE_OPERATION);
operation.get(NAME).set("bound-address");
String ip = executeForResult(operation).asString();
//it appears some system can return a binding with the zone specifier on the end
if(ip.contains(":") && ip.contains("%")) {
ip = ip.split("%")[0];
}
final ModelNode portOp = new ModelNode();
portOp.get(OP_ADDR).get("socket-binding-group").set(socketBindingGroupName);
portOp.get(OP_ADDR).get("socket-binding").set(socketBinding);
portOp.get(OP).set(READ_ATTRIBUTE_OPERATION);
portOp.get(NAME).set("bound-port");
final int port = defined(executeForResult(portOp), socketBindingGroupName + " -> " + socketBinding + " -> bound-port is undefined").asInt();
return URI.create(protocol + "://" + NetworkUtils.formatPossibleIpv6Address(ip) + ":" + port);
} catch (Exception e) {
throw new RuntimeException(e);