├── javadoc ├── package-list ├── resources │ └── inherit.gif ├── packages.html ├── script.js ├── stylesheet.css ├── allclasses-noframe.html ├── allclasses-frame.html ├── net │ └── juniper │ │ └── netconf │ │ ├── package-frame.html │ │ ├── class-use │ │ ├── Device.html │ │ ├── XMLBuilder.html │ │ ├── LoadException.html │ │ ├── NetconfSession.html │ │ └── CommitException.html │ │ ├── package-use.html │ │ ├── package-tree.html │ │ └── package-summary.html ├── overview-frame.html ├── index.html ├── deprecated-list.html ├── serialized-form.html ├── overview-tree.html ├── constant-values.html ├── overview-summary.html └── help-doc.html ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ ├── maven-wrapper.properties │ └── MavenWrapperDownloader.java ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── src ├── test │ ├── resources │ │ ├── sampleCliOutputReply.xml │ │ ├── sampleMissingElement.xml │ │ ├── sampleEmptyFPCTempRpcReply.xml │ │ ├── sampleFPCTempRPCReply.xml │ │ ├── log4j.properties │ │ └── responses │ │ │ └── lldpResponse.xml │ └── java │ │ └── net │ │ └── juniper │ │ └── netconf │ │ ├── TestHelper.java │ │ ├── LoadExceptionTest.java │ │ ├── CommitExceptionTest.java │ │ ├── DatastoreTest.java │ │ ├── NetconfExceptionTest.java │ │ ├── TestConstants.java │ │ ├── element │ │ ├── DatastoreTest.java │ │ ├── RpcErrorTest.java │ │ ├── HelloTest.java │ │ └── RpcReplyLoadConfigResultsTest.java │ │ ├── integration │ │ ├── INTEGRATION_TESTS.md │ │ ├── RUN-CRPD-CONTAINER.md │ │ └── run-integration-tests.sh │ │ └── XMLBuilderTest.java └── main │ └── java │ └── net │ └── juniper │ └── netconf │ ├── CommitException.java │ ├── NetconfException.java │ ├── LoadException.java │ ├── element │ ├── Datastore.java │ └── AbstractNetconfElement.java │ └── NetconfConstants.java ├── .gitignore ├── .editorconfig ├── examples ├── ShowChassis.java ├── CreateDevice.java ├── parse_system_info.java ├── parse_interface_info.java ├── EditConfiguration.java └── snmp_config.java ├── .github └── workflows │ ├── maven.yml │ └── codeql-analysis.yml ├── LICENSE ├── gradlew.bat ├── README.md ├── mvnw.cmd └── gradlew /javadoc/package-list: -------------------------------------------------------------------------------- 1 | net.juniper.netconf 2 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Juniper/netconf-java/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /javadoc/resources/inherit.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Juniper/netconf-java/HEAD/javadoc/resources/inherit.gif -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Juniper/netconf-java/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | -------------------------------------------------------------------------------- /src/test/resources/sampleCliOutputReply.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | operational-response 4 | 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /src/test/resources/sampleMissingElement.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Routing Engine 0 5 | 41 degrees C / 105 degrees F 6 | 7 | -------------------------------------------------------------------------------- /src/test/resources/sampleEmptyFPCTempRpcReply.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Routing Engine 0 5 | 41 degrees C / 105 degrees F 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Package Files # 4 | *.jar 5 | *.war 6 | *.ear 7 | 8 | target 9 | .settings 10 | .project 11 | .classpath 12 | 13 | # IntelliJ # 14 | *.iml 15 | .idea/ 16 | .gradle 17 | gradle/* 18 | !gradle/wrapper/ 19 | !gradle/wrapper/gradle-wrapper.jar 20 | !gradle/wrapper/gradle-wrapper.properties 21 | 22 | build/ 23 | libraries/ 24 | 25 | logs/ 26 | log-test/ 27 | 28 | .DS_Store 29 | .factorypath 30 | settings.json -------------------------------------------------------------------------------- /src/main/java/net/juniper/netconf/CommitException.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 Juniper Networks, Inc. 3 | All Rights Reserved 4 | 5 | Use is subject to license terms. 6 | 7 | */ 8 | 9 | package net.juniper.netconf; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * Describes exceptions related to commit operation 15 | */ 16 | public class CommitException extends IOException { 17 | CommitException(String msg) { 18 | super(msg); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # See https://editorconfig.org/ 2 | [*] 3 | charset = utf-8 4 | end_of_line = lf 5 | indent_size = 4 6 | indent_style = space 7 | insert_final_newline = false 8 | max_line_length = 120 9 | tab_width = 4 10 | 11 | [{*.bat,*.cmd}] 12 | end_of_line = crlf 13 | 14 | [*.java] 15 | ij_java_blank_lines_after_imports = 1 16 | ij_java_blank_lines_before_imports = 1 17 | ij_java_class_count_to_use_import_on_demand = 999 18 | ij_java_imports_layout = *,|,javax.**,java.**,|,$* 19 | ij_java_layout_static_imports_separately = true 20 | ij_java_names_count_to_use_import_on_demand = 999 21 | ij_java_use_single_class_imports = true 22 | -------------------------------------------------------------------------------- /src/test/java/net/juniper/netconf/TestHelper.java: -------------------------------------------------------------------------------- 1 | package net.juniper.netconf; 2 | 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.net.URL; 6 | 7 | class TestHelper { 8 | 9 | static File getSampleFile(String fileName) throws FileNotFoundException { 10 | URL sampleFileUri = ClassLoader.getSystemClassLoader() 11 | .getResource(fileName); 12 | if (sampleFileUri == null) { 13 | throw new FileNotFoundException(String.format("Could not find file %s", fileName)); 14 | } 15 | return new File(sampleFileUri.getFile()); 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /src/test/java/net/juniper/netconf/LoadExceptionTest.java: -------------------------------------------------------------------------------- 1 | package net.juniper.netconf; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 5 | 6 | public class LoadExceptionTest { 7 | 8 | private static final String TEST_MESSAGE = "test message"; 9 | 10 | private void throwLoadException() throws LoadException { 11 | throw new LoadException(TEST_MESSAGE); 12 | } 13 | 14 | 15 | @Test 16 | public void GIVEN_newLoadException_THEN_exceptionCreated() { 17 | assertThatThrownBy(this::throwLoadException) 18 | .isInstanceOf(LoadException.class) 19 | .hasMessage(TEST_MESSAGE); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/net/juniper/netconf/CommitExceptionTest.java: -------------------------------------------------------------------------------- 1 | package net.juniper.netconf; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 6 | 7 | public class CommitExceptionTest { 8 | private static final String TEST_MESSAGE = "test message"; 9 | 10 | private void throwCommitException() throws CommitException { 11 | throw new CommitException(TEST_MESSAGE); 12 | } 13 | 14 | @Test 15 | public void GIVEN_newCommitException_THEN_exceptionCreated() { 16 | assertThatThrownBy(this::throwCommitException) 17 | .isInstanceOf(CommitException.class) 18 | .hasMessage(TEST_MESSAGE); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/net/juniper/netconf/DatastoreTest.java: -------------------------------------------------------------------------------- 1 | package net.juniper.netconf; 2 | 3 | import net.juniper.netconf.element.Datastore; 4 | import org.junit.jupiter.api.Test; 5 | import static org.assertj.core.api.Assertions.assertThat; 6 | 7 | public class DatastoreTest { 8 | @Test 9 | public void testDatastoreName() { 10 | assertThat(Datastore.OPERATIONAL.toString()).isEqualTo("operational"); 11 | assertThat(Datastore.RUNNING.toString()).isEqualTo("running"); 12 | assertThat(Datastore.CANDIDATE.toString()).isEqualTo("candidate"); 13 | assertThat(Datastore.STARTUP.toString()).isEqualTo("startup"); 14 | assertThat(Datastore.INTENDED.toString()).isEqualTo("intended"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/net/juniper/netconf/NetconfExceptionTest.java: -------------------------------------------------------------------------------- 1 | package net.juniper.netconf; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 6 | 7 | public class NetconfExceptionTest { 8 | private static final String TEST_MESSAGE = "test message"; 9 | 10 | private void throwNetconfException() throws NetconfException { 11 | throw new NetconfException(TEST_MESSAGE); 12 | } 13 | 14 | @Test 15 | public void GIVEN_newNetconfException_THEN_exceptionCreated() { 16 | assertThatThrownBy(this::throwNetconfException) 17 | .isInstanceOf(NetconfException.class) 18 | .hasMessage(TEST_MESSAGE); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/resources/sampleFPCTempRPCReply.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Routing Engine 0 5 | 6 | 41 degrees C / 105 degrees F 7 | 8 | 9 | 10 | Routing Engine 1 11 | 12 | 37 degrees C / 98 degrees F 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=DEBUG, file, stdout 3 | 4 | # Direct log messages to a log file 5 | log4j.appender.file=org.apache.log4j.RollingFileAppender 6 | log4j.appender.file.File=log-test/netconf-java.log 7 | log4j.appender.file.MaxFileSize=100MB 8 | log4j.appender.file.MaxBackupIndex=10 9 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 11 | 12 | # Direct log messages to stdout 13 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 14 | log4j.appender.stdout.Target=System.out 15 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n -------------------------------------------------------------------------------- /javadoc/packages.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |
21 | 22 |
23 |
24 | The front page has been relocated.Please see: 25 |
26 |           Frame version 27 |
28 |           Non-frame version.
29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/test/resources/responses/lldpResponse.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | xe-0/0/9:1 5 | ae51 6 | Mac address 7 | 00:00:00:80:1e:00 8 | ethernet 6/1 9 | test.system.new 10 | 11 | 12 | -------------------------------------------------------------------------------- /javadoc/script.js: -------------------------------------------------------------------------------- 1 | function show(type) 2 | { 3 | count = 0; 4 | for (var key in methods) { 5 | var row = document.getElementById(key); 6 | if ((methods[key] & type) != 0) { 7 | row.style.display = ''; 8 | row.className = (count++ % 2) ? rowColor : altColor; 9 | } 10 | else 11 | row.style.display = 'none'; 12 | } 13 | updateTabs(type); 14 | } 15 | 16 | function updateTabs(type) 17 | { 18 | for (var value in tabs) { 19 | var sNode = document.getElementById(tabs[value][0]); 20 | var spanNode = sNode.firstChild; 21 | if (value == type) { 22 | sNode.className = activeTableTab; 23 | spanNode.innerHTML = tabs[value][1]; 24 | } 25 | else { 26 | sNode.className = tableTab; 27 | spanNode.innerHTML = "" + tabs[value][1] + ""; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/juniper/netconf/NetconfException.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 Juniper Networks, Inc. 3 | All Rights Reserved 4 | 5 | Use is subject to license terms. 6 | 7 | */ 8 | 9 | package net.juniper.netconf; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * Describes exceptions related to establishing Netconf session. 15 | */ 16 | public class NetconfException extends IOException { 17 | /** 18 | * Constructs a {@code NetconfException} with the specified detail message. 19 | * 20 | * @param msg the detail message that describes the exception 21 | */ 22 | public NetconfException(String msg) { 23 | super(msg); 24 | } 25 | 26 | /** 27 | * Constructs a {@code NetconfException} with the specified detail message 28 | * and underlying cause. 29 | * 30 | * @param msg the detail message 31 | * @param t the throwable that caused this exception 32 | */ 33 | public NetconfException(String msg, Throwable t) { 34 | super(msg, t); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /examples/ShowChassis.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Juniper Networks, Inc. 3 | * All Rights Reserved 4 | * 5 | * Use is subject to license terms. 6 | * 7 | */ 8 | 9 | import net.juniper.netconf.Device; 10 | import net.juniper.netconf.XML; 11 | import org.xml.sax.SAXException; 12 | 13 | import java.io.IOException; 14 | 15 | public class ShowChassis { 16 | public static void main(String[] args) throws 17 | SAXException, IOException { 18 | 19 | Device device = CreateDevice.createDevice(); 20 | device.connect(); 21 | 22 | //Send RPC and receive RPC Reply as XML 23 | XML rpc_reply = device.executeRPC("get-chassis-inventory"); 24 | /* OR 25 | * device.executeRPC(""); 26 | * OR 27 | * device.executeRPC(""); 28 | */ 29 | 30 | //Print the RPC-Reply and close the device. 31 | System.out.println(rpc_reply.toString()); 32 | device.close(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | 6 | name: Java CI (Maven & Gradle) 7 | 8 | on: 9 | push: 10 | branches: [ "master" ] 11 | pull_request: 12 | branches: [ "master" ] 13 | 14 | jobs: 15 | build: 16 | runs-on: ubuntu-latest 17 | 18 | # Runs both Maven and Gradle builds to keep both build scripts healthy 19 | strategy: 20 | matrix: 21 | build-tool: [maven, gradle] 22 | 23 | steps: 24 | - uses: actions/checkout@v4 25 | 26 | - name: Set up JDK 17 27 | uses: actions/setup-java@v4 28 | with: 29 | java-version: '17' 30 | distribution: 'temurin' 31 | cache: ${{ matrix.build-tool }} 32 | 33 | - name: Build with Maven 34 | if: matrix.build-tool == 'maven' 35 | run: mvn -B package --file pom.xml 36 | 37 | - name: Build with Gradle 38 | if: matrix.build-tool == 'gradle' 39 | run: ./gradlew --no-daemon clean build 40 | -------------------------------------------------------------------------------- /javadoc/stylesheet.css: -------------------------------------------------------------------------------- 1 | /* Javadoc style sheet */ 2 | 3 | /* Define colors, fonts and other style attributes here to override the defaults */ 4 | 5 | /* Page background color */ 6 | body { background-color: #FFFFFF } 7 | 8 | /* Headings */ 9 | h1 { font-size: 145% } 10 | 11 | /* Table colors */ 12 | .TableHeadingColor { background: #CCCCFF } /* Dark mauve */ 13 | .TableSubHeadingColor { background: #EEEEFF } /* Light mauve */ 14 | .TableRowColor { background: #FFFFFF } /* White */ 15 | 16 | /* Font used in left-hand frame lists */ 17 | .FrameTitleFont { font-size: 100%; font-family: Helvetica, Arial, sans-serif } 18 | .FrameHeadingFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif } 19 | .FrameItemFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif } 20 | 21 | /* Navigation bar fonts and colors */ 22 | .NavBarCell1 { background-color:#EEEEFF;} /* Light mauve */ 23 | .NavBarCell1Rev { background-color:#00008B;} /* Dark Blue */ 24 | .NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;} 25 | .NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;} 26 | 27 | .NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} 28 | .NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} 29 | 30 | -------------------------------------------------------------------------------- /src/test/java/net/juniper/netconf/TestConstants.java: -------------------------------------------------------------------------------- 1 | package net.juniper.netconf; 2 | 3 | /** 4 | * Central location for NETCONF protocol constants used across the library. 5 | *

6 | * The values defined here correspond to RFC 6241 (base 1.0) and related drafts 7 | * so that all modules reference a single, canonical source of truth rather than 8 | * scattering string literals throughout the codebase. 9 | *

10 | * This class is a simple constant holder and is therefore marked {@code final} 11 | * and given a private constructor to prevent instantiation. 12 | */ 13 | public class TestConstants { 14 | 15 | public static final String CORRECT_HELLO = "\n" + 16 | "\n" + 17 | "urn:ietf:params:netconf:base:1.0\n" + 18 | "urn:ietf:params:netconf:base:1.0#candidate\n" + 19 | "urn:ietf:params:netconf:base:1.0#confirmed-commit\n" + 20 | "urn:ietf:params:netconf:base:1.0#validate\n" + 21 | "urn:ietf:params:netconf:base:1.0#url?protocol=http,ftp,file\n" + 22 | "\n" + 23 | ""; 24 | public static final String LLDP_REQUEST = ""; 25 | } 26 | -------------------------------------------------------------------------------- /javadoc/allclasses-noframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | All Classes (netconf-java 2.0.0 API) 8 | 9 | 10 | 11 | 12 | 13 |

All Classes

14 |
15 | 24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /src/test/java/net/juniper/netconf/element/DatastoreTest.java: -------------------------------------------------------------------------------- 1 | package net.juniper.netconf.element; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | class DatastoreTest { 8 | 9 | @Test 10 | void testToStringReturnsLowercaseName() { 11 | assertEquals("running", Datastore.RUNNING.toString()); 12 | assertEquals("candidate", Datastore.CANDIDATE.toString()); 13 | assertEquals("startup", Datastore.STARTUP.toString()); 14 | assertEquals("intended", Datastore.INTENDED.toString()); 15 | assertEquals("operational", Datastore.OPERATIONAL.toString()); 16 | } 17 | 18 | @Test 19 | void testFromXmlNameIsCaseInsensitive() { 20 | assertEquals(Datastore.RUNNING, Datastore.fromXmlName("RUNNING")); 21 | assertEquals(Datastore.STARTUP, Datastore.fromXmlName("Startup")); 22 | assertEquals(Datastore.OPERATIONAL, Datastore.fromXmlName("operational")); 23 | } 24 | 25 | @Test 26 | void testFromXmlNameThrowsOnUnknown() { 27 | Exception ex = assertThrows(IllegalArgumentException.class, () -> { 28 | Datastore.fromXmlName("bogus"); 29 | }); 30 | assertTrue(ex.getMessage().contains("Unknown Datastore XML name")); 31 | } 32 | 33 | @Test 34 | void testFromXmlNameThrowsOnNull() { 35 | Exception ex = assertThrows(IllegalArgumentException.class, () -> { 36 | Datastore.fromXmlName(null); 37 | }); 38 | assertTrue(ex.getMessage().contains("cannot be null")); 39 | } 40 | } -------------------------------------------------------------------------------- /src/main/java/net/juniper/netconf/LoadException.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 Juniper Networks, Inc. 3 | All Rights Reserved 4 | 5 | Use is subject to license terms. 6 | */ 7 | 8 | package net.juniper.netconf; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * Exception thrown when a load RPC returns <rpc-error> or otherwise 14 | * fails to complete successfully. 15 | * 16 | *

Three convenient constructors are provided so callers can supply: 17 | *

    18 | *
  1. a human‑readable message only,
  2. 19 | *
  3. a message and root cause, or
  4. 20 | *
  5. just the root cause.
  6. 21 | *
22 | */ 23 | public class LoadException extends IOException { 24 | 25 | /** 26 | * Creates a {@code LoadException} with the supplied message. 27 | * 28 | * @param message description of the load failure 29 | */ 30 | public LoadException(String message) { 31 | super(message); 32 | } 33 | 34 | /** 35 | * Creates a {@code LoadException} with a message and a root cause. 36 | * 37 | * @param message description of the load failure 38 | * @param cause underlying exception that triggered the failure 39 | */ 40 | public LoadException(String message, Throwable cause) { 41 | super(message, cause); 42 | } 43 | 44 | /** 45 | * Creates a {@code LoadException} that wraps an underlying cause. 46 | * 47 | * @param cause underlying exception that triggered the failure 48 | */ 49 | public LoadException(Throwable cause) { 50 | super(cause); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | (BSD 2) 2 | 3 | Copyright © 2013, Juniper Networks 4 | 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | (1) Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | (2) Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation and/or 15 | other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 24 | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | The views and conclusions contained in the software and documentation are those 29 | of the authors and should not be interpreted as representing official policies, 30 | either expressed or implied, of Juniper Networks. 31 | -------------------------------------------------------------------------------- /examples/CreateDevice.java: -------------------------------------------------------------------------------- 1 | import net.juniper.netconf.Device; 2 | import net.juniper.netconf.NetconfException; 3 | 4 | class CreateDevice { 5 | 6 | private static final String HOSTNAME = "HOSTNAME"; 7 | private static final String USERNAME = "username"; 8 | private static final String PASSWORD = "passwd!"; 9 | private static final String PEM_KEY_FILE_PATH = "/tmp/pemFile"; 10 | 11 | 12 | /** 13 | * Create a new Device using username and password authentication. 14 | * 15 | * @return an unconnected Device object. 16 | * @throws NetconfException if there are issues creating the Device. 17 | */ 18 | public static Device createDevice() throws NetconfException { 19 | return Device.builder() 20 | .hostName(HOSTNAME) 21 | .userName(USERNAME) 22 | .password(PASSWORD) 23 | .strictHostKeyChecking(false) 24 | .build(); 25 | } 26 | 27 | /** 28 | * Create a new Device using username and public key file. 29 | * 30 | * @param keyFile the path to a private key file used to authenticate to the Device. 31 | * @return an unconnected Device object. 32 | * @throws NetconfException if there are issues creating the Device. 33 | */ 34 | public static Device createDeviceWithKeyAuth(String keyFile) throws NetconfException { 35 | return Device.builder() 36 | .hostName(HOSTNAME) 37 | .userName(USERNAME) 38 | .pemKeyFile(PEM_KEY_FILE_PATH) 39 | .strictHostKeyChecking(false) 40 | .build(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /javadoc/allclasses-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | All Classes (netconf-java 2.0.0 API) 8 | 9 | 10 | 11 | 12 | 13 |

All Classes

14 |
15 | 24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /src/test/java/net/juniper/netconf/integration/INTEGRATION_TESTS.md: -------------------------------------------------------------------------------- 1 | # NetConf Java Integration Tests 2 | 3 | This directory contains integration tests for the netconf-java library that test against real network devices. 4 | 5 | ## Overview 6 | 7 | The integration tests verify: 8 | - Basic device connection and authentication 9 | - Server capabilities retrieval 10 | - Configuration retrieval via get-config 11 | - Multiple sequential connections 12 | - Error handling and timeouts 13 | - Device-specific RPC operations 14 | 15 | ## Running the Tests 16 | 17 | ### Method 1: Using JUnit (Recommended) 18 | 19 | ```bash 20 | # Run with interactive prompts 21 | mvn test -Dtest=NetconfIntegrationTest -Dnetconf.integration.enabled=true 22 | 23 | # Run with predefined credentials 24 | mvn test -Dtest=NetconfIntegrationTest -Dnetconf.integration.enabled=true \ 25 | -Dnetconf.host=192.168.1.1 \ 26 | -Dnetconf.username=admin \ 27 | -Dnetconf.password=secret \ 28 | -Dnetconf.port=830 29 | ``` 30 | 31 | ### Method 2: Using the Shell Script 32 | 33 | ```bash 34 | # Make the script executable 35 | chmod +x run-integration-tests.sh 36 | 37 | # Run with interactive prompts 38 | ./run-integration-tests.sh 39 | 40 | # Run with command line arguments 41 | ./run-integration-tests.sh --host 192.168.1.1 --username admin --password secret 42 | ``` 43 | 44 | ### Method 3: Manual Test Runner 45 | 46 | For environments where JUnit is not available: 47 | 48 | ```bash 49 | # Compile the manual runner 50 | javac -cp "target/classes:target/dependency/*" src/test/java/net/juniper/netconf/integration/ManualTestRunner.java 51 | 52 | # Run the manual tests 53 | java -cp "target/classes:target/dependency/*:src/test/java" net.juniper.netconf.integration. -------------------------------------------------------------------------------- /javadoc/net/juniper/netconf/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | net.juniper.netconf (netconf-java 2.0.0 API) 8 | 9 | 10 | 11 | 12 | 13 |

net.juniper.netconf

14 |
15 |

Classes

16 | 22 |

Exceptions

23 | 28 |
29 | 30 | 31 | -------------------------------------------------------------------------------- /examples/parse_system_info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Juniper Networks, Inc. 3 | * All Rights Reserved 4 | * 5 | * Use is subject to license terms. 6 | * 7 | */ 8 | 9 | // Code to parse following rpc-reply 10 | /* 11 | * 12 | * abc 13 | * junos 14 | * 14.2I20 15 | * server 16 | * 17 | * 18 | */ 19 | 20 | 21 | import net.juniper.netconf.Device; 22 | import net.juniper.netconf.XML; 23 | import org.xml.sax.SAXException; 24 | 25 | import java.io.IOException; 26 | import java.util.Arrays; 27 | import java.util.List; 28 | 29 | public class parse_system_info { 30 | public static void main(String[] args) throws 31 | SAXException, IOException { 32 | 33 | Device device = CreateDevice.createDevice(); 34 | device.connect(); 35 | 36 | //Send RPC and receive RPC Reply as XML 37 | XML rpc_reply = device.executeRPC("get-system-information"); 38 | List list1 = Arrays.asList("system-information","hardware-model"); 39 | List list2 = Arrays.asList("system-information","os-name"); 40 | List list3 = Arrays.asList("system-information","os-version"); 41 | List list4 = Arrays.asList("system-information","host-name"); 42 | 43 | String val1= rpc_reply.findValue(list1); 44 | String val2= rpc_reply.findValue(list2); 45 | String val3= rpc_reply.findValue(list3); 46 | String val4= rpc_reply.findValue(list4); 47 | 48 | System.out.println(val1); 49 | System.out.println(val2); 50 | System.out.println(val3); 51 | System.out.println(val4); 52 | 53 | device.close(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /examples/parse_interface_info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Juniper Networks, Inc. 3 | * All Rights Reserved 4 | * 5 | * Use is subject to license terms. 6 | * 7 | */ 8 | 9 | //code to parse layered rpc reply 10 | 11 | import net.juniper.netconf.Device; 12 | import net.juniper.netconf.XML; 13 | import org.w3c.dom.Node; 14 | import org.w3c.dom.NodeList; 15 | import org.xml.sax.SAXException; 16 | 17 | import java.io.IOException; 18 | import java.util.Arrays; 19 | import java.util.List; 20 | 21 | public class parse_interface_info { 22 | public static void main(String[] args) throws IOException, 23 | SAXException { 24 | 25 | Device device = CreateDevice.createDevice(); 26 | device.connect(); 27 | 28 | XML rpc_reply = device.executeRPC("get-interface-information"); 29 | System.out.println(rpc_reply.toString()); 30 | // Obtain a list of list of ‘org.w3c.dom.Node’ objects 31 | List list = Arrays.asList("interface-information","physical-interface"); 32 | List physical_interfaces_list = rpc_reply.findNodes(list); 33 | // Print the value for each of the name elements: 34 | for (Object o : physical_interfaces_list) { 35 | Node node = (Node) o; 36 | NodeList child_nodes_of_phy_interface = node.getChildNodes(); 37 | // child_nodes_of_phy_interface contains nodes like and 38 | // Get each node from the NodeList 39 | for (int i = 0; i < child_nodes_of_phy_interface.getLength(); i++) { 40 | Node child_node = child_nodes_of_phy_interface.item(i); 41 | if (child_node.getNodeType() != Node.ELEMENT_NODE) { 42 | continue; 43 | } 44 | if (child_node.getNodeName().equals("name")) { // Print the text value of the node 45 | System.out.println(child_node.getTextContent()); 46 | } 47 | break; 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /examples/EditConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Juniper Networks, Inc. 3 | * All Rights Reserved 4 | * 5 | * Use is subject to license terms. 6 | * 7 | */ 8 | 9 | import net.juniper.netconf.CommitException; 10 | import net.juniper.netconf.Device; 11 | import net.juniper.netconf.LoadException; 12 | import net.juniper.netconf.XML; 13 | import net.juniper.netconf.XMLBuilder; 14 | import org.xml.sax.SAXException; 15 | 16 | import javax.xml.parsers.ParserConfigurationException; 17 | import java.io.IOException; 18 | 19 | 20 | public class EditConfiguration { 21 | public static void main(String[] args) throws IOException, 22 | ParserConfigurationException, SAXException { 23 | 24 | 25 | /*Build the XML configuration 26 | *The XML configuration required is: 27 | * 28 | * 29 | * 30 | * 31 | * 32 | * 33 | * 34 | * 35 | */ 36 | XMLBuilder builder = new XMLBuilder(); 37 | XML ftp_config = builder.createNewConfig("system", "services", "ftp"); 38 | 39 | Device device = CreateDevice.createDevice(); 40 | device.connect(); 41 | 42 | //Lock the configuration first 43 | boolean isLocked = device.lockConfig(); 44 | if(!isLocked) { 45 | System.out.println("Could not lock configuration. Exit now."); 46 | return; 47 | } 48 | 49 | //Load and commit the configuration 50 | try { 51 | device.loadXMLConfiguration(ftp_config.toString(), "merge"); 52 | device.commit(); 53 | } catch(LoadException | CommitException e) { 54 | System.out.println(e.getMessage()); 55 | return; 56 | } 57 | 58 | //Unlock the configuration and close the device. 59 | device.unlockConfig(); 60 | device.close(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/net/juniper/netconf/element/Datastore.java: -------------------------------------------------------------------------------- 1 | package net.juniper.netconf.element; 2 | 3 | import java.util.Locale; 4 | 5 | /** 6 | * Datastore 7 | *

8 | * As defined by RFC-8342. 9 | * See ... 10 | */ 11 | public enum Datastore { 12 | /** 13 | * The running configuration datastore as defined by RFC-8342. 14 | */ 15 | RUNNING("running"), 16 | /** 17 | * The candidate configuration datastore as defined by RFC-8342. 18 | */ 19 | CANDIDATE("candidate"), 20 | /** 21 | * The startup configuration datastore as defined by RFC-8342. 22 | */ 23 | STARTUP("startup"), 24 | /** 25 | * The intended configuration datastore as defined by RFC-8342. 26 | */ 27 | INTENDED("intended"), 28 | /** 29 | * The operational state datastore as defined by RFC-8342. 30 | */ 31 | OPERATIONAL("operational"); 32 | 33 | private final String xmlName; 34 | 35 | Datastore(String xmlName) { 36 | this.xmlName = xmlName.toLowerCase(Locale.US); 37 | } 38 | 39 | /** 40 | * Returns the XML name (lowercase) for this datastore. 41 | */ 42 | @Override 43 | public String toString() { 44 | return xmlName; 45 | } 46 | 47 | /** 48 | * Returns the Datastore enum constant corresponding to the given XML name (case-insensitive). 49 | * @param name the XML name to lookup 50 | * @return the Datastore enum constant 51 | * @throws IllegalArgumentException if no matching constant exists 52 | */ 53 | public static Datastore fromXmlName(String name) { 54 | if (name == null) { 55 | throw new IllegalArgumentException("Datastore XML name cannot be null"); 56 | } 57 | String nameLc = name.toLowerCase(Locale.US); 58 | for (Datastore ds : values()) { 59 | if (ds.xmlName.equals(nameLc)) { 60 | return ds; 61 | } 62 | } 63 | throw new IllegalArgumentException("Unknown Datastore XML name: " + name); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/net/juniper/netconf/integration/RUN-CRPD-CONTAINER.md: -------------------------------------------------------------------------------- 1 | # Running Juniper cRPD for integration tests 2 | 3 | This project’s integration tests need a live NETCONF endpoint. 4 | You can spin up Juniper’s containerised Routing Protocol Daemon (**cRPD**) locally in < 1 minute. 5 | 6 | --- 7 | 8 | ## 1 . Prerequisites 9 | 10 | * **Docker + Colima** (or Docker Desktop) on macOS 11 | ```bash 12 | brew install colima docker docker-compose 13 | colima start # arm64 by default; add --arch x86_64 if you need an amd64 VM 14 | ``` 15 | 16 | * **cRPD image** (free evaluation tarball from Juniper) 17 | Place it under `src/test/resources/` as shown below. 18 | 19 | --- 20 | 21 | ## 2 . Load the image into Docker 22 | 23 | ```bash 24 | docker load < src/test/resources/junos-routing-crpd-docker-23.2R1.13-arm64.tgz 25 | # or …-amd64… if you’re running a colima --arch x86_64 VM 26 | ``` 27 | 28 | Verify: 29 | 30 | ```bash 31 | docker images | grep crpd 32 | # crpd 23.2R1.13 0cf5ad… 498MB 33 | ``` 34 | 35 | --- 36 | 37 | ## 3 . Start cRPD with NETCONF and SSH exposed 38 | 39 | ```bash 40 | docker run -d --name crpd1 --privileged \ 41 | -p 2222:22 \ # SSH 42 | -p 1830:830 \ # NETCONF 43 | crpd:23.2R1.13 44 | ``` 45 | 46 | Wait ~40 s, then configure a test user and enable NETCONF: 47 | 48 | ```bash 49 | docker exec -ti crpd1 cli 50 | 51 | # inside Junos CLI 52 | configure 53 | set system root-authentication plain-text-password 54 | # (enter a password, e.g. Junos123) 55 | set system login user test uid 2000 class super-user 56 | set system login user test authentication plain-text-password 57 | # (password: test1234) 58 | 59 | set system services ssh 60 | set system services netconf ssh 61 | commit and-quit 62 | ``` 63 | 64 | --- 65 | 66 | ## 4 . Run the integration test wrapper 67 | 68 | ```bash 69 | ./src/test/java/net/juniper/netconf/integration/run-integration-tests.sh \ 70 | --username test \ 71 | --password test1234 \ 72 | --host localhost \ 73 | --port 1830 74 | ``` 75 | 76 | The script builds the library, spins up JUnit tests, and targets the NETCONF service you just started. 77 | 78 | --- 79 | 80 | ### Cleaning up 81 | 82 | ```bash 83 | docker rm -f crpd1 # stop & remove the container 84 | ``` 85 | 86 | That’s it! You now have a repeatable way to launch a Junos device for automated NETCONF testing. -------------------------------------------------------------------------------- /src/main/java/net/juniper/netconf/NetconfConstants.java: -------------------------------------------------------------------------------- 1 | package net.juniper.netconf; 2 | 3 | /** 4 | * Centralised collection of string literals and protocol constants used 5 | * throughout the NETCONF client library. 6 | *

7 | * The class is {@code final} and has a private constructor – it cannot be 8 | * instantiated or extended. All members are {@code public static final} 9 | * to encourage direct use without additional indirection. 10 | *

11 | * 12 | * @author Jonas Glass 13 | */ 14 | public class NetconfConstants { 15 | 16 | /* ------------------------------------------------------------------ 17 | * Framing protocol 18 | * ------------------------------------------------------------------ */ 19 | 20 | /** 21 | * Device prompt used by the NETCONF chunked framing protocol. 22 | * 23 | * @see RFC 6242 §4.1 24 | */ 25 | public static final String DEVICE_PROMPT = "]]>]]>"; 26 | 27 | /* ------------------------------------------------------------------ 28 | * XML preamble & namespaces 29 | * ------------------------------------------------------------------ */ 30 | 31 | /** 32 | * XML declaration emitted at the top of NETCONF messages. 33 | */ 34 | public static final String XML_VERSION = ""; 35 | 36 | /** 37 | * XML namespace for NETCONF Base 1.0 38 | * 39 | * @see RFC 6241 §8.1 40 | */ 41 | public static final String URN_XML_NS_NETCONF_BASE_1_0 = "urn:ietf:params:xml:ns:netconf:base:1.0"; 42 | 43 | /** 44 | * URI form of the NETCONF Base 1.0 capability identifier. 45 | * 46 | * @see RFC 6241 §8.1 47 | */ 48 | public static final String URN_IETF_PARAMS_NETCONF_BASE_1_0 = "urn:ietf:params:netconf:base:1.0"; 49 | 50 | /* ------------------------------------------------------------------ 51 | * Misc helpers 52 | * ------------------------------------------------------------------ */ 53 | 54 | /** Empty line helper constant. */ 55 | public static final String EMPTY_LINE = ""; 56 | 57 | /** Line feed (Unix‑style newline). */ 58 | public static final String LF = "\n"; 59 | 60 | /** Carriage return (use with {@code LF} for CRLF sequences). */ 61 | public static final String CR = "\r"; 62 | 63 | /** UTF‑8 charset literal used throughout the library. */ 64 | public static final String CHARSET_UTF8 = "utf-8"; 65 | 66 | /** 67 | * Not instantiable – utility holder only. 68 | */ 69 | private NetconfConstants() { /* no‑op */ } 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/net/juniper/netconf/element/RpcErrorTest.java: -------------------------------------------------------------------------------- 1 | package net.juniper.netconf.element; 2 | 3 | import net.juniper.netconf.element.RpcError.ErrorSeverity; 4 | import net.juniper.netconf.element.RpcError.ErrorTag; 5 | import net.juniper.netconf.element.RpcError.ErrorType; 6 | import net.juniper.netconf.element.RpcError.RpcErrorInfo; 7 | import org.junit.jupiter.api.Test; 8 | 9 | import static org.assertj.core.api.Assertions.*; 10 | 11 | /** 12 | * Unit tests for the {@link RpcError} record and its helper enums / builder. 13 | */ 14 | class RpcErrorTest { 15 | 16 | @Test 17 | void builderCreatesEquivalentRecord() { 18 | RpcErrorInfo info = RpcErrorInfo.builder() 19 | .badAttribute("attr") 20 | .sessionId("101") 21 | .build(); 22 | 23 | RpcError fromBuilder = RpcError.builder() 24 | .errorType(ErrorType.RPC) 25 | .errorTag(ErrorTag.INVALID_VALUE) 26 | .errorSeverity(ErrorSeverity.ERROR) 27 | .errorPath("/interfaces/interface[name='xe-0/0/0']") 28 | .errorMessage("invalid value") 29 | .errorMessageLanguage("en") 30 | .errorInfo(info) 31 | .build(); 32 | 33 | RpcError direct = new RpcError(ErrorType.RPC, 34 | ErrorTag.INVALID_VALUE, 35 | ErrorSeverity.ERROR, 36 | "/interfaces/interface[name='xe-0/0/0']", 37 | "invalid value", 38 | "en", 39 | info); 40 | 41 | assertThat(fromBuilder).isEqualTo(direct); 42 | assertThat(fromBuilder.hashCode()).isEqualTo(direct.hashCode()); 43 | } 44 | 45 | @Test 46 | void enumsRoundTripFromString() { 47 | assertThat(ErrorType.from("protocol")).isEqualTo(ErrorType.PROTOCOL); 48 | assertThat(ErrorTag.from("unknown-element")).isEqualTo(ErrorTag.UNKNOWN_ELEMENT); 49 | assertThat(ErrorSeverity.from("warning")).isEqualTo(ErrorSeverity.WARNING); 50 | 51 | // unknown returns null 52 | assertThat(ErrorTag.from("does-not-exist")).isNull(); 53 | } 54 | 55 | @Test 56 | void toStringContainsKeyFields() { 57 | RpcError error = RpcError.builder() 58 | .errorType(ErrorType.TRANSPORT) 59 | .errorTag(ErrorTag.LOCK_DENIED) 60 | .errorSeverity(ErrorSeverity.ERROR) 61 | .errorMessage("lock denied") 62 | .build(); 63 | 64 | String txt = error.toString(); 65 | assertThat(txt).contains("TRANSPORT") 66 | .contains("LOCK_DENIED") 67 | .contains("lock denied"); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /javadoc/overview-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Overview 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 |
22 |
25 | 26 | 27 | 28 | 62 | 63 |
All Classes 29 |

30 | 31 | Packages 32 |
33 | ch.ethz.ssh2 34 |
35 | ch.ethz.ssh2.auth 36 |
37 | ch.ethz.ssh2.channel 38 |
39 | ch.ethz.ssh2.crypto 40 |
41 | ch.ethz.ssh2.crypto.cipher 42 |
43 | ch.ethz.ssh2.crypto.dh 44 |
45 | ch.ethz.ssh2.crypto.digest 46 |
47 | ch.ethz.ssh2.log 48 |
49 | ch.ethz.ssh2.packets 50 |
51 | ch.ethz.ssh2.sftp 52 |
53 | ch.ethz.ssh2.signature 54 |
55 | ch.ethz.ssh2.transport 56 |
57 | ch.ethz.ssh2.util 58 |
59 | net.juniper.netconf 60 |
61 |

64 | 65 |

66 |   67 | 68 | 69 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ "master" ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ "master" ] 20 | schedule: 21 | - cron: '22 13 * * 3' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'java' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v3 42 | 43 | # Initializes the CodeQL tools for scanning. 44 | - name: Initialize CodeQL 45 | uses: github/codeql-action/init@v2 46 | with: 47 | languages: ${{ matrix.language }} 48 | # If you wish to specify custom queries, you can do so here or in a config file. 49 | # By default, queries listed here will override any specified in a config file. 50 | # Prefix the list here with "+" to use these queries and those in the config file. 51 | 52 | # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 53 | # queries: security-extended,security-and-quality 54 | 55 | 56 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 57 | # If this step fails, then you should remove it and run the build manually (see below) 58 | - name: Autobuild 59 | uses: github/codeql-action/autobuild@v2 60 | 61 | # ℹ️ Command-line programs to run using the OS shell. 62 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 63 | 64 | # If the Autobuild fails above, remove it and uncomment the following three lines. 65 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. 66 | 67 | # - run: | 68 | # echo "Run, Build Application using script" 69 | # ./location_of_script_within_repo/buildscript.sh 70 | 71 | - name: Perform CodeQL Analysis 72 | uses: github/codeql-action/analyze@v2 73 | -------------------------------------------------------------------------------- /javadoc/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | netconf-java 2.0.0 API 8 | 60 | 61 | 62 | 63 | 64 | 65 | <noscript> 66 | <div>JavaScript is disabled on your browser.</div> 67 | </noscript> 68 | <h2>Frame Alert</h2> 69 | <p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="net/juniper/netconf/package-summary.html">Non-frame version</a>.</p> 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /examples/snmp_config.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Juniper Networks, Inc. 3 | * All Rights Reserved 4 | * 5 | * Use is subject to license terms. 6 | * 7 | */ 8 | 9 | 10 | //code to load snmp configuration 11 | 12 | import net.juniper.netconf.CommitException; 13 | import net.juniper.netconf.Device; 14 | import net.juniper.netconf.LoadException; 15 | import net.juniper.netconf.XML; 16 | import net.juniper.netconf.XMLBuilder; 17 | import org.xml.sax.SAXException; 18 | 19 | import javax.xml.parsers.ParserConfigurationException; 20 | import java.io.IOException; 21 | 22 | 23 | /*Build the XML configuration. The XML configuration required is: 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | new-trap-receiver 41 | 42 | 43 | 44 | 45 | 162 46 | 47 | 10.0.0.1 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | XMLBuilder builder = new XMLBuilder(); 57 | XML ftp_config = builder.createNewConfig("system", "services", "ftp"); 58 | 59 | */ 60 | 61 | public class snmp_config { 62 | public static void main(String[] args) throws IOException, 63 | ParserConfigurationException, SAXException { 64 | 65 | XMLBuilder builder = new XMLBuilder(); 66 | XML trapGroupConfig = builder.createNewConfig("snmp"); 67 | XML trapGroup = trapGroupConfig.addPath("trap-group"); 68 | trapGroup.append("group-name", "new-trap-receiver"); 69 | XML categories = trapGroup.append("categories"); 70 | categories.append("chassis"); 71 | categories.append("link"); 72 | trapGroup.append("destination-port", "162"); 73 | XML targets = trapGroup.append("targets"); 74 | targets.append("name", "10.0.0.1"); 75 | 76 | Device device = CreateDevice.createDevice(); 77 | device.connect(); 78 | 79 | //Lock the configuration first 80 | boolean isLocked = device.lockConfig(); 81 | if (!isLocked) { 82 | System.out.println("Could not lock configuration. Exit now."); 83 | return; 84 | } 85 | 86 | //Load and commit the configuration 87 | try { 88 | device.loadXMLConfiguration(trapGroupConfig.toString(), "merge"); 89 | device.commit(); 90 | } catch (LoadException | CommitException e) { 91 | System.out.println(e.getMessage()); 92 | return; 93 | } 94 | 95 | //Unlock the configuration and close the device. 96 | device.unlockConfig(); 97 | device.close(); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH= 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /src/test/java/net/juniper/netconf/integration/run-integration-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # run-integration-tests.sh 4 | # Script to run netconf-java integration tests with interactive credential prompts 5 | 6 | set -e 7 | 8 | echo "=== NetConf Java Integration Test Runner ===" 9 | echo "This script will run integration tests against a real network device." 10 | echo "You will be prompted for connection details if not provided via environment." 11 | echo "" 12 | 13 | # Check if Maven is available 14 | if ! command -v mvn &> /dev/null; then 15 | echo "Error: Maven is not installed or not in PATH" 16 | exit 1 17 | fi 18 | 19 | # Parse command line arguments 20 | INTERACTIVE=true 21 | SKIP_COMPILE=false 22 | 23 | while [[ $# -gt 0 ]]; do 24 | case $1 in 25 | --host) 26 | NETCONF_HOST="$2" 27 | shift 2 28 | ;; 29 | --username) 30 | NETCONF_USERNAME="$2" 31 | shift 2 32 | ;; 33 | --password) 34 | NETCONF_PASSWORD="$2" 35 | shift 2 36 | ;; 37 | --port) 38 | NETCONF_PORT="$2" 39 | shift 2 40 | ;; 41 | --timeout) 42 | NETCONF_TIMEOUT="$2" 43 | shift 2 44 | ;; 45 | --skip-compile) 46 | SKIP_COMPILE=true 47 | shift 48 | ;; 49 | --help|-h) 50 | echo "Usage: $0 [options]" 51 | echo "Options:" 52 | echo " --host Device hostname or IP address" 53 | echo " --username SSH username" 54 | echo " --password SSH password" 55 | echo " --port NETCONF port (default: 830)" 56 | echo " --timeout Connection timeout in milliseconds (default: 30000)" 57 | echo " --skip-compile Skip Maven compile phase" 58 | echo " --help, -h Show this help message" 59 | echo "" 60 | echo "Environment variables can also be used:" 61 | echo " NETCONF_HOST, NETCONF_USERNAME, NETCONF_PASSWORD, NETCONF_PORT, NETCONF_TIMEOUT" 62 | exit 0 63 | ;; 64 | *) 65 | echo "Unknown option: $1" 66 | echo "Use --help for usage information" 67 | exit 1 68 | ;; 69 | esac 70 | done 71 | 72 | # Set defaults from environment if not provided via command line 73 | NETCONF_HOST=${NETCONF_HOST:-$NETCONF_HOST} 74 | NETCONF_USERNAME=${NETCONF_USERNAME:-$NETCONF_USERNAME} 75 | NETCONF_PASSWORD=${NETCONF_PASSWORD:-$NETCONF_PASSWORD} 76 | NETCONF_PORT=${NETCONF_PORT:-830} 77 | NETCONF_TIMEOUT=${NETCONF_TIMEOUT:-30000} 78 | 79 | # Compile the project first (unless skipped) 80 | if [ "$SKIP_COMPILE" = false ]; then 81 | echo "Compiling project..." 82 | mvn compile test-compile -q 83 | if [ $? -ne 0 ]; then 84 | echo "Error: Failed to compile project" 85 | exit 1 86 | fi 87 | echo "✓ Project compiled successfully" 88 | echo "" 89 | fi 90 | 91 | # Build Maven command 92 | MVN_CMD="mvn test -Dtest=NetconfIntegrationTest -Dnetconf.integration.enabled=true" 93 | 94 | # Add system properties if provided 95 | if [ -n "$NETCONF_HOST" ]; then 96 | MVN_CMD="$MVN_CMD -Dnetconf.host=$NETCONF_HOST" 97 | fi 98 | 99 | if [ -n "$NETCONF_USERNAME" ]; then 100 | MVN_CMD="$MVN_CMD -Dnetconf.username=$NETCONF_USERNAME" 101 | fi 102 | 103 | if [ -n "$NETCONF_PASSWORD" ]; then 104 | MVN_CMD="$MVN_CMD -Dnetconf.password=$NETCONF_PASSWORD" 105 | fi 106 | 107 | if [ -n "$NETCONF_PORT" ]; then 108 | MVN_CMD="$MVN_CMD -Dnetconf.port=$NETCONF_PORT" 109 | fi 110 | 111 | if [ -n "$NETCONF_TIMEOUT" ]; then 112 | MVN_CMD="$MVN_CMD -Dnetconf.timeout=$NETCONF_TIMEOUT" 113 | fi 114 | 115 | echo "Running integration tests..." 116 | echo "Command: $MVN_CMD" 117 | echo "" 118 | 119 | # Execute the tests 120 | eval $MVN_CMD 121 | 122 | echo "" 123 | echo "=== Integration Tests Complete ===" -------------------------------------------------------------------------------- /javadoc/deprecated-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Deprecated List (netconf-java 2.0.0 API) 8 | 9 | 10 | 11 | 12 | 13 | 23 |

JavaScript is disabled on your browser.
25 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 42 |
43 | 70 | 71 |
72 |

Deprecated API

73 |

Contents

74 |
75 | 76 |
77 | 78 | 79 | 80 | 81 | 82 | 83 | 91 |
92 | 119 | 120 |

Copyright 2018, Juniper Networks, Inc.

121 | 122 | 123 | -------------------------------------------------------------------------------- /src/test/java/net/juniper/netconf/XMLBuilderTest.java: -------------------------------------------------------------------------------- 1 | package net.juniper.netconf; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import static org.assertj.core.api.Assertions.assertThat; 5 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 6 | 7 | import java.util.Arrays; 8 | import java.util.Collections; 9 | 10 | public class XMLBuilderTest { 11 | 12 | @Test 13 | public void createNewConfig_twoElements_createsExpectedXML() throws Exception { 14 | XMLBuilder builder = new XMLBuilder(); 15 | XML xml = builder.createNewConfig("system", "services"); 16 | assertThat(xml.toString()) 17 | .containsIgnoringWhitespaces( 18 | ""); 19 | } 20 | 21 | @Test 22 | public void createNewConfig_oneElement_createsExpectedXML() throws Exception { 23 | XMLBuilder builder = new XMLBuilder(); 24 | XML xml = builder.createNewConfig("system"); 25 | assertThat(xml.toString()).containsIgnoringWhitespaces(""); 26 | } 27 | 28 | @Test 29 | public void createNewConfig_threeElements_createsExpectedXML() throws Exception { 30 | XMLBuilder builder = new XMLBuilder(); 31 | XML xml = builder.createNewConfig("system", "services", "ftp"); 32 | assertThat(xml.toString()).containsIgnoringWhitespaces(""); 33 | } 34 | 35 | @Test 36 | public void createNewConfig_list_createsExpectedXML() throws Exception { 37 | XMLBuilder builder = new XMLBuilder(); 38 | XML xml = builder.createNewConfig(Arrays.asList("system", "services", "ftp")); 39 | assertThat(xml.toString()).containsIgnoringWhitespaces(""); 40 | } 41 | 42 | @Test 43 | public void createNewConfig_emptyList_returnsNull() throws Exception { 44 | XMLBuilder builder = new XMLBuilder(); 45 | XML xml = builder.createNewConfig(Collections.emptyList()); 46 | assertThat(xml).isNull(); 47 | } 48 | 49 | @Test 50 | public void createNewRPC_twoElements_createsExpectedXML() throws Exception { 51 | XMLBuilder builder = new XMLBuilder(); 52 | XML xml = builder.createNewRPC("get-interface-information", "terse"); 53 | String xmlStr = xml.toString(); 54 | 55 | // Verify opening tag has message‑id and correct namespace (order irrelevant) 56 | assertThat(xmlStr) 57 | .matches("(?s).*]*message-id=\"\\d+\"[^>]*xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"[^>]*>.*"); 58 | 59 | // Verify payload hierarchy, ignoring whitespace/line breaks 60 | assertThat(xmlStr) 61 | .containsIgnoringWhitespaces(""); 62 | } 63 | 64 | @Test 65 | public void createNewXML_fourElements_createsExpectedXML() throws Exception { 66 | XMLBuilder builder = new XMLBuilder(); 67 | XML xml = builder.createNewXML("top", "middle", "sub", "leaf"); 68 | assertThat(xml.toString()).containsIgnoringWhitespaces(""); 69 | } 70 | 71 | @Test 72 | public void createNewXML_list_createsExpectedXML() throws Exception { 73 | XMLBuilder builder = new XMLBuilder(); 74 | XML xml = builder.createNewXML(Arrays.asList("a", "b", "c")); 75 | assertThat(xml.toString()).containsIgnoringWhitespaces(""); 76 | } 77 | 78 | @Test 79 | public void createNewXML_emptyList_returnsNull() throws Exception { 80 | XMLBuilder builder = new XMLBuilder(); 81 | XML xml = builder.createNewXML(Collections.emptyList()); 82 | assertThat(xml).isNull(); 83 | } 84 | 85 | @Test 86 | public void createNewRPC_autoAddsMessageIdAndNamespace() throws Exception { 87 | XMLBuilder builder = new XMLBuilder(); 88 | XML xml = builder.createNewRPC("get", "running"); 89 | String xmlStr = xml.toString(); 90 | 91 | // Assert the rpc element has a message-id attribute with a numeric value 92 | assertThat(xmlStr) 93 | .contains("message-id=\"") 94 | .matches("(?s).*]*message-id=\"\\d+\"[^>]*xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"[^>]*>.*"); 95 | 96 | // Ensure hierarchy is intact 97 | assertThat(xmlStr) 98 | .containsIgnoringWhitespaces(""); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /javadoc/net/juniper/netconf/class-use/Device.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class net.juniper.netconf.Device (netconf-java 2.0.0 API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 42 |
43 | 70 | 71 |
72 |

Uses of Class
net.juniper.netconf.Device

73 |
74 |
No usage of net.juniper.netconf.Device
75 | 76 |
77 | 78 | 79 | 80 | 81 | 82 | 83 | 91 |
92 | 119 | 120 |

Copyright 2018, Juniper Networks, Inc.

121 | 122 | 123 | -------------------------------------------------------------------------------- /javadoc/net/juniper/netconf/class-use/XMLBuilder.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class net.juniper.netconf.XMLBuilder (netconf-java 2.0.0 API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 42 |
43 | 70 | 71 |
72 |

Uses of Class
net.juniper.netconf.XMLBuilder

73 |
74 |
No usage of net.juniper.netconf.XMLBuilder
75 | 76 |
77 | 78 | 79 | 80 | 81 | 82 | 83 | 91 |
92 | 119 | 120 |

Copyright 2018, Juniper Networks, Inc.

121 | 122 | 123 | -------------------------------------------------------------------------------- /javadoc/net/juniper/netconf/class-use/LoadException.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class net.juniper.netconf.LoadException (netconf-java 2.0.0 API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 42 |
43 | 70 | 71 |
72 |

Uses of Class
net.juniper.netconf.LoadException

73 |
74 |
No usage of net.juniper.netconf.LoadException
75 | 76 |
77 | 78 | 79 | 80 | 81 | 82 | 83 | 91 |
92 | 119 | 120 |

Copyright 2018, Juniper Networks, Inc.

121 | 122 | 123 | -------------------------------------------------------------------------------- /.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | 10 | https://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an 14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, either express or implied. See the License for the 16 | specific language governing permissions and limitations 17 | under the License. 18 | */ 19 | 20 | import java.io.File; 21 | import java.io.FileInputStream; 22 | import java.io.FileOutputStream; 23 | import java.io.IOException; 24 | import java.net.URL; 25 | import java.nio.channels.Channels; 26 | import java.nio.channels.ReadableByteChannel; 27 | import java.util.Properties; 28 | 29 | public class MavenWrapperDownloader { 30 | 31 | /** 32 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 33 | */ 34 | private static final String DEFAULT_DOWNLOAD_URL = 35 | "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; 36 | 37 | /** 38 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 39 | * use instead of the default one. 40 | */ 41 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 42 | ".mvn/wrapper/maven-wrapper.properties"; 43 | 44 | /** 45 | * Path where the maven-wrapper.jar will be saved to. 46 | */ 47 | private static final String MAVEN_WRAPPER_JAR_PATH = 48 | ".mvn/wrapper/maven-wrapper.jar"; 49 | 50 | /** 51 | * Name of the property which should be used to override the default download url for the wrapper. 52 | */ 53 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 54 | 55 | public static void main(String args[]) { 56 | System.out.println("- Downloader started"); 57 | File baseDirectory = new File(args[0]); 58 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 59 | 60 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 61 | // wrapperUrl parameter. 62 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 63 | String url = DEFAULT_DOWNLOAD_URL; 64 | if(mavenWrapperPropertyFile.exists()) { 65 | FileInputStream mavenWrapperPropertyFileInputStream = null; 66 | try { 67 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 68 | Properties mavenWrapperProperties = new Properties(); 69 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 70 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 71 | } catch (IOException e) { 72 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 73 | } finally { 74 | try { 75 | if(mavenWrapperPropertyFileInputStream != null) { 76 | mavenWrapperPropertyFileInputStream.close(); 77 | } 78 | } catch (IOException e) { 79 | // Ignore ... 80 | } 81 | } 82 | } 83 | System.out.println("- Downloading from: : " + url); 84 | 85 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 86 | if(!outputFile.getParentFile().exists()) { 87 | if(!outputFile.getParentFile().mkdirs()) { 88 | System.out.println( 89 | "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 90 | } 91 | } 92 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 93 | try { 94 | downloadFileFromURL(url, outputFile); 95 | System.out.println("Done"); 96 | System.exit(0); 97 | } catch (Throwable e) { 98 | System.out.println("- Error downloading"); 99 | e.printStackTrace(); 100 | System.exit(1); 101 | } 102 | } 103 | 104 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 105 | URL website = new URL(urlString); 106 | ReadableByteChannel rbc; 107 | rbc = Channels.newChannel(website.openStream()); 108 | FileOutputStream fos = new FileOutputStream(destination); 109 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 110 | fos.close(); 111 | rbc.close(); 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /javadoc/serialized-form.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Serialized Form (netconf-java 2.0.0 API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 42 |
43 | 70 | 71 |
72 |

Serialized Form

73 |
74 |
75 | 97 |
98 | 99 |
100 | 101 | 102 | 103 | 104 | 105 | 106 | 114 |
115 | 142 | 143 |

Copyright 2018, Juniper Networks, Inc.

144 | 145 | 146 | -------------------------------------------------------------------------------- /javadoc/net/juniper/netconf/package-use.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Package net.juniper.netconf (netconf-java 2.0.0 API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 42 |
43 | 70 | 71 |
72 |

Uses of Package
net.juniper.netconf

73 |
74 |
75 |
    76 |
  • 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 89 | 90 | 91 | 94 | 95 | 96 | 100 | 101 | 102 | 106 | 107 | 108 |
    Classes in net.juniper.netconf used by net.juniper.netconf 
    Class and Description
    CommitException 87 |
    Describes exceptions related to commit operation
    88 |
    NetconfException 92 |
    Describes exceptions related to establishing Netconf session.
    93 |
    NetconfSession 97 |
    A NetconfSession object is used to call the Netconf driver 98 | methods.
    99 |
    XML 103 |
    An XML object represents XML content and provides methods to 104 | manipulate it.
    105 |
    109 |
  • 110 |
111 |
112 | 113 |
114 | 115 | 116 | 117 | 118 | 119 | 120 | 128 |
129 | 156 | 157 |

Copyright 2018, Juniper Networks, Inc.

158 | 159 | 160 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | netconf-java 2 | ============ 3 | 4 | **A modernized Java library for NETCONF (now Java 17‑compatible)** 5 | 6 | Java library for NETCONF 7 | 8 | SUPPORT 9 | ======= 10 | 11 | This software is not officially supported by Juniper Networks, but by a team dedicated to helping customers, 12 | partners, and the development community. To report bug-fixes, issues, suggestions, please raise issues 13 | or even better submit pull requests on GitHub. 14 | 15 | REQUIREMENTS 16 | ============ 17 | 18 | * [OpenJDK 17](https://openjdk.org/projects/jdk/17/) or later 19 | * [Maven](https://maven.apache.org/download.cgi) if you want to build using `mvn` [Supported from v2.1.1]. 20 | * [Gradle 8+](https://gradle.org/releases/) if you prefer a Gradle build (`./gradlew build`) 21 | 22 | Building 23 | ======== 24 | You can build the project using **Maven** or **Gradle**. 25 | 26 | ### Maven 27 | ```bash 28 | mvn clean package 29 | ``` 30 | 31 | ### Gradle 32 | ```bash 33 | ./gradlew clean build 34 | ``` 35 | (The wrapper script downloads the correct Gradle version automatically.) 36 | 37 | Releases 38 | ======== 39 | Releases contain source code only. Due to changing JDK licensing, jar files are not released. 40 | User may download the source code and compile it with desired JDK version. 41 | 42 | * Instructions to build 43 | * Download Source Code for the required release 44 | * Compile the code and build the jar using your chosen JDK version 45 | * Use the jar file 46 | 47 | * Instructions to build using `mvn` 48 | * Download Source Code for the required release 49 | * Compile the code and build the jar using `mvn package` 50 | * Use the jar file from (source to netconf-java)/netconf-java/target 51 | * Use `mvn versions:display-dependency-updates` to identify possible target versions for dependencies 52 | 53 | ======= 54 | 55 | v2.2.0 56 | ------ 57 | * Java 17 baseline; compiled with `--release 17` 58 | * Gradle build added alongside Maven 59 | * SpotBugs upgraded to 6.x 60 | * Added **:confirmed-commit:1.1** support (`commitConfirm(timeout, persist)` and `cancelCommit(persistId)`) 61 | * Added **killSession(String)** helper for RFC 6241 §7.9 62 | * Auto‑inject base 1.1 capability in <hello> exchange 63 | * Gradle wrapper committed; GitHub Actions now builds Maven *and* Gradle 64 | * Expanded Javadoc and SpotBugs clean‑up 65 | 66 | v2.1.1 67 | ------ 68 | 69 | * Fixed `mvn` build issues 70 | 71 | v2.0.0 72 | ------ 73 | 74 | * Replaced the ssh library with [JSch](http://www.jcraft.com/jsch/) 75 | * Adds support for new ssh crypto algorithms 76 | * More modern ssh implementation 77 | * Added support for importing and building the library with maven 78 | * Added FindBugs code testing to maven build 79 | 80 | This is a breaking change to the API. New Device objects are now created using a builder. 81 | Example: 82 | 83 | ```Java 84 | Device device = Device.builder().hostName("hostname") 85 | .userName("username") 86 | .password("password") 87 | .connectionTimeout(2000) 88 | .hostKeysFileName("hostKeysFileName") 89 | .build(); 90 | ``` 91 | 92 | SYNOPSIS 93 | ======== 94 | 95 | ```Java 96 | import java.io.IOException; 97 | import javax.xml.parsers.ParserConfigurationException; 98 | import net.juniper.netconf.NetconfException; 99 | import org.xml.sax.SAXException; 100 | 101 | import net.juniper.netconf.XML; 102 | import net.juniper.netconf.Device; 103 | 104 | public class ShowInterfaces { 105 | public static void main(String args[]) throws NetconfException, 106 | ParserConfigurationException, SAXException, IOException { 107 | 108 | //Create device 109 | Device device = Device.builder() 110 | .hostName("hostname") 111 | .userName("username") 112 | .password("password") 113 | .connectionTimeout(2000) 114 | .hostKeysFileName("hostKeysFileName") 115 | .build(); 116 | device.connect(); 117 | 118 | //Send RPC and receive RPC Reply as XML 119 | XML rpc_reply = device.executeRPC("get-interface-information"); 120 | /* OR 121 | * device.executeRPC(""); 122 | * OR 123 | * device.executeRPC(""); 124 | */ 125 | 126 | //Print the RPC-Reply and close the device. 127 | System.out.println(rpc_reply); 128 | device.close(); 129 | } 130 | } 131 | ``` 132 | 133 | LICENSE 134 | ======= 135 | 136 | (BSD 2) 137 | 138 | Copyright © 2013, Juniper Networks 139 | 140 | All rights reserved. 141 | 142 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 143 | 144 | (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 145 | 146 | (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 147 | 148 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 149 | 150 | The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of Juniper Networks. 151 | 152 | AUTHOR 153 | ====== 154 | 155 | [Ankit Jain](http://www.linkedin.com/in/ankitj093), Juniper Networks 156 | [Peter J Hill](https://github.com/peterjhill), Oracle 157 | [Community Contributors](https://github.com/Juniper/netconf-java/graphs/contributors) 158 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( 125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | echo Found %WRAPPER_JAR% 132 | ) else ( 133 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 134 | echo Downloading from: %DOWNLOAD_URL% 135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" 136 | echo Finished downloading %WRAPPER_JAR% 137 | ) 138 | @REM End of extension 139 | 140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 141 | if ERRORLEVEL 1 goto error 142 | goto end 143 | 144 | :error 145 | set ERROR_CODE=1 146 | 147 | :end 148 | @endlocal & set ERROR_CODE=%ERROR_CODE% 149 | 150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 154 | :skipRcPost 155 | 156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 158 | 159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 160 | 161 | exit /B %ERROR_CODE% 162 | -------------------------------------------------------------------------------- /javadoc/overview-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Class Hierarchy (netconf-java 2.0.0 API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 42 |
43 | 70 | 71 |
72 |

Hierarchy For All Packages

73 | Package Hierarchies: 74 | 77 |
78 |
79 |

Class Hierarchy

80 | 105 |
106 | 107 |
108 | 109 | 110 | 111 | 112 | 113 | 114 | 122 |
123 | 150 | 151 |

Copyright 2018, Juniper Networks, Inc.

152 | 153 | 154 | -------------------------------------------------------------------------------- /javadoc/net/juniper/netconf/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | net.juniper.netconf Class Hierarchy (netconf-java 2.0.0 API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 42 |
43 | 70 | 71 |
72 |

Hierarchy For Package net.juniper.netconf

73 |
74 |
75 |

Class Hierarchy

76 | 101 |
102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 118 |
119 | 146 | 147 |

Copyright 2018, Juniper Networks, Inc.

148 | 149 | 150 | -------------------------------------------------------------------------------- /javadoc/net/juniper/netconf/class-use/NetconfSession.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class net.juniper.netconf.NetconfSession (netconf-java 2.0.0 API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 42 |
43 | 70 | 71 |
72 |

Uses of Class
net.juniper.netconf.NetconfSession

73 |
74 |
75 | 114 |
115 | 116 |
117 | 118 | 119 | 120 | 121 | 122 | 123 | 131 |
132 | 159 | 160 |

Copyright 2018, Juniper Networks, Inc.

161 | 162 | 163 | -------------------------------------------------------------------------------- /javadoc/net/juniper/netconf/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | net.juniper.netconf (netconf-java 2.0.0 API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 42 |
43 | 70 | 71 |
72 |

Package net.juniper.netconf

73 |
74 |
75 |
    76 |
  • 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 89 | 90 | 91 | 92 | 96 | 97 | 98 | 99 | 103 | 104 | 105 | 106 | 110 | 111 | 112 |
    Class Summary 
    ClassDescription
    Device 87 |
    A Device is used to define a Netconf server.
    88 |
    NetconfSession 93 |
    A NetconfSession object is used to call the Netconf driver 94 | methods.
    95 |
    XML 100 |
    An XML object represents XML content and provides methods to 101 | manipulate it.
    102 |
    XMLBuilder 107 |
    An XMLBuilder is used to create an XML object.This is useful to 108 | create XML RPC's and configurations.
    109 |
    113 |
  • 114 |
  • 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 127 | 128 | 129 | 130 | 133 | 134 | 135 | 136 | 139 | 140 | 141 |
    Exception Summary 
    ExceptionDescription
    CommitException 125 |
    Describes exceptions related to commit operation
    126 |
    LoadException 131 |
    Describes exceptions related to load operation
    132 |
    NetconfException 137 |
    Describes exceptions related to establishing Netconf session.
    138 |
    142 |
  • 143 |
144 |
145 | 146 |
147 | 148 | 149 | 150 | 151 | 152 | 153 | 161 |
162 | 189 | 190 |

Copyright 2018, Juniper Networks, Inc.

191 | 192 | 193 | -------------------------------------------------------------------------------- /javadoc/constant-values.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Constant Field Values (netconf-java 2.0.0 API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 42 |
43 | 70 | 71 |
72 |

Constant Field Values

73 |

Contents

74 | 77 |
78 |
79 | 80 | 81 |

net.juniper.*

82 | 143 |
144 | 145 |
146 | 147 | 148 | 149 | 150 | 151 | 152 | 160 |
161 | 188 | 189 |

Copyright 2018, Juniper Networks, Inc.

190 | 191 | 192 | -------------------------------------------------------------------------------- /javadoc/overview-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Overview 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 45 | 48 | 49 | 50 | 51 | 54 | 69 | 70 |
46 | 47 |
71 | 72 | 73 | 74 |
75 | 76 | 77 | 78 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 |
79 | Packages
ch.ethz.ssh2 
ch.ethz.ssh2.auth 
ch.ethz.ssh2.channel 
ch.ethz.ssh2.crypto 
ch.ethz.ssh2.crypto.cipher 
ch.ethz.ssh2.crypto.dh 
ch.ethz.ssh2.crypto.digest 
ch.ethz.ssh2.log 
ch.ethz.ssh2.packets 
ch.ethz.ssh2.sftp 
ch.ethz.ssh2.signature 
ch.ethz.ssh2.transport 
ch.ethz.ssh2.util 
net.juniper.netconf 
138 | 139 |

140 |  


141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 162 | 165 | 166 | 167 | 168 | 171 | 186 | 187 |
163 | 164 |
188 | 189 | 190 | 191 |
192 | 193 | 194 | 195 | -------------------------------------------------------------------------------- /javadoc/net/juniper/netconf/class-use/CommitException.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class net.juniper.netconf.CommitException (netconf-java 2.0.0 API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 42 |
43 | 70 | 71 |
72 |

Uses of Class
net.juniper.netconf.CommitException

73 |
74 |
75 |
    76 |
  • 77 |
      78 |
    • 79 | 80 | 81 |

      Uses of CommitException in net.juniper.netconf

      82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 94 | 95 | 96 | 97 | 100 | 101 | 102 | 103 | 106 | 107 | 108 | 109 | 113 | 114 | 115 | 116 | 121 | 122 | 123 |
      Methods in net.juniper.netconf that throw CommitException 
      Modifier and TypeMethod and Description
      voidDevice.commit() 92 |
      Commit the candidate configuration.
      93 |
      voidDevice.commitConfirm(long seconds) 98 |
      Commit the candidate configuration, temporarily.
      99 |
      voidNetconfSession.commitFull() 104 |
      Commit the candidate configuration and rebuild the config database.
      105 |
      voidDevice.commitFull() 110 |
      Commit full is an unsupported Juniper command that will commit the config and then signal all processes to 111 | check the configuration for changes.
      112 |
      voidDevice.commitThisConfiguration(String configFile, 117 | String loadType) 118 |
      Loads and commits the candidate configuration, Configuration can be in 119 | text/xml format.
      120 |
      124 |
    • 125 |
    126 |
  • 127 |
128 |
129 | 130 |
131 | 132 | 133 | 134 | 135 | 136 | 137 | 145 |
146 | 173 | 174 |

Copyright 2018, Juniper Networks, Inc.

175 | 176 | 177 | -------------------------------------------------------------------------------- /javadoc/help-doc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | API Help 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 44 | 47 | 48 | 49 | 50 | 53 | 68 | 69 |
45 | 46 |
70 | 71 | 72 | 73 |
74 |
75 |

76 | How This API Document Is Organized

77 |
78 | This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.

79 | Overview

80 |
81 | 82 |

83 | The Overview page is the front page of this API document and provides a list of all packages with a summary for each. This page can also contain an overall description of the set of packages.

84 |

85 | Package

86 |
87 | 88 |

89 | Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:

    90 |
  • Interfaces (italic)
  • Classes
  • Exceptions
  • Errors
91 |
92 |

93 | Class/Interface

94 |
95 | 96 |

97 | Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

    98 |
  • Class inheritance diagram
  • Direct Subclasses
  • All Known Subinterfaces
  • All Known Implementing Classes
  • Class/interface declaration
  • Class/interface description 99 |

    100 |

  • Nested Class Summary
  • Field Summary
  • Constructor Summary
  • Method Summary 101 |

    102 |

  • Field Detail
  • Constructor Detail
  • Method Detail
103 | Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
104 |

105 | Tree (Class Hierarchy)

106 |
107 | There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.
    108 |
  • When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
  • When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
109 |
110 |

111 | Deprecated API

112 |
113 | The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
114 |

115 | Index

116 |
117 | The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
118 |

119 | Prev/Next

120 | These links take you to the next or previous class, interface, package, or related page.

121 | Frames/No Frames

122 | These links show and hide the HTML frames. All pages are available with or without frames. 123 |

124 |

125 | Serialized Form

126 | Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description. 127 |

128 | 129 | 130 | This help file applies to API documentation generated using the standard doclet. 131 | 132 |
133 |


134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 155 | 158 | 159 | 160 | 161 | 164 | 179 | 180 |
156 | 157 |
181 | 182 | 183 | 184 |
185 | 186 | 187 | 188 | -------------------------------------------------------------------------------- /src/test/java/net/juniper/netconf/element/HelloTest.java: -------------------------------------------------------------------------------- 1 | package net.juniper.netconf.element; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.xmlunit.assertj.XmlAssert; 5 | 6 | import static org.assertj.core.api.Assertions.assertThat; 7 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 8 | 9 | import java.net.URI; 10 | import java.net.URISyntaxException; 11 | 12 | public class HelloTest { 13 | 14 | // Samples taken from https://www.juniper.net/documentation/us/en/software/junos/netconf/topics/concept/netconf-session-rfc-compliant.html 15 | public static final String HELLO_WITHOUT_NAMESPACE = """ 16 | \ 17 | 18 | 19 | urn:ietf:params:netconf:base:1.0 20 | urn:ietf:params:netconf:base:1.0#candidate 21 | urn:ietf:params:netconf:base:1.0#confirmed-commit 22 | urn:ietf:params:netconf:base:1.0#validate 23 | urn:ietf:params:netconf:base:1.0#url?protocol=http,ftp,file 24 | urn:ietf:params:netconf:base:1.1 25 | 26 | 27700 27 | """; 28 | 29 | public static final String HELLO_WITH_NAMESPACE = """ 30 | \ 31 | 32 | 33 | urn:ietf:params:netconf:base:1.0 34 | urn:ietf:params:netconf:base:1.0#candidate 35 | urn:ietf:params:netconf:base:1.0#confirmed-commit 36 | urn:ietf:params:netconf:base:1.0#validate 37 | urn:ietf:params:netconf:base:1.0#url?protocol=http,ftp,file 38 | urn:ietf:params:netconf:base:1.1 39 | 40 | 27703 41 | """; 42 | 43 | @Test 44 | public void willCreateAnObjectFromPacketWithoutNamespace() throws Exception { 45 | 46 | final Hello hello = Hello.from(HELLO_WITHOUT_NAMESPACE); 47 | 48 | assertThat(hello.getSessionId()) 49 | .isEqualTo("27700"); 50 | assertThat(hello.getCapabilities()) 51 | .containsExactly( 52 | "urn:ietf:params:netconf:base:1.0", 53 | "urn:ietf:params:netconf:base:1.0#candidate", 54 | "urn:ietf:params:netconf:base:1.0#confirmed-commit", 55 | "urn:ietf:params:netconf:base:1.0#validate", 56 | "urn:ietf:params:netconf:base:1.0#url?protocol=http,ftp,file", 57 | "urn:ietf:params:netconf:base:1.1"); 58 | assertThat(hello.hasCapability("urn:ietf:params:netconf:base:1.0#candidate")) 59 | .isTrue(); 60 | } 61 | 62 | @Test 63 | public void willCreateAnObjectFromPacketWithNamespace() throws Exception { 64 | 65 | final Hello hello = Hello.from(HELLO_WITH_NAMESPACE); 66 | 67 | assertThat(hello.getSessionId()) 68 | .isEqualTo("27703"); 69 | assertThat(hello.getCapabilities()) 70 | .containsExactly( 71 | "urn:ietf:params:netconf:base:1.0", 72 | "urn:ietf:params:netconf:base:1.0#candidate", 73 | "urn:ietf:params:netconf:base:1.0#confirmed-commit", 74 | "urn:ietf:params:netconf:base:1.0#validate", 75 | "urn:ietf:params:netconf:base:1.0#url?protocol=http,ftp,file", 76 | "urn:ietf:params:netconf:base:1.1"); 77 | assertThat(hello.hasCapability("urn:ietf:params:netconf:base:1.0#candidate")) 78 | .isTrue(); 79 | } 80 | 81 | @Test 82 | public void willCreateXmlFromAnObject() { 83 | 84 | final Hello hello = Hello.builder() 85 | .capability("urn:ietf:params:netconf:base:1.0") 86 | .capability("urn:ietf:params:netconf:base:1.0#candidate") 87 | .capability("urn:ietf:params:netconf:base:1.0#confirmed-commit") 88 | .capability("urn:ietf:params:netconf:base:1.0#validate") 89 | .capability("urn:ietf:params:netconf:base:1.0#url?protocol=http,ftp,file") 90 | .capability("urn:ietf:params:netconf:base:1.1") 91 | 92 | .sessionId("27700") 93 | .build(); 94 | 95 | XmlAssert.assertThat(hello.getXml()) 96 | .and(HELLO_WITHOUT_NAMESPACE) 97 | .ignoreWhitespace() 98 | .areIdentical(); 99 | } 100 | 101 | @Test 102 | public void willCreateXmlWithNamespaceFromAnObject() { 103 | 104 | final Hello hello = Hello.builder() 105 | .namespacePrefix("nc") 106 | .capability("urn:ietf:params:netconf:base:1.0") 107 | .capability("urn:ietf:params:netconf:base:1.0#candidate") 108 | .capability("urn:ietf:params:netconf:base:1.0#confirmed-commit") 109 | .capability("urn:ietf:params:netconf:base:1.0#validate") 110 | .capability("urn:ietf:params:netconf:base:1.0#url?protocol=http,ftp,file") 111 | .sessionId("27703") 112 | .build(); 113 | 114 | XmlAssert.assertThat(hello.getXml()) 115 | .and(HELLO_WITH_NAMESPACE) 116 | .ignoreWhitespace() 117 | .areIdentical(); 118 | } 119 | 120 | @Test 121 | public void willHandleEmptyCapabilities() { 122 | Hello hello = Hello.builder() 123 | .sessionId("99999") 124 | .build(); 125 | 126 | // Base capability 1.1 is auto‑injected by the builder 127 | assertThat(hello.getCapabilities()) 128 | .containsExactly("urn:ietf:params:netconf:base:1.1"); 129 | assertThat(hello.getSessionId()).isEqualTo("99999"); 130 | } 131 | 132 | @Test 133 | public void willHandleNullSessionId() { 134 | Hello hello = Hello.builder() 135 | .capability("urn:ietf:params:netconf:base:1.0") 136 | .build(); 137 | 138 | assertThat(hello.getSessionId()).isNull(); 139 | } 140 | 141 | @Test 142 | public void willThrowOnMalformedXml() { 143 | String badXml = "urn"; 144 | assertThatThrownBy(() -> Hello.from(badXml)) 145 | .isInstanceOf(Exception.class); 146 | } 147 | 148 | @Test 149 | public void willRoundTripNamespaceXml() throws Exception { 150 | Hello original = Hello.from(HELLO_WITH_NAMESPACE); 151 | Hello roundTripped = Hello.from(original.getXml()); 152 | assertThat(roundTripped).isEqualTo(original); 153 | } 154 | 155 | @Test 156 | public void differentObjectsNotEqual() { 157 | Hello h1 = Hello.builder().sessionId("1").build(); 158 | Hello h2 = Hello.builder().sessionId("2").build(); 159 | assertThat(h1).isNotEqualTo(h2); 160 | } 161 | 162 | @Test 163 | public void willHandleNullCapabilityCheck() { 164 | Hello hello = Hello.builder().build(); 165 | assertThat(hello.hasCapability(null)).isFalse(); 166 | } 167 | 168 | /** 169 | * RFC 6241 §3.1 – capability names MUST be valid URIs. 170 | * Supplying an invalid capability string to the builder should 171 | * throw an IllegalArgumentException. 172 | */ 173 | @Test 174 | public void willRejectNonUriCapability() { 175 | String bogus = "not a uri"; 176 | assertThatThrownBy(() -> Hello.builder() 177 | .sessionId("42") 178 | .capability(bogus) 179 | .build()) 180 | .isInstanceOf(IllegalArgumentException.class) 181 | .hasMessageContaining("Capability MUST be a valid URI per RFC 3986:"); 182 | } 183 | 184 | @Test 185 | void builderAddsBase11CapabilityByDefault() { 186 | Hello hello = Hello.builder().sessionId("123").build(); 187 | assertThat(hello.getCapabilities()) 188 | .contains("urn:ietf:params:netconf:base:1.1"); 189 | } 190 | 191 | @Test 192 | public void willRejectDtdInXml() { 193 | String withDtd = """ 194 | 196 | ]> 197 | 198 | 1 199 | 200 | """; 201 | 202 | assertThatThrownBy(() -> Hello.from(withDtd)) 203 | .isInstanceOf(Exception.class) 204 | .hasMessageContaining("DOCTYPE"); 205 | } 206 | 207 | /** 208 | * Ensures every capability returned by Hello#getCapabilities() parses as a URI. 209 | */ 210 | @Test 211 | public void capabilitiesAreUris() throws URISyntaxException { 212 | Hello hello = Hello.builder() 213 | .sessionId("99") 214 | .capability("urn:ietf:params:netconf:base:1.0") 215 | .capability("urn:ietf:params:netconf:capability:writable-running:1.0") 216 | .build(); 217 | 218 | for (String cap : hello.getCapabilities()) { 219 | new URI(cap); // throws URISyntaxException if invalid 220 | } 221 | } 222 | } -------------------------------------------------------------------------------- /src/main/java/net/juniper/netconf/element/AbstractNetconfElement.java: -------------------------------------------------------------------------------- 1 | package net.juniper.netconf.element; 2 | 3 | import net.juniper.netconf.NetconfConstants; 4 | import org.w3c.dom.Document; 5 | import org.w3c.dom.Element; 6 | 7 | import javax.xml.parsers.DocumentBuilderFactory; 8 | import javax.xml.parsers.ParserConfigurationException; 9 | import javax.xml.transform.OutputKeys; 10 | import javax.xml.transform.Transformer; 11 | import javax.xml.transform.TransformerException; 12 | import javax.xml.transform.TransformerFactory; 13 | import javax.xml.transform.dom.DOMSource; 14 | import javax.xml.transform.stream.StreamResult; 15 | import java.io.StringWriter; 16 | 17 | import static java.lang.String.format; 18 | 19 | /** 20 | * Base class for all model objects that represent NETCONF XML fragments 21 | * (e.g. {@code }, {@code }). 22 | *

23 | * Each subclass wraps a {@link org.w3c.dom.Document} so that: 24 | *

    25 | *
  • The DOM is immutable from the caller’s perspective— 26 | * getters return defensive copies.
  • 27 | *
  • An on‑demand, pre‑rendered XML {@link String} is cached for fast 28 | * {@link #equals(Object)}, {@link #hashCode()}, and logging.
  • 29 | *
30 | * Common XML helper methods live here so builders and parsers can share a 31 | * single, RFC 6241‑aware implementation. 32 | * 33 | * @author Juniper Networks 34 | */ 35 | public abstract class AbstractNetconfElement { 36 | 37 | private final Document document; 38 | private final String xml; 39 | 40 | /** 41 | * Wraps the supplied DOM {@link Document} and pre‑computes its XML string 42 | * representation for fast equality checks and logging. 43 | * 44 | * @param document a fully‑formed NETCONF XML document; must not be {@code null} 45 | * @throws NullPointerException if {@code document} is {@code null} 46 | */ 47 | protected AbstractNetconfElement(final Document document) { 48 | this.document = document; 49 | this.xml = createXml(document); 50 | } 51 | 52 | /** 53 | * Returns a defensive deep copy of the underlying DOM 54 | * {@link Document} so callers cannot mutate the internal state. 55 | * 56 | * @return a cloned {@link Document} representing this element 57 | */ 58 | public Document getDocument() { 59 | return (Document) document.cloneNode(true); // deep copy 60 | } 61 | 62 | /** 63 | * Returns the cached XML string representation of the wrapped document. 64 | * 65 | * @return XML string with no declaration (UTF‑8 assumed) 66 | */ 67 | public String getXml() { 68 | return xml; 69 | } 70 | 71 | /** 72 | * Creates an empty, namespace‑aware DOM {@link Document}. 73 | *

74 | * Internally delegates to {@link #createDocumentBuilderFactory()} to ensure 75 | * all security features are applied consistently. 76 | * 77 | * @return a brand‑new, empty {@link Document} 78 | * @throws IllegalStateException if the platform’s XML parser cannot be configured 79 | */ 80 | protected static Document createBlankDocument() { 81 | try { 82 | return createDocumentBuilderFactory().newDocumentBuilder().newDocument(); 83 | } catch (final ParserConfigurationException e) { 84 | throw new IllegalStateException("Unable to create document builder", e); 85 | } 86 | } 87 | 88 | /** 89 | * Returns a pre‑configured {@link DocumentBuilderFactory} with 90 | * namespace awareness enabled. Additional hardening options 91 | * (e.g. disallowing DTDs) can be added here centrally so every 92 | * NETCONF element parser benefits. 93 | * 94 | * @return a namespace‑aware {@link DocumentBuilderFactory} 95 | */ 96 | protected static DocumentBuilderFactory createDocumentBuilderFactory() { 97 | final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); 98 | documentBuilderFactory.setNamespaceAware(true); 99 | return documentBuilderFactory; 100 | } 101 | 102 | /** 103 | * Serialises a DOM {@link Document} to its XML string representation. 104 | *

105 | * The XML declaration is omitted because NETCONF frames are always UTF‑8 106 | * and the declaration is not required on the wire. 107 | * 108 | * @param document the document to serialise; must not be {@code null} 109 | * @return XML string (no declaration) 110 | * @throws IllegalStateException if a {@link TransformerException} occurs 111 | */ 112 | protected static String createXml(final Document document) { 113 | try { 114 | final TransformerFactory transformerFactory = TransformerFactory.newInstance(); 115 | final Transformer transformer = transformerFactory.newTransformer(); 116 | transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); 117 | final StringWriter stringWriter = new StringWriter(); 118 | transformer.transform(new DOMSource(document), new StreamResult(stringWriter)); 119 | return stringWriter.toString(); 120 | } catch (final TransformerException e) { 121 | throw new IllegalStateException("Unable to transform document to XML", e); 122 | } 123 | } 124 | 125 | /** 126 | * Convenience helper that builds an XPath expression matching a NETCONF 127 | * element in the base 1.0 namespace with the specified local‑name. 128 | * 129 | * @param elementName local name (e.g. {@code "rpc-reply"}) 130 | * @return an XPath string scoped to the NETCONF base namespace 131 | */ 132 | protected static String getXpathFor(final String elementName) { 133 | return format("/*[namespace-uri()='urn:ietf:params:xml:ns:netconf:base:1.0' and local-name()='%s']", elementName); 134 | } 135 | 136 | /** 137 | * Appends a child element (with optional text content) to the given parent, 138 | * using the NETCONF base 1.0 namespace and the provided prefix. 139 | * 140 | * @param document owner document 141 | * @param parentElement element to which the new child is appended 142 | * @param namespacePrefix namespace prefix to set on the new element 143 | * @param elementName local name of the child element 144 | * @param text text content; if {@code null} the element is skipped 145 | * @return the newly created element, or {@code null} if {@code text} was {@code null} 146 | */ 147 | protected static Element appendElementWithText( 148 | final Document document, 149 | final Element parentElement, 150 | final String namespacePrefix, 151 | final String elementName, 152 | final String text) { 153 | 154 | if (text != null) { 155 | final Element childElement = document.createElementNS(NetconfConstants.URN_XML_NS_NETCONF_BASE_1_0, elementName); 156 | childElement.setPrefix(namespacePrefix); 157 | childElement.setTextContent(text); 158 | parentElement.appendChild(childElement); 159 | return childElement; 160 | } else { 161 | return null; 162 | } 163 | } 164 | 165 | /** 166 | * Safely retrieves an attribute value from the supplied DOM {@link Element}. 167 | * 168 | * @param element the element to query; may be {@code null} 169 | * @param attributeName the local name of the attribute 170 | * @return the attribute value if the element is non‑null and the attribute 171 | * exists; otherwise {@code null} 172 | */ 173 | protected static String getAttribute(final Element element, final String attributeName) { 174 | if (element != null && element.hasAttribute(attributeName)) { 175 | return element.getAttribute(attributeName); 176 | } else { 177 | return null; 178 | } 179 | } 180 | 181 | /** 182 | * Returns the trimmed text content of a DOM {@link Element}. 183 | * 184 | * @param element the element whose {@code getTextContent()} should be read; 185 | * may be {@code null} 186 | * @return trimmed text or {@code null} if the element is {@code null} 187 | */ 188 | protected static String getTextContent(final Element element) { 189 | if (element == null) { 190 | return null; 191 | } else { 192 | return trim(element.getTextContent()); 193 | } 194 | } 195 | 196 | /** 197 | * Convenience null‑safe {@link String#trim()} wrapper. 198 | * 199 | * @param string the input string; may be {@code null} 200 | * @return a trimmed copy of {@code string}, or {@code null} if the input 201 | * was {@code null} 202 | */ 203 | protected static String trim(final String string) { 204 | return string == null ? null : string.trim(); 205 | } 206 | 207 | @Override 208 | public boolean equals(Object o) { 209 | if (this == o) return true; 210 | if (o == null || getClass() != o.getClass()) return false; 211 | AbstractNetconfElement that = (AbstractNetconfElement) o; 212 | return xml.equals(that.xml); 213 | } 214 | 215 | @Override 216 | public int hashCode() { 217 | return xml.hashCode(); 218 | } 219 | 220 | @Override 221 | public String toString() { 222 | return getClass().getSimpleName() + "{}"; 223 | } 224 | } 225 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # SPDX-License-Identifier: Apache-2.0 19 | # 20 | 21 | ############################################################################## 22 | # 23 | # Gradle start up script for POSIX generated by Gradle. 24 | # 25 | # Important for running: 26 | # 27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 28 | # noncompliant, but you have some other compliant shell such as ksh or 29 | # bash, then to run this script, type that shell name before the whole 30 | # command line, like: 31 | # 32 | # ksh Gradle 33 | # 34 | # Busybox and similar reduced shells will NOT work, because this script 35 | # requires all of these POSIX shell features: 36 | # * functions; 37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 39 | # * compound commands having a testable exit status, especially «case»; 40 | # * various built-in commands including «command», «set», and «ulimit». 41 | # 42 | # Important for patching: 43 | # 44 | # (2) This script targets any POSIX shell, so it avoids extensions provided 45 | # by Bash, Ksh, etc; in particular arrays are avoided. 46 | # 47 | # The "traditional" practice of packing multiple parameters into a 48 | # space-separated string is a well documented source of bugs and security 49 | # problems, so this is (mostly) avoided, by progressively accumulating 50 | # options in "$@", and eventually passing that to Java. 51 | # 52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 54 | # see the in-line comments for details. 55 | # 56 | # There are tweaks for specific operating systems such as AIX, CygWin, 57 | # Darwin, MinGW, and NonStop. 58 | # 59 | # (3) This script is generated from the Groovy template 60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 61 | # within the Gradle project. 62 | # 63 | # You can find Gradle at https://github.com/gradle/gradle/. 64 | # 65 | ############################################################################## 66 | 67 | # Attempt to set APP_HOME 68 | 69 | # Resolve links: $0 may be a link 70 | app_path=$0 71 | 72 | # Need this for daisy-chained symlinks. 73 | while 74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 75 | [ -h "$app_path" ] 76 | do 77 | ls=$( ls -ld "$app_path" ) 78 | link=${ls#*' -> '} 79 | case $link in #( 80 | /*) app_path=$link ;; #( 81 | *) app_path=$APP_HOME$link ;; 82 | esac 83 | done 84 | 85 | # This is normally unused 86 | # shellcheck disable=SC2034 87 | APP_BASE_NAME=${0##*/} 88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH="\\\"\\\"" 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | if ! command -v java >/dev/null 2>&1 137 | then 138 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 139 | 140 | Please set the JAVA_HOME variable in your environment to match the 141 | location of your Java installation." 142 | fi 143 | fi 144 | 145 | # Increase the maximum file descriptors if we can. 146 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 147 | case $MAX_FD in #( 148 | max*) 149 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 150 | # shellcheck disable=SC2039,SC3045 151 | MAX_FD=$( ulimit -H -n ) || 152 | warn "Could not query maximum file descriptor limit" 153 | esac 154 | case $MAX_FD in #( 155 | '' | soft) :;; #( 156 | *) 157 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 158 | # shellcheck disable=SC2039,SC3045 159 | ulimit -n "$MAX_FD" || 160 | warn "Could not set maximum file descriptor limit to $MAX_FD" 161 | esac 162 | fi 163 | 164 | # Collect all arguments for the java command, stacking in reverse order: 165 | # * args from the command line 166 | # * the main class name 167 | # * -classpath 168 | # * -D...appname settings 169 | # * --module-path (only if needed) 170 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 171 | 172 | # For Cygwin or MSYS, switch paths to Windows format before running java 173 | if "$cygwin" || "$msys" ; then 174 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 175 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 176 | 177 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 178 | 179 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 180 | for arg do 181 | if 182 | case $arg in #( 183 | -*) false ;; # don't mess with options #( 184 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 185 | [ -e "$t" ] ;; #( 186 | *) false ;; 187 | esac 188 | then 189 | arg=$( cygpath --path --ignore --mixed "$arg" ) 190 | fi 191 | # Roll the args list around exactly as many times as the number of 192 | # args, so each arg winds up back in the position where it started, but 193 | # possibly modified. 194 | # 195 | # NB: a `for` loop captures its iteration list before it begins, so 196 | # changing the positional parameters here affects neither the number of 197 | # iterations, nor the values presented in `arg`. 198 | shift # remove old arg 199 | set -- "$@" "$arg" # push replacement arg 200 | done 201 | fi 202 | 203 | 204 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 205 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 206 | 207 | # Collect all arguments for the java command: 208 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 209 | # and any embedded shellness will be escaped. 210 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 211 | # treated as '${Hostname}' itself on the command line. 212 | 213 | set -- \ 214 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 215 | -classpath "$CLASSPATH" \ 216 | -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ 217 | "$@" 218 | 219 | # Stop when "xargs" is not available. 220 | if ! command -v xargs >/dev/null 2>&1 221 | then 222 | die "xargs is not available" 223 | fi 224 | 225 | # Use "xargs" to parse quoted args. 226 | # 227 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 228 | # 229 | # In Bash we could simply go: 230 | # 231 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 232 | # set -- "${ARGS[@]}" "$@" 233 | # 234 | # but POSIX shell has neither arrays nor command substitution, so instead we 235 | # post-process each arg (as a line of input to sed) to backslash-escape any 236 | # character that might be a shell metacharacter, then use eval to reverse 237 | # that process (while maintaining the separation between arguments), and wrap 238 | # the whole thing up as a single "set" statement. 239 | # 240 | # This will of course break if any of these variables contains a newline or 241 | # an unmatched quote. 242 | # 243 | 244 | eval "set -- $( 245 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 246 | xargs -n1 | 247 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 248 | tr '\n' ' ' 249 | )" '"$@"' 250 | 251 | exec "$JAVACMD" "$@" 252 | -------------------------------------------------------------------------------- /src/test/java/net/juniper/netconf/element/RpcReplyLoadConfigResultsTest.java: -------------------------------------------------------------------------------- 1 | package net.juniper.netconf.element; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.xmlunit.assertj.XmlAssert; 5 | 6 | import static org.assertj.core.api.Assertions.assertThat; 7 | 8 | public class RpcReplyLoadConfigResultsTest { 9 | 10 | private static final String LOAD_CONFIG_RESULTS_OK_NO_NAMESPACE = """ 11 | \ 12 | 15 | 16 | 17 | 18 | """; 19 | 20 | private static final String LOAD_CONFIG_RESULTS_OK_WITH_NAMESPACE = """ 21 | \ 22 | 25 | 26 | 27 | 28 | """; 29 | 30 | private static final String LOAD_CONFIG_RESULTS_ERROR_NO_NAMESPACE = "" 31 | + "\n" + 34 | " \n" + 35 | " \n" + 36 | " protocol\n" + 37 | " operation-failed\n" + 38 | " error\n" + 39 | " syntax error\n" + 40 | " \n" + 41 | " foobar\n" + 42 | " \n" + 43 | " \n" + 44 | " \n" + 45 | " \n" + 46 | "\n"; 47 | 48 | private static final String LOAD_CONFIG_RESULTS_ERROR_WITH_NAMESPACE = """ 49 | \ 50 | 53 | 54 | 55 | protocol 56 | operation-failed 57 | error 58 | syntax error 59 | 60 | foobar 61 | 62 | 63 | 64 | 65 | 66 | """; 67 | 68 | @Test 69 | public void willParseAnOkResponseWithNoNamespacePrefix() throws Exception { 70 | 71 | final RpcReplyLoadConfigResults rpcReply = RpcReply.from(LOAD_CONFIG_RESULTS_OK_NO_NAMESPACE); 72 | 73 | assertThat(rpcReply.getMessageId()) 74 | .isEqualTo("3"); 75 | assertThat(rpcReply.getAction()) 76 | .isEqualTo("set"); 77 | assertThat(rpcReply.isOK()) 78 | .isTrue(); 79 | assertThat(rpcReply.hasErrorsOrWarnings()) 80 | .isFalse(); 81 | assertThat(rpcReply.hasErrors()) 82 | .isFalse(); 83 | assertThat(rpcReply.hasWarnings()) 84 | .isFalse(); 85 | assertThat(rpcReply.getErrors()) 86 | .isEmpty(); 87 | 88 | } 89 | 90 | @Test 91 | public void willParseAnOkResponseWithNamespacePrefix() throws Exception { 92 | 93 | final RpcReplyLoadConfigResults rpcReply = RpcReply.from(LOAD_CONFIG_RESULTS_OK_WITH_NAMESPACE); 94 | 95 | assertThat(rpcReply.getMessageId()) 96 | .isEqualTo("4"); 97 | assertThat(rpcReply.getAction()) 98 | .isEqualTo("set"); 99 | assertThat(rpcReply.isOK()) 100 | .isTrue(); 101 | assertThat(rpcReply.hasErrorsOrWarnings()) 102 | .isFalse(); 103 | assertThat(rpcReply.hasErrors()) 104 | .isFalse(); 105 | assertThat(rpcReply.hasWarnings()) 106 | .isFalse(); 107 | assertThat(rpcReply.getErrors()) 108 | .isEmpty(); 109 | 110 | } 111 | 112 | @Test 113 | public void willParseAnErrorResponseWithoutNamespacePrefix() throws Exception { 114 | 115 | final RpcReplyLoadConfigResults rpcReply = RpcReply.from(LOAD_CONFIG_RESULTS_ERROR_NO_NAMESPACE); 116 | 117 | assertThat(rpcReply.getMessageId()) 118 | .isEqualTo("5"); 119 | assertThat(rpcReply.getAction()) 120 | .isEqualTo("set"); 121 | assertThat(rpcReply.isOK()) 122 | .isTrue(); 123 | assertThat(rpcReply.hasErrorsOrWarnings()) 124 | .isTrue(); 125 | assertThat(rpcReply.hasErrors()) 126 | .isTrue(); 127 | assertThat(rpcReply.hasWarnings()) 128 | .isFalse(); 129 | assertThat(rpcReply.getErrors()) 130 | .containsExactly(RpcError.builder() 131 | .errorType(RpcError.ErrorType.PROTOCOL) 132 | .errorTag(RpcError.ErrorTag.OPERATION_FAILED) 133 | .errorSeverity(RpcError.ErrorSeverity.ERROR) 134 | .errorMessage("syntax error") 135 | .errorInfo(RpcError.RpcErrorInfo.builder() 136 | .badElement("foobar") 137 | .build()) 138 | .build()); 139 | } 140 | 141 | @Test 142 | public void willParseAnErrorResponseWithNamespacePrefix() throws Exception { 143 | 144 | final RpcReplyLoadConfigResults rpcReply = RpcReply.from(LOAD_CONFIG_RESULTS_ERROR_WITH_NAMESPACE); 145 | 146 | assertThat(rpcReply.getMessageId()) 147 | .isEqualTo("6"); 148 | assertThat(rpcReply.getAction()) 149 | .isEqualTo("set"); 150 | assertThat(rpcReply.isOK()) 151 | .isTrue(); 152 | assertThat(rpcReply.hasErrorsOrWarnings()) 153 | .isTrue(); 154 | assertThat(rpcReply.hasErrors()) 155 | .isTrue(); 156 | assertThat(rpcReply.hasWarnings()) 157 | .isFalse(); 158 | assertThat(rpcReply.getErrors()) 159 | .containsExactly(RpcError.builder() 160 | .errorType(RpcError.ErrorType.PROTOCOL) 161 | .errorTag(RpcError.ErrorTag.OPERATION_FAILED) 162 | .errorSeverity(RpcError.ErrorSeverity.ERROR) 163 | .errorMessage("syntax error") 164 | .errorInfo(RpcError.RpcErrorInfo.builder() 165 | .badElement("foobar") 166 | .build()) 167 | .build()); 168 | } 169 | 170 | @Test 171 | public void willCreateXmlOkWithoutNamespace() { 172 | 173 | final RpcReply rpcReply = RpcReplyLoadConfigResults.loadConfigResultsBuilder() 174 | .messageId("3") 175 | .action("set") 176 | .ok(true) 177 | .build(); 178 | 179 | XmlAssert.assertThat(rpcReply.getXml()) 180 | .and(LOAD_CONFIG_RESULTS_OK_NO_NAMESPACE) 181 | .ignoreWhitespace() 182 | .areIdentical(); 183 | } 184 | 185 | @Test 186 | public void willCreateXmlOkWithNamespace() { 187 | 188 | final RpcReply rpcReply = RpcReplyLoadConfigResults.loadConfigResultsBuilder() 189 | .namespacePrefix("nc") 190 | .messageId("4") 191 | .action("set") 192 | .ok(true) 193 | .build(); 194 | 195 | XmlAssert.assertThat(rpcReply.getXml()) 196 | .and(LOAD_CONFIG_RESULTS_OK_WITH_NAMESPACE) 197 | .ignoreWhitespace() 198 | .areIdentical(); 199 | } 200 | 201 | @Test 202 | public void willCreateXmlErrorWithoutNamespace() { 203 | 204 | final RpcReply rpcReply = RpcReplyLoadConfigResults.loadConfigResultsBuilder() 205 | .messageId("5") 206 | .action("set") 207 | .ok(true) 208 | .addError(RpcError.builder() 209 | .errorType(RpcError.ErrorType.PROTOCOL) 210 | .errorTag(RpcError.ErrorTag.OPERATION_FAILED) 211 | .errorSeverity(RpcError.ErrorSeverity.ERROR) 212 | .errorMessage("syntax error") 213 | .errorInfo(RpcError.RpcErrorInfo.builder() 214 | .badElement("foobar") 215 | .build()) 216 | .build()) 217 | .build(); 218 | 219 | XmlAssert.assertThat(rpcReply.getXml()) 220 | .and(LOAD_CONFIG_RESULTS_ERROR_NO_NAMESPACE) 221 | .ignoreWhitespace() 222 | .areIdentical(); 223 | } 224 | 225 | @Test 226 | public void willCreateXmlErrorWithNamespace() { 227 | 228 | final RpcReply rpcReply = RpcReplyLoadConfigResults.loadConfigResultsBuilder() 229 | .namespacePrefix("nc") 230 | .messageId("6") 231 | .action("set") 232 | .ok(true) 233 | .addError(RpcError.builder() 234 | .errorType(RpcError.ErrorType.PROTOCOL) 235 | .errorTag(RpcError.ErrorTag.OPERATION_FAILED) 236 | .errorSeverity(RpcError.ErrorSeverity.ERROR) 237 | .errorMessage("syntax error") 238 | .errorInfo(RpcError.RpcErrorInfo.builder() 239 | .badElement("foobar") 240 | .build()) 241 | .build()) 242 | .build(); 243 | 244 | XmlAssert.assertThat(rpcReply.getXml()) 245 | .and(LOAD_CONFIG_RESULTS_ERROR_WITH_NAMESPACE) 246 | .ignoreWhitespace() 247 | .areIdentical(); 248 | } 249 | 250 | } --------------------------------------------------------------------------------