I have come across a few posts, none of which has really answered my question, I have also been in the process of raising the question but putting it off only to research more dead ends...
So here is the issue, using j2ssh libraries to make ssh connections :
@OnMessage
public String handleOpen(Session usersession) {
System.out.println("Client is now connected.")
properties = new SshConnectionProperties();
properties.setHost(host)
properties.setPort(sshPort)
ssh.connect(properties, new IgnoreHostKeyVerification())
int result=0
PasswordAuthenticationClient pwd = new PasswordAuthenticationClient()
pwd.setUsername(username)
pwd.setPassword(password)
result = ssh.authenticate(pwd)
if(result == 4) {
isAuthenticated=true
}
// Evaluate the result
if (isAuthenticated) {
session = ssh.openSessionChannel()
SessionOutputReader sor = new SessionOutputReader(session)
if (session.requestPseudoTerminal("gogrid",80,24, 0 , 0, "")) {
if (session.startShell()) {
ChannelOutputStream out = session.getOutputStream()
session.getOutputStream().write("${usercommand} \n".getBytes())
println "--------------------------------authenticated user"
handleMessage(session.getInputStream(),usersession)
}
}
}
}
@OnMessage
public void handleMessage(InputStream stream, Session usersession) {
try {
usersession.getBasicRemote().sendText('SOMETHING')
usersession.getBasicRemote().sendObject(stream)
//return stream
} catch (IOException e) {
}
}
What I would like to do is for handleMessage to return the entire inputStream
Then within the javascript on the client's webpage to recieve that input stream :
...
webSocket.onmessage=function(message) {processMessage(message);};
var THRESHOLD = 10240;
...
function processMessage(message) {
//webSocket.send(textMessage.value);
//textMessage.value="";
messagesTextarea.value +=" woot woot woot\n";
if(message.data instanceof ArrayBuffer) {
var wordarray = new Uint16Array(message.data);
for (var i = 0; i < wordarray.length; i++)
{
console.log(wordarray[i]);
wordarray[i]=wordarray[i]+1;
}
messagesTextarea.value +=""+wordarray.buffer+"\n"
}else{
messagesTextarea.value +=""+message.data+"\n"
}
/*
setInterval( function() {
//messagesTextarea.value +=" Receive from Server ===> "+ message.data +"\n";
if (webSocket.bufferedAmount < THRESHOLD) {
if ((message.data != null)&&(message.data !="")) {
messagesTextarea.value +=" got from Server ===> ("+message.data+")";
}
} }, 5000);
*/
}
The objective is to launch ssh connection (no input really required - although with input would be of benefit for further client calls...
Once connected to run
handleMessage(session.getInputStream(),usersession)
This then returns the stream from the connection back to the javascript frontend.
At the moment I can see a connection to handleMessage but nothing is being returned to javascript frontend...
So I guess its related to how do you stream inputstreams via a javascript frontend.....