Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java Open Source > Apache Tomcat
|
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
 
Old May 15th, 2006, 07:53 AM
Registered User
 
Join Date: May 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
 
Old May 18th, 2006, 11:32 AM
Authorized User
 
Join Date: Apr 2005
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Can you outline the problems?

A stacktrace of the same will help

Regards,
eNJay

 
Old May 19th, 2006, 07:39 AM
Registered User
 
Join Date: May 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old May 19th, 2006, 03:29 PM
Authorized User
 
Join Date: Apr 2005
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old May 22nd, 2006, 01:52 AM
Registered User
 
Join Date: May 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old May 24th, 2006, 07:20 AM
Authorized User
 
Join Date: Apr 2005
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old May 25th, 2006, 12:52 AM
Registered User
 
Join Date: May 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old May 30th, 2006, 01:18 AM
Authorized User
 
Join Date: Apr 2005
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx for the update.

Interesting. Just wondering as to what might have broken when the server was running as service..

Regards,
eNJay

 
Old July 12th, 2006, 11:30 PM
Authorized User
 
Join Date: Mar 2006
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Raj,

Pls let me know the command, how u r executing this program. I am trying as below :

java UploadFile classpath.txt \\sys1203\\Ram

 
Old July 13th, 2006, 02:53 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Facing Problem in WSAD mvharish J2EE 0 May 25th, 2007 04:24 AM
i am facing a problem mkazim85 SQL Language 2 April 20th, 2007 07:28 AM
Facing problem with commandtimeout altaf SQL Server ASP 0 June 27th, 2003 08:33 AM
Facing problem with commandtimeout altaf Classic ASP Databases 0 June 27th, 2003 08:27 AM
Facing problem with commandtimeout altaf SQL Server 2000 0 June 27th, 2003 08:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.