.JSchException: Packet corrupt - java

I am using Jsch 0.1.51 on RHEl 6 with Jdk 1.7_51. While making session to a remote machine I am getting exception that is :
com.jcraft.jsch.JSchException: Packet corrupt
at com.jcraft.jsch.Session.start_discard(Session.java:1049)
at com.jcraft.jsch.Session.read(Session.java:919)
at com.jcraft.jsch.UserAuthNone.start(UserAuthNone.java:56)
at com.jcraft.jsch.Session.connect(Session.java:389)
at com.jcraft.jsch.Session.connect(Session.java:183)
at TestSFTP.checkException(TestSFTP.java:130)
at TestSFTP.moveFileToDir(TestSFTP.java:78)
at TestSFTP.main(TestSFTP.java:73)
Same code was working fine with RHEL 5. Can any body provide some suggestions .. Thanks
code used is :
Session session = null;
ChannelSftp channelSftp = null;
JSch jsch = new JSch();
session = jsch.getSession(this.sftpUser,this.sftpHost,this.sftpPort);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.setPassword(this.sftpPassword);
session.connect();
channelSftp = (ChannelSftp)session.openChannel("sftp");
channelSftp.connect();
I am getting error at session.connect();

This exception can occur if you are trying to connect on an already existent session. A work around is closing the session and then starting a new session. This helped me. Found some help from this site:
http://flyingjxswithjava.blogspot.com/2015/03/comjcraftjschjschexception-packet.html
Quoting essential points from the site to understand the problem:
This exception occurs when the Session is reused repeatedly in a loop where the session is disconnected intentionally or due to time out and needs to reconnect again.
The reason that such an exception is thrown is that the first time the Session is connected to the remote site, a random number called Packet is generated for the session.
When the thread is having its 1 hour sleep, the session gets automatically disconnected due to no activity for a certain period of time.
When the Session is disconnected, the Packet is lost.
When the Session is trying to reconnect, it could not find the Packet, thus the exception is thrown.

Related

How to check connection of javax.mail

properties.put("mail.imap.host", host);
properties.put("mail.imap.port", "993");
Session emailSession = Session.getDefaultInstance(properties);
Store store = emailSession.getStore("imaps");
store.connect(host, username, password);
This code is working well, but if the mail server is down, I got the expection:
javax.mail.MessagingException: * BYE JavaMail Exception: java.io.IOException: Connection dropped by server?;
nested exception is:
com.sun.mail.iap.ConnectionException: * BYE JavaMail Exception: java.io.IOException: Connection dropped by server?
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:731)
at javax.mail.Service.connect(Service.java:366)
at javax.mail.Service.connect(Service.java:246)
at eugene.neocortex.fm.mail.check.CheckingMails.fetch(CheckingMails.java:100)
So I need to check if server is available? And I read the documentation of javax.mail and cant find method, how do I can check if server is alive? Method isConnected() checks if currently connected, but I need to check connection to my mail server before this code or I got exception again on this code string:
Store store = emailSession.getStore("imaps");

Why do I get a MQRC_NOT_AUTHORIZED error when trying to get channel information using PCF?

I am using MQ Java PCF API to retrieve information from an MQ installation. There are several constructors for the class PCFMessageAgent. There is one that accepts the host, port and channel name. I have shown an extract from the documentation.
public PCFMessageAgent(String host,
int port,
String channel)
throws MQException
Initialises a new PCFMessageAgent with a client connection to a queue manager.
The code I have is
PCFMessageAgent agent = new PCFMessageAgent(host, port, "SYSTEM.DEF.SVRCONN");
PCFMessage pcfCmd = new PCFMessage(MQConstants.MQCMD_INQUIRE_CHANNEL);
pcfCmd.addParameter(MQConstants.MQCACH_CHANNEL_NAME, channelName);
PCFMessage[] pcfResponse = agent.send(pcfCmd);
but I get a MQRC_NOT_AUTHORIZED error
Exception in thread "main" com.ibm.mq.MQException: MQJE001: Completion Code '2', Reason '2035'.
at com.ibm.mq.MQManagedConnectionJ11.<init>(MQManagedConnectionJ11.java:249)
at com.ibm.mq.MQClientManagedConnectionFactoryJ11._createManagedConnection(MQClientManagedConnectionFactoryJ11.java:450)
at com.ibm.mq.MQClientManagedConnectionFactoryJ11.createManagedConnection(MQClientManagedConnectionFactoryJ11.java:487)
at com.ibm.mq.StoredManagedConnection.<init>(StoredManagedConnection.java:97)
at com.ibm.mq.MQSimpleConnectionManager.allocateConnection(MQSimpleConnectionManager.java:194)
at com.ibm.mq.MQQueueManagerFactory.obtainBaseMQQueueManager(MQQueueManagerFactory.java:868)
Why do I get this error? How do I fix this.
I found this in the error logs. Any help will be much appreciated.
07/08/17 15:42:51 - Process(3294.15) User(user1) Program(amqrmppa)
Host(ubuntuvm-2) Installation(Installation1)
VRMF(8.0.0.7) QMgr(QM_FR2_2)
AMQ9777: Channel was blocked
EXPLANATION:
The inbound channel 'SYSTEM.DEF.SVRCONN' was blocked from address
'192.168.56.101' because the active values of the channel matched a record
configured with USERSRC(NOACCESS). The active values of the channel were
'CLNTUSER(user1)'.
ACTION:
Contact the systems administrator, who should examine the channel
authentication records to ensure that the correct settings have been
configured. The ALTER QMGR CHLAUTH switch is used to control whether channel
authentication records are used. The command DISPLAY CHLAUTH can be used to
query the channel authentication records.
----- cmqxrmsa.c : 1462 -------------------------------------------------------
07/08/17 15:42:51 - Process(3294.15) User(user1) Program(amqrmppa)
Host(ubuntuvm-2) Installation(Installation1)
VRMF(8.0.0.7) QMgr(QM_FR2_2)
AMQ9999: Channel 'SYSTEM.DEF.SVRCONN' to host '192.168.56.101' ended
abnormally.
EXPLANATION:
The channel program running under process ID 3294 for channel
'SYSTEM.DEF.SVRCONN' ended abnormally. The host name is '192.168.56.101'; in
some cases the host name cannot be determined and so is shown as '????'.
ACTION:
Look at previous error messages for the channel program in the error logs to
determine the cause of the failure. Note that this message can be excluded
completely or suppressed by tuning the "ExcludeMessage" or "SuppressMessage"
attributes under the "QMErrorLog" stanza in qm.ini. Further information can be
found in the System Administration Guide.
----- amqrmrsa.c : 930 --------------------------------------------------------
The issue is that you are attempting to connect to the channel SYSTEM.DEV.SVRCONN. By default there is a CHLAUTH rule that blocks access to channels named SYSTEM.*.
You can create a new SVRCONN channel that does not have a name that starts with SYSTEM and it would get past this check.

How to execute Multiple commands

I want to:
Log in to putty using Hostname, username, password and port number.
This I have achieved.
Once I logged in, I want to connect to server1. Usually in putty we
connect using ssh command (ssh user#server1).
Once I connected to that server.I need to run multiple commands like:
df -kh ps -ef|grep www
And after executing above commands, I need to log out from
server1 and need to log in to server2.
How can I do it in JSCH?
JSch jsch=new JSch();
Session session=jsch.getSession(remoteHostUserName, RemoteHostName, remoteHostPortNo);
session.setPassword(remoteHostpassword);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
System.out.println("Please wait...");
session.connect();
System.out.println("Connected "+remoteHostUserName+"#"+RemoteHostName);
ChannelExec channel=(ChannelExec) session.openChannel("shell");
BufferedReader in=new BufferedReader(new InputStreamReader(channel.getInputStream()));
channel.setCommand("df -kh");
channel.setCommand("pwd");
channel.connect();
Try ChannelShell channel = (ChannelShell) session.openChannel("shell"); setup inputStream and outputStream and subsequently perform the following loop:
write into the connected inputStream and flush it
read from the connected outputStream
This way you can even construct your second commands based on the outcome of the first one.
In order to create an interactive session, you can refer the Example class provided jsch developers.
http://www.jcraft.com/jsch/examples/UserAuthKI.java
Create the Channel object as an instance of Shell
ie
Channel channel=session.openChannel("shell");
And then set the Input and Output Streams for that Channel object.
channel.setInputStream(System.in);
channel.setOutputStream(System.out);
And then connect the channel.
This way, after each comand execution, the channel won't be closed and the state of the previous command can be persisted.
Using the above code, you can create an interactive session in your console
You can run multiple commands by using below approach
put all the commands in a string separated by ;
"command1;command2...."

MQ-7 connectivity issue

Hi below is the code I used to check the connectivity
String qManager="";
int openOptions = CMQC.MQOO_FAIL_IF_QUIESCING + CMQC.MQOO_INPUT_SHARED + CMQC.MQOO_INQUIRE+CMQC.MQOO_BROWSE;
try{
Hashtable props = new Hashtable();
props.put(CMQC.HOST_NAME_PROPERTY, "IP");
props.put(CMQC.PORT_PROPERTY, port_num);
props.put(CMQC.CHANNEL_PROPERTY, "SYSTEM.DEFAULT.LOCAL.QUEUE");
MQQueueManager qMgr = new MQQueueManager("QM", props);
MQQueue destQueue = qMgr.accessQueue("Q_name", openOptions);
System.out.println("Connected");
destQueue.close();
qMgr.disconnect();
}catch(MQException mqe){
System.out.println(mqe.reasonCode);
}
}
}
When I run the program I get this Exception
MQJE001: An MQException occurred: Completion Code 2, Reason 2009
MQJE016: MQ queue manager closed channel immediately during connect
2009
Closure reason = 2009
MQJE001: Completion Code 2, Reason 2009
Kindly help me
There are 2 things I suspect here:
props.put(CMQC.HOST_NAME_PROPERTY, "IP"); <-- Is the hostname so short?
props.put(CMQC.CHANNEL_PROPERTY, "SYSTEM.DEFAULT.LOCAL.QUEUE"); <-- Why is the local queue name set as channel property
There are some samples in the "tools" folder of MQ installation, that can help you.
I got this error bcoz in IBM Websphere MQ-7 the channel security was enabled. After Disabling the channel security i was able to connect it

XMPP server does not respond to Smack login request

I'm trying to establish a connection to an XMPP server using smack.
ConnectionConfiguration cf = new ConnectionConfiguration("jabber.ccc.de");
cf.setTruststorePassword("changeme");
this.connection = new XMPPConnection(cf);
this.connection.connect();
this.connection.login("user", "password");
But whenever logging in I get an XMPPException (No response from the server.: ) and the socket gets closed.
Any ideas what's going wrong here?
Regards
Have you tried seeing what the actual XMPP data being sent to/from the server is?
Try adding this to your code at startup:
System.setProperty("smack.debugEnabled", "true");
XMPPConnection.DEBUG_ENABLED = true;
Try this one.
ConnectionConfiguration cf = new ConnectionConfiguration("jabber.ccc.de",5222, "test");
cf.setTruststorePassword("changeme");
this.connection = new XMPPConnection(cf);
this.connection.connect();
this.connection.login("user", "password");
Just put the following line before you make the connection.
SASLAuthentication.supportSASLMechanism("PLAIN");
This problem was addressed by a person called Davanum; see the link
The problem is :
you are behind a slow internet connection.
You need to increase time out for packet reply in smack config.
Strangely, you can get this problem, only the first time, after a boot of the client system (windows).

Categories

Resources