Hola a todos/as.
Escribo para ver si alguien tiene alguna solución para un problema que tengo al intentar hacer una conexión "ssh". He utiilizado el código que aparece en la siguiente página http://www.jscape.com/articles/ssh_using_java.html
Y me encuentro con el problema siguiente:
java.lang.UnsupportedOperationException: Not supported yet.2
at Editran.disconnected(Editran.java:160)
at com.jscape.inet.ssh.Ssh.fireSshDisconnected(Unknow n Source)
at com.jscape.inet.ssh.Ssh.disconnect(Unknown Source)
at com.jscape.inet.ssh.Ssh.connect(Unknown Source)
at Editran.Editran(Editran.java:89)
at Editran.doGetOrPost(Editran.java:54)
at Editran.doGet(Editran.java:33)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:173)
at org.hyperic.hq.product.servlet.filter.JMXFilter.do Filter(JMXFilter.java:325)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11 ConnectionHandler.processConnection(Http11BaseProt ocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
<?xml version='1.0' encoding='iso-8859-1'?><error><codigo>1</codigo><descripcion>java.lang.UnsupportedOperation Exception: Not supported yet.2</descripcion></error>
El código de mi Servlet es el siguiente:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.jscape.inet.ssh.*;
import com.jscape.inet.ssh.util.SshParameters;
public class Editran extends HttpServlet implements SshListener{
private boolean connected = false;
int vTimeout; // Milisegundos de Timout que se establece para la petición
String vResult; //Variable en la que contendremos el resultado recibido
String vCabecera = "<?xml version='1.0' encoding='iso-8859-1'?>";
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
//setInitParams();
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGetOrPost(request, response);
}
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGetOrPost(request, response);
}
protected void doGetOrPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
if (request.getParameter("p_host") == null ||
request.getParameter("p_codusr") == null ||
request.getParameter("p_pwdusr") == null ||
request.getParameter("p_ruta") == null ||
request.getParameter("p_file") == null ||
request.getParameter("p_control") == null ) {
printError(response, -1, "Faltan Parámetros necesarios k");
}else{
Editran(request, response,
request.getParameter("p_host"),
request.getParameter("p_codusr"),
request.getParameter("p_pwdusr"),
request.getParameter("p_ruta"),
request.getParameter("p_file"),
request.getParameter("p_control"));
}
} catch (Exception e) {
response.setContentType("text/xml");
response.getWriter().println(vCabecera);
response.getWriter().println("<error>");
e.printStackTrace(response.getWriter());
response.getWriter().println("</error>");
}
}
public void Editran (HttpServletRequest request, HttpServletResponse response,
String p_host,String p_codusr, String p_pwdusr, String p_ruta, String p_file, String p_control)throws ServletException, IOException
{
Ssh ssh = null;
SshParameters sshParams = null;
try {
String comando = p_ruta + "/" +p_file ;
sshParams = new SshParameters(p_host,p_codusr,p_pwdusr);
// create new Ssh instance
ssh = new Ssh(sshParams);
// register to capture events
ssh.addSshListener(new Editran());
printError(response,1,"PRUEBA");
// connect
ssh.connect();
// get output stream for writing data to SSH server
OutputStream out = ssh.getOutputStream();
// holds line entered at console
String line = null;
// read data from console
while (connected && (line = comando) != null) {
// send line with CRLF to SSH server
line += "\r\n";
try {
out.write(line.getBytes());
out.flush();
} catch(Exception ioe){
connected = false;
}
}
} catch (Exception e) {
/*e.printStackTrace();*/
e.printStackTrace(response.getWriter());
printError(response,1,e.toString());
} finally {
try {
if(connected) {
ssh.disconnect();
}
} catch(Exception e) {
e.printStackTrace();
e.printStackTrace(response.getWriter());
}
}
PrintMessage(response, vResult);
}
/* Función utilizada para escribir un mensaje dado en la respuesta de la petición*/
private void PrintMessage (HttpServletResponse response, String p_message )
{
try{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println(p_message);
out.close();
}catch(Exception f){}
}
/** Método para devolver un error en formato XML**/
private void printError (HttpServletResponse response, int p_code, String p_message)
{
String v_msg = vCabecera +
"<error>" +
"<codigo>" + p_code +
"</codigo>" +
"<descripcion>" + p_message +
"</descripcion>" +
"</error>";
PrintMessage(response, v_msg);
}
public void connected(SshConnectedEvent arg0) {
throw new UnsupportedOperationException("Not supported yet.1");
}
public void disconnected(SshDisconnectedEvent arg0) {
throw new UnsupportedOperationException("Not supported yet.2");
}
public void dataReceived(SshDataReceivedEvent arg0) {
throw new UnsupportedOperationException("Not supported yet.3");
}
Agradeceria una respuesta. Muchas gracias.
Un saludo.