Supported Platforms
Related Documentation
Troubleshooting Exception Errors in a NETCONF Java Toolkit Program
The following sections outline exception errors that you might encounter when executing a NETCONF Java toolkit program. These sections also present potential causes and solutions for each error.
Troubleshooting Connection Errors: Socket Timed Out
Problem
A NETCONF exception occurs, and you see the following error message:
Exception in thread "main" net.juniper.netconf.NetconfException: The connect() operation on the socket timed out. at net.juniper.netconf.Device.createNetconfSession(Device.java:344) at net.juniper.netconf.Device.connect(Device.java:225) at GetChassisInventory.main(GetChassisInventory.java:14)
Cause
Potential causes for the socket timed out error include:
- The device or interface to which you are connecting is down or unavailable.
- The IP address or DNS name in the arguments for the Device object is incorrect.
- The connection timeout value was exceeded before the connection was established.
Solution
Ensure that the device is up and running. Also verify that the IP address or DNS name is correct in the arguments of the Device constructor in your program code.
The default timeout value for connecting to a device is 5000 milliseconds. To set the timeout value to a larger interval to ensure that the program has sufficient time to establish the connection, call the setTimeOut() method on the device object. The following code sets the timeout interval to 10 seconds:
Device device = new Device("10.10.1.1","admin","PaSsWoRd",null); device.setTimeOut(10000); device.connect();
Troubleshooting Connection Errors: No Connection
Problem
An IllegalStateException exception occurs, and you see the following error message:
Exception in thread "main" java.lang.IllegalStateException: Cannot execute RPC, you need to establish a connection first. at net.juniper.netconf.Device.executeRPC(Device.java:498) at GetChassisInventoryRun.main(GetChassisInventoryRun.java:15)
Cause
An SSHv2 connection or NETCONF session was not established with the remote device.
Solution
Call the connect() method on the device object to establish an SSHv2 connection and a default NETCONF session with the device on which the NETCONF server runs. Once the connection and session are established, RPC execution should be successful.
Troubleshooting Authentication Errors
Problem
A NETCONF exception occurs, and you see the following error message:
Exception in thread "main" net.juniper.netconf.NetconfException: Authentication failed. at net.juniper.netconf.Device.createNetconfSession(Device.java:358) at net.juniper.netconf.Device.connect(Device.java:225) at GetChassisInventory.main(GetChassisInventory.java:14)
<!-- or -->
Could not connect to device:Authentication failed.
Cause
An error message for failed authentication could have several possible causes, including the following:
- The host or authentication details passed as arguments to the Device constructor are incorrectly entered in the program code.
- The arguments for the Device object are correct, but there is no corresponding user account created on the device to which you are connecting.
Solution
If there is no user account on the device to which you are connecting, create the account with the appropriate authentication. For more information about configuring user accounts on a device running Junos OS, see the Junos OS Administration Library for Routing Devices.
If the user account exists on the remote device, but the arguments for the Device constructor are entered incorrectly in the program code, correct the arguments and recompile the program.
Troubleshooting NETCONF Session Errors
Problem
A NETCONF exception occurs, and you see the following error message:
Exception in thread "main" net.juniper.netconf.NetconfException: There was a problem while connecting to 10.10.1.1:830 at net.juniper.netconf.Device.createNetconfSession(Device.java:344) at net.juniper.netconf.Device.connect(Device.java:225) at GetChassisInventory.main(GetChassisInventory.java:14)
Cause
NETCONF over SSH might not be enabled on the device where the NETCONF server resides, or it might be enabled on a different port.
Solution
Ensure that you have enabled NETCONF over SSH on the device where the NETCONF server resides. If your NETCONF Java toolkit program does not specify a specific port number in the Device argurments, the NETCONF session is established on the default NETCONF-over-SSH port, 830. To verify whether NETCONF over SSH is enabled on the default port for a device running Junos OS, enter the following operational mode command on the remote device:
user@host> show configuration system services
ftp; netconf { ssh; }
If the netconf configuration hierarchy is absent, issue the following statements in configuration mode to enable NETCONF over SSH on the default port:
If the netconf configuration hierarchy specifies a port other than the default port, you should include the new port number in the Device object constructor arguments. For example, the following device is configured for NETCONF over SSH on port 12345:
user@host> show configuration system services
netconf { ssh { port 12345; } }
To correct the connection issue, include the new port number in the Device arguments.
Device device = new Device("10.10.1.1", "admin", "PaSsWoRd", null, 12345);