• Post Reply Bookmark Topic Watch Topic
  • New Topic

why does it hang?  RSS feed

 
kevin yeandel
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I spent about 3 hours on this and am going off my head...

I have a jsp setting params then calling another jsp:

test-getobjectunix.jsp

<jsp:forward page="getobjectunix.jsp">
<jsp:param name="command" value=" \". ~/.bash_profile ; echo -e 'dump,c,3d12d68a80000102' | iapi repo -Udmadmin -P\"" />
<jsp:param name="password" value="123456"/>
<jsp:param name="servername" value="example.com"/>
<jsp:param name="noCache" value="0900getobjecttest"/>
<jsp:param name="user" value="dmadmin"/>
</jsp:forward>

getobjectunix.jsp

<%@ page import="java.io.*" %>
<HTML><BODY>
<%
String ret = "C:\\tomcat\\apache-tomcat-7.0.25\\webapps\\mydoc\\logs\\tmp_"+request.getParameter("servername") +request.getParameter("noCache") + ".txt";
Runtime rt=Runtime.getRuntime();
String cmd[]={"cmd.exe","/k","C:\\tomcat\\apache-tomcat-7.0.25\\plink.exe -pw " + request.getParameter("password") + " " + request.getParameter("user") +"@" +request.getParameter("servername")+ " " + request.getParameter("command")};
Process unix_proc=rt.exec(cmd);
%>
<%=ret%>

</BODY></HTML>
What is actually being passed to the command shell is
C:\tomcat\apache-tomcat-7.0.25\plink.exe -pw 123456 dmadmin@example.com ". ~/.bash_profile ; echo -e 'dump,c,3d12d68a80000102' | iapi repo -Udmadmin -P"

If I run that from the command line the contents are displayed as expected. If I call the test-getunixobject.jsp from the browser nothing much happens... is there something very obvious here that I am missing?
Many thanks in advance...
Kevin
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Why on Earth are you doing processing in a JSP? Especially firing off a separate process?

First step: move the Java code in the second JSP to a servlet where it belongs. Then it'll be a lot easier to diagnose.

Let us know when you've got that done and repost the new code. (Be sure to read UseCodeTags first.)

 
kevin yeandel
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not a servlet because java isn't my bag and doing it in jsp is easier for someone like me :)
I'll look into putting it into a class.
Apart from debugging.. I would like to know what you mean by "where it belongs"...
Thanks
Kevin

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java code in a JSP has been discredited for over 10 years now. It is considered a really poor and lazy practice.

See: http://www.coderanch.com/how-to/java/WhyNotUseScriptlets
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And while you're moving the Runtime.exec code to a servlet, read When Runtime.exec() won't.
 
kevin yeandel
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for your help.

The problem was that since Tomcat was running as Default User, the remote server challenged for an RSA key - which it wouldn't normally do if Default User had previously logged into the Unix server. So I had to copy the rsa registry keys from

[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY]
to
[HKEY_USERS\.DEFAULT\Software\SimonTatham\PuTTY]

to bypass a challenge.

Unfortunately my Java skills are not exactly my "selling point" but I still had to solve an admin problem in the short term.
In the longer term, can you just advise me:

I had a look at servlet/RequestParamExample code and it seems to be a good starting point for building the class
Could I use my jsp forward to call the class with some params? I'm currently calling the JSP with Adobe FlashBuilder's HTTPService.

Many thanks again

Kevin
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!