|
Apache Tomcat General discussion of the Apache Tomcat servlet container. For discussions specific to the Professional Apache Tomcat book, please see the book discussion forum for that book. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Apache Tomcat section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
May 15th, 2006, 07:53 AM
|
Registered User
|
|
Join Date: May 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Facing problem with tomcat 5.5.9
Hi everybody.
I'm maintaing a system in java that transfers files from on machine to another. For actual data transfer it uses servlets. Previously it was running on tomcat 4.0 and OK. But, when I changed the server from tomcat 4.0 to tomcat 5.5.9 it's creating some problems in transferring data(files) in a network, however it's OK within the local system. I've successfully installed and configured the tomcat, but still in trouble. Could anyone kindly help me in the same.
Your prompt reply would be highly appreciated becoz its very urgent!
Thanks in advance.
raj
Bhoj Raj Joshi
Web/Application Developer,
KDK Infotech, New Delhi.
|
May 18th, 2006, 11:32 AM
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
Can you outline the problems?
A stacktrace of the same will help
Regards,
eNJay
|
May 19th, 2006, 07:39 AM
|
Registered User
|
|
Join Date: May 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your quick reply.
Well, my system starts from a normal java class namely UploadFile.java which calls a servlet class namely RecvServlet_data.java like this way:
Context root is %CATALINA_HOME%/webapps/examples.
code of UploadFile.java:
import java.io.*;
import java.net.*;
public class UploadFile
{
URLConnection con;
public static void main(String []str)
{
try
{
File srcFile = new File(str[0]);
String destPath = str[1];
String result = new UploadFile().transferFile(srcFile, destPath);
System.out.println(result);
}
catch(Exception e)
{
System.out.println("Usage: sourcePath destPath");
System.exit(1);
}
}
public String transferFile(File sourceFile, String destPath)
{
try
{
String base = "http://127.0.0.1:8080/examples/servlet/RecvServlet_data";
String fileName = sourceFile.getPath();
destPath += File.separator + sourceFile.getName();
FileInputStream fin = new FileInputStream(sourceFile);
URL url = new URL(base + "?name=" + URLEncoder.encode(fileName,"UTF-8") + "&path=" + URLEncoder.encode(destPath,"UTF-8"));
con = url.openConnection();
con.setRequestProperty("REQUEST_METHOD", "POST");
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(true);
con.setRequestProperty("Content-Type", "multipart-formdata");
DataOutputStream dataOut = new DataOutputStream(con.getOutputStream());
int c = 30720;
byte b[] = new byte[c];
for(int i = fin.read(b, 0, c); i >= 0; i = fin.read(b, 0, c))
{
dataOut.write(b, 0, i);
}
dataOut.flush();
dataOut.close();
fin.close();
return "Success";
}
catch(Exception e)
{
System.out.println("Error: " + e.toString());
return "Failure";
}
finally
{
con = null;
}
}
}
Code of RecvServlet_data.java:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class RecvServlet_data extends HttpServlet
{
public RecvServlet_data()
{
}
public void init()throws ServletException
{
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
doPost(req, res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
String fileName = req.getParameter("name");
String destIP = req.getParameter("path");
System.out.println("File : " + fileName + " is ready to transfer to " + destIP);
File destFile = new File(destIP);
DataInputStream dataIn = new DataInputStream(req.getInputStream());
BufferedOutputStream buffOut = new BufferedOutputStream(new FileOutputStream(destFile));
int c = 30720;
byte b[] = new byte[c];
try
{
for(int j = dataIn.read(b, 0, c); j >= 0; j = dataIn.read(b, j, c))
{
buffOut.write(b, 0, j);
c += j;
}
}
catch(Exception e)
{
System.out.println("Error in Servlet : " + e.getMessage());
}
}
}
web.xml file is configured as:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>
RecvServlet_data
</servlet-name>
<servlet-class>
RecvServlet_data
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
RecvServlet_data
</servlet-name>
<url-pattern>
/servlet/RecvServlet_data
</url-pattern>
</servlet-mapping>
</web-app>
Now, when i'm trying to run UploadFile file, i just get "Success" message and nothing else done.
This is just that part of my system which actually transfers files. I don't know whether my code has been changed or any other problem...please help me.
Bhoj Raj Joshi
Web/Application Developer,
KDK Infotech, New Delhi.
|
May 19th, 2006, 03:29 PM
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Did you look at the port you are trying to open in the class?
http://127.0.0.1:8080/examples/servlet/RecvServlet_data";
You are trying to access the servlet on the local machine. No wonder why it works on the machine that has the server. Replace it with the IP address of the machine where servlet is. That should work.
Regards,
eNJay
|
May 22nd, 2006, 01:52 AM
|
Registered User
|
|
Join Date: May 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm doing so because the servlet class is in the same local system and tomcat as well. I've also done what u suggested me i.e. replacing 127.0.0.1 with the IP address of the system on which tomcat is running with my servlet class, but i again end up with the same problem.
Alternatively, is there any machanism to grant privilleges to a tomcat server for accessing files or other resources in a network?
raj
|
May 24th, 2006, 07:20 AM
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Can you do a quick as to what is being received at the servlet end? I see that you are writing it to a file. Is that file created at all?
Regards,
eNJay
|
May 25th, 2006, 12:52 AM
|
Registered User
|
|
Join Date: May 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi eNJay,
Thanks very much for ur curious attachment with my problem. I got the point now, the problem was with my tomcat version rather than code.
Previously, i was using tomcat 4.0 console version and then migrated to tomcat 5.5 running as a service.
This was the main problem. But when i run tomcat 5.5 from within console, IT WORKED as before.
THANKS anyway.
raj
|
May 30th, 2006, 01:18 AM
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanx for the update.
Interesting. Just wondering as to what might have broken when the server was running as service..
Regards,
eNJay
|
July 12th, 2006, 11:30 PM
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Raj,
Pls let me know the command, how u r executing this program. I am trying as below :
java UploadFile classpath.txt \\sys1203\\Ram
|
July 13th, 2006, 02:53 AM
|
Friend of Wrox
|
|
Join Date: Jan 2006
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Maybe I'm completely confused, but why aren't you calling the connect() method on your URLConnection object? I'm surprised the code worked without it on Tomcat 4.x.
Jon Emerson
http://www.zoominfo.com/JonEmerson
|
|
|