2017-11-22 20 views
1

年後にJSchを使用してCiscoスイッチに接続します。今日私は、スイッチで行ったのと同じ方法でCisco WLCに接続しようとしました。何も動作しません!JSchでCisco WLCに接続するときにNullPointerExceptionを取得する

例外:com.jcraft.jsch.JSchException:java.lang.NullPointerExceptionが

あなたが最初のWLCでWLCでのPuTTYでログインしようとした場合WLCとスイッチの間の差が、あります「次のようにログイン:」を求めてください。ここでは、fooBarを書くか何も書くことができません。その後、WLCはユーザーとパスワードを要求しています。ここ は、コードは私が使用される:問題を解決した人の周りの誰かが

java.util.Properties configuration = new java.util.Properties(); 

configuration.put("kex", "diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256"); 
configuration.put("StrictHostKeyChecking", "no"); 

final JSch jsch = new JSch(); 
final Session session = jsch.getSession(TELNET_USER, outletWLC.getIp(),22); 

session.setPassword(TELNET_PASSWORD); 
session.setConfig(configuration); 
session.connect();  // Here I get the Exception! 
if (!session.isConnected()) { 
    throw new RuntimeException("cannot connect session"); 
} 

final ChannelShell channelShell = (ChannelShell) session.openChannel("shell"); 
final ByteArrayInputStream toSwitchStream = 
    new ByteArrayInputStream(commandString.getBytes()); 

final ByteArrayOutputStream fromSwitchStream = new ByteArrayOutputStream(); 
final int available = toSwitchStream.available(); 
channelShell.setInputStream(toSwitchStream); 
channelShell.setOutputStream(fromSwitchStream); 

channelShell.connect(); 

ありますか?

com.jcraft.jsch.JSchException: java.lang.NullPointerException 
    at com.jcraft.jsch.Session.receive_kexinit(Session.java:544) 
    at com.jcraft.jsch.Session.connect(Session.java:291) 
    at com.jcraft.jsch.Session.connect(Session.java:154) 
    at de.mediamarkt.indira.server.services.MSVorfPasswServiceImpl.readWLC(MSVorfPasswServiceImpl.java:169) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at de.mediamarkt.indira.server.remote.IndiraProxyServlet.service(IndiraProxyServlet.java:93) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) 
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1097) 
    at de.mediamarkt.indira.server.filter.IndiraMultiPersistenceUnitTransactionFilter.doFilter(IndiraMultiPersistenceUnitTransactionFilter.java:23) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1088) 
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360) 
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) 
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729) 
    at org.mortbay.jetty.handler.HandlerList.handle(HandlerList.java:49) 
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) 
    at org.mortbay.jetty.Server.handle(Server.java:324) 
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505) 
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843) 
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647) 
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) 
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380) 
    at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228) 
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488) 
Caused by: java.lang.NullPointerException 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Class.java:264) 
    at com.jcraft.jsch.Session.receive_kexinit(Session.java:540) 
    ... 26 more 

JSCHログ:

INFO: Connecting to 10.3.xxx.xxx port 22 
INFO: Connection established 
INFO: Remote version string: SSH-2.0-CISCO_WLC 
INFO: Local version string: SSH-2.0-JSCH-0.1.44 
INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256 
INFO: aes256-ctr is not available. 
INFO: aes192-ctr is not available. 
INFO: aes256-cbc is not available. 
INFO: aes192-cbc is not available. 
INFO: arcfour256 is not available. 
INFO: SSH_MSG_KEXINIT sent 
INFO: SSH_MSG_KEXINIT received 
INFO: kex: server->client aes128-ctr hmac-sha1 none 
INFO: kex: client->server aes128-ctr hmac-sha1 none 
INFO: Disconnecting from 10.3.xxx.xxx port 22 
+0

com.jcraft.jsch.JSchException:java.lang.NullPointerExceptionが –

+0

ライン最後のセッションのセッション= jsch.getSession(System.lineSeparator()+ TELNET_USER、outletWLC.getIp()、22)。 はテストのためのもので、正しいものは最後のものですセッションセッション= jsch.getSession(TELNET_USER、outletWLC.getIp()、22); –

+0

例外コールスタックを含む!そして古いコメントを削除してください。 –

答えて

1

は今、私は私の継承されたプロジェクトはJSCHの間違ったバージョンをロード隠された場所を見つけました。 私はそれを修正し、驚き、驚き、それは動作します!マーティンに多くの支持をいただきありがとうございます!

INFO: Connecting to 10.3.xxx.xxx port 22 
INFO: Connection established 
INFO: Remote version string: SSH-2.0-CISCO_WLC 
INFO: Local version string: SSH-2.0-JSCH-0.1.54 
INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256 
INFO: aes256-ctr is not available. 
INFO: aes192-ctr is not available. 
INFO: aes256-cbc is not available. 
INFO: aes192-cbc is not available. 
INFO: CheckKexes: diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521 
INFO: CheckSignatures: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521 
INFO: SSH_MSG_KEXINIT sent 
INFO: SSH_MSG_KEXINIT received 
INFO: kex: server: [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1 
INFO: kex: server: ssh-rsa,rsa-sha2-512,rsa-sha2-256 
INFO: kex: server: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected] 
INFO: kex: server: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected] 
INFO: kex: server: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1 
INFO: kex: server: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1 
INFO: kex: server: none,[email protected],zlib 
INFO: kex: server: none,[email protected],zlib 
INFO: kex: server: 
INFO: kex: server: 
INFO: kex: client: diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256 
INFO: kex: client: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521 
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc 
INFO: kex: client: aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc 
INFO: kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96 
INFO: kex: client: hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96 
INFO: kex: client: none 
INFO: kex: client: none 
INFO: kex: client: 
INFO: kex: client: 
INFO: kex: server->client aes128-ctr hmac-sha1 none 
INFO: kex: client->server aes128-ctr hmac-sha1 none 
INFO: SSH_MSG_KEXDH_INIT sent 
INFO: expecting SSH_MSG_KEXDH_REPLY 
INFO: ssh_rsa_verify: signature true 
WARN: Permanently added '10.3.xxx.xxx' (RSA) to the list of known hosts. 
INFO: SSH_MSG_NEWKEYS sent 
INFO: SSH_MSG_NEWKEYS received 
INFO: SSH_MSG_SERVICE_REQUEST sent 
INFO: SSH_MSG_SERVICE_ACCEPT received 
関連する問題