File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Server returned HTTP response code: 504 for URL... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Server returned HTTP response code: 504 for URL..." Watch "Server returned HTTP response code: 504 for URL..." New topic
Author

Server returned HTTP response code: 504 for URL...

may Lee
Ranch Hand

Joined: Nov 20, 2003
Posts: 68
My websbite (Apache) uses private IP address and is publihsed by a Microsoft ISA proxy server. Public Internet users can access the website through the proxy server.

On my website, it uses applet to send date to servlet (they are on the same computer), then servlet searches data according to the date from applet and send the data back to applet. When the date is less than one day long, it works well, when the date is more than one day, it shows the following error:

java.io.IOException: Server returned HTTP response code: 504 for URL:http://11.11.11.11:8080/myservlet/servlet/...'

The servlet and applet use ObjectInputStream and ObjectOutputStream to communication with each other.

I check the error code, it is said:
Status code (504) indicating that the server did not receive a timely response from the upstream server while acting as a gateway or proxy.

But I still don't understand the error clearly, and how to solve the problem? Thanks for any suggestion!
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

My guess (without seeing the servlet code) is that there is a bug in the servlet causing it to go into an infinite loop under the conditions you see. Try moving the code to a stand-alone class and testing it outside the servlet container, or attaching a debugger to your servlet to trace the behaviour.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

On a side note, it looks like you're using the 'Invoker Servlet' to access your servlets. This is generally frowned on since it can cause security and general application problems. The preferred way to access servlets is to disable the invoker servlet and provide the correct servlet configuration in the web.xml file.

Just in case you're wondering what I mean, the path /[context]/servlet/... hints that the invoker servlet is being used.

Dave
[ September 18, 2005: Message edited by: David O'Meara ]
may Lee
Ranch Hand

Joined: Nov 20, 2003
Posts: 68
I did a test with my program without passing throguh the proxy server, I mean all
are on the private network, the webserver only on the private LAN and I access the website from LAN, there is no any map between private and public IP address for applet CODEBASE and servlet path, then it works well even for long time period, eg 5 days. SO I guess, it may be some timeout problem on the ISA proxy server when the mapping between private and public IP address is timeout.

Because when users ask data of long time period, say more than one day, the servlet takes at least more than 6-7 minutes to get all the data on the LAN, if asking for 5 days' data, it will take maybe 20 minutes to get the data, so maybe the mapping on ISA proxy server or the HTTP connection between servlet and applet cannot exist so long?

I am still looking for solutions. Any suggestion is appreciated. Thanks a lot.
may Lee
Ranch Hand

Joined: Nov 20, 2003
Posts: 68
Here is part of my code in applet and servlet, not complete of course:

(1) Part code of applet

/*In the applet code, I define the servlet path like this*/
String servletPath="http://192.168.0.24/myservlet/servlet/servletToapplet";

/* This is part of the applet code to send date to servlet*/
try{
URL url=new URL(servletPath);
URLConnection conn=url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setDefaultUseCaches(false);
/****send object from applet to servlet******************/
conn.setRequestProperty("Content-Type","application/octet-stream");
ObjectOutputStream toServlet=new ObjectOutputStream(conn.getOutputStream());
toServlet.writeObject(datato);
toServlet.flush();
toServlet.close();
/****get object df from servlet*********/
ObjectInputStream fromServlet=new ObjectInputStream(conn.getInputStream());
datafrom=(dataFromservlet)fromServlet.readObject();
fileexist=datafrom.fileexist;
servleterror=datafrom.servleterror;

}

(2)
/* This is part of servlet code, to show how servlet get date from applet and*/

try{
/****servlet gets input stream from applet***********************/
fromApplet=new ObjectInputStream(request.getInputStream());
/**read the serialized object (dataToservlet) from applet**/
dt=(dataToservlet) fromApplet.readObject();
fromApplet.close();
....


(3)
/*this is part of the servlet code to show how servlet send data back to applet by object*/
response.setContentType("java-internal/"+dataFromservlet.class.getName());
toApplet=new ObjectOutputStream(response.getOutputStream());
toApplet.writeObject(df);
toApplet.flush();
toApplet.close();
may Lee
Ranch Hand

Joined: Nov 20, 2003
Posts: 68
I am not clear what to do with the invoker. The following is my web.xml for the servlet under Tomcat. How to change? Could you show me?

<?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>servletToapplet</servlet-name>
<servlet-class>servletToapplet</servlet-class>
</servlet>


<servlet-mapping>

<servlet-name>invoker</servlet-name>

<url-pattern>/servlet/*</url-pattern>

</servlet-mapping>



<servlet-mapping>
<servlet-name>servletToapplet</servlet-name>
<url-pattern>/servletToapplet</url-pattern>
</servlet-mapping>


</web-app>
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

As Ben is fold (and correct) of saying, you should see this:
http://faq.javaranch.com/view?InvokerServlet
may Lee
Ranch Hand

Joined: Nov 20, 2003
Posts: 68
I found the solution for my problem. Share it here, hope it can give people some idea when they meet similar problems.

The error is because of the CODEBASE and servletPath. I am using proxy server to publish my website. Before I used private IP addresse for the CODEBASE and servletPath. So I changed them to the public IP address and make map of the public and private IP address on the proxy server. Now it is working.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Thanks, May Lee for sharing the solution. Congrats you got it work.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Server returned HTTP response code: 504 for URL...