I'm trying to send config of router to TFTP server using JSF . When i test my code with Main class it works but when i try to integrate this code into button action's it doesn't work . This is my session bean code
public Void SendConfigViaTftp(Router r) {
int port=22;
String name = r.getRouterName();
String ip=r.getRouterIP();
String password =r.getRouterPassword();
try
{
JSch jsch = new JSch();
Session session = jsch.getSession(name, ip, port);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
System.out.println("Establishing Connection...");
session.connect();
System.out.println("Connection established.");
ChannelExec channelExec = (ChannelExec)session.openChannel("exec");
InputStream in = channelExec.getInputStream();
channelExec.setCommand("enable");
channelExec.setCommand("copy run tftp:");
OutputStream out = channelExec.getOutputStream();
channelExec.connect();
System.out.println("Copy.");
out.write(("192.168.18.1 \n").getBytes());
System.out.println("IP.");
out.write(name.getBytes());
System.out.println("name.");
out.flush();
out.close();
session.disconnect();
return true;
}
catch(Exception e){System.err.print(e);
}
}
This is the output :
11:53:25,279 INFO [stdout] (default task-11) Establishing Connection...
11:53:25,516 INFO [stdout] (default task-11) Connection established.
11:53:25,578 INFO [stdout] (default task-11) Copy.
11:53:25,578 INFO [stdout] (default task-11) IP.
11:53:25,578 INFO [stdout] (default task-11) name.
This is the code of my button
<p:commandButton value="Sauvegarder(TFTP)" action="#{ListBean.sauvegardeTFTP(rtr)}" update=":routeurs" ><f:ajax disabled="true"/></p:commandButton>
I'm sure that the problem is my jsf application has a problem with the OutputStream . Can some one help me .