wood burning stoves 2.0*
The moose likes Servlets and the fly likes java.io.IOException: Server returned HTTP response code: 500 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "java.io.IOException: Server returned HTTP response code: 500" Watch "java.io.IOException: Server returned HTTP response code: 500" New topic
Author

java.io.IOException: Server returned HTTP response code: 500

James Gadbury
Greenhorn

Joined: Mar 20, 2009
Posts: 24
Hi all,

I have an Applet that is attempting to communicate with a Servlet. The servlet should - when prompted by the Applet - connect to a mySQL database called GTDB, return all rows from a table called 'TUNES' (basically car setups), create serialisable Tune objects, add them to an ArrayList, and return the whole list of Tunes to the Applet. Credit to Chad's tutorial here: http://www.j-nine.com/pubs/applet2servlet/index.htm

I'm not sure where to start with these problems I've been going round in circles for the last 24 hours searching the net (some results from here) and trying things. I have had a host of problems (fileNotFound / classNotFound / classDefNotFound) and as I have gone through fixing them, other ones seem to crop up / come back!

Here is the latest error: java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/GTDBServlet/GTDBServlet

Here is all my code listings:

Applet side:

GTDB_Applet - http://rafb.net/p/oFgFtI58.html
MainJPanel - http://rafb.net/p/ehX4h159.html - consists of a JTable and a button. When the button is clicked, GTDB_Applet::getTunesList is called and a request should be sent to the Sevlet. Line 194 has the ActionListner on an update button, line 164 is the displayTunes method that populates the JTable


Servlet side:

GTDBServlet - http://rafb.net/p/EZHuYb41.html
TuneDataAccessor - http://rafb.net/p/H0pfjy41.html (helps out with the SQL)


Other files:

.classpath - http://rafb.net/p/1VvE4Y69.html (in GTPServlet project folder)
web.xml - http://rafb.net/p/xto3zB73.html (in GTDBServlet\WEB-INF)


I am using XAMPP v1.7 for Windows (XP SP3) which includes Apache, mySQL 5 and Tomcat 6. I have a working 'SimpleServlet' demo that I created using this tutorial (step 9): http://plato.acadiau.ca/courses/comp/dsilver/2513/EclipseAndTomcatTutorial/. When I navigate to http://localhost:8080/ServletDemo/SimpleServlet, SimpleServlet works. So I have used this example as a basis to get my GTDBServlet up and running, copying the file structure / layout. However, if a navigate to http://localhost:8080/GTDBServlet/GTDBServlet, I get the message:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet.init() for servlet GTDBServlet threw exception
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Unknown Source)

root cause

java.lang.NullPointerException
TunesDataAccessor.cleanUp(TunesDataAccessor.java:48)
TunesDataAccessor.<init>(TunesDataAccessor.java:38)
GTDBServlet.init(GTDBServlet.java:44)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Unknown Source)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.


-------------------------------------------------------


Here are my errors from the Eclipse console when I try to run GTDB_Applet:


java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/GTDBServlet/GTDBServlet
Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
at GTDB_Applet.MainJPanel.displayTunes(MainJPanel.java:180)
at GTDB_Applet.MainJPanel.refreshListButtonActionPerformed(MainJPanel.java:211)
at GTDB_Applet.MainJPanel.access$1(MainJPanel.java:207)
at GTDB_Applet.MainJPanel$2.actionPerformed(MainJPanel.java:100)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

I have also had this error:

java.net.SocketException: Connection reset
Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
at GTDB_Applet.MainJPanel.displayTunes(MainJPanel.java:180)
at GTDB_Applet.MainJPanel.refreshListButtonActionPerformed(MainJPanel.java:211)
at GTDB_Applet.MainJPanel.access$1(MainJPanel.java:207)
at GTDB_Applet.MainJPanel$2.actionPerformed(MainJPanel.java:100)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


GTDBServlet is the name of the project folder that resides alongside ServletDemo on my XAMPP web server (located K:\Program Files\XAMPP\htdocs). The project structure is the same as ServletDemo. GTDBServlet is also the class name of my Servlet. So I believe my webxml file and the path http://localhost:8080/GTDBServlet/GTDBServlet to be correct.

I followed these instructions to try and configure the Tomcat SSL: http://tomcat.apache.org/tomcat-5.5-doc/ssl-howto.html. Someone elsewhere advised to do so to resolve java.io.IOException: Server returned HTTP response code: 500 for URL

If anyone can offer any pointers or advice, I'd be very gratetful. Going to bed after a long day trying to resolve this one problem is getting disheartening, yet I feel close to my first breakthrough and first Applet > Servlet > DB setup! Thanks for read and any help in advance!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Response code 500 means that there was an error on the server.

I didn't notice anything in your post which said you looked in the server's logs to find out what the error was. (Sorry if I missed it, if you did say that.) Anyway, that's what you should do. It's possible the error was caused by your applet sending a bad request, but that's still a problem which should be fixed on the server.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
NullPointerException is a RuntimeException which is in general just a developer fault. Fix the code accordingly and see further.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12756
    
    5
The key line is:

javax.servlet.ServletException: Servlet.init() for servlet GTDBServlet threw exception

if init throws an exception, the server marks that servlet as unavailabe - as you have seen.

There is no sense chasing anything else until you can get the servlet to init() correctly.

Bill
James Gadbury
Greenhorn

Joined: Mar 20, 2009
Posts: 24
Hi,

First of all, thanks for the responses and your time. Having taken on the advice given, I found my (Tomcat server) logs and searched around for solutions.

I have got to the bottom of the servlet initialisation error - there was a problem with DriverManager.getConnection(dbURL, userID, password); in my TunesDataAccessor class; the path and port for the MySql database were incorrect and I also had an issue with Class.forName(&amp;quot;com.mysql.jdbc.Driver&amp;quot;).newInstance(); not functioning (I had to add the MySql J/ Connector driver to my classpath).

I have since had hours of trying to resolve a runtime error of java.lang.ClassNotFoundException: Tune. Tune is a class that implements the serializable interface so I can send serialized objects between the Applet and Servlet. I managed to fix this error and my application was working as I had hoped for the first time in days and then somehow - annoyingly - I have managed to reintroduce the error I think it is to do with my servlet project .classpath file (see it here: http://rafb.net/p/1VvE4Y69.html). I have been trying to learn by example and by reading tutorials on the classpath files, but I feel none-the-wiser.

Here is my servlet project file structure:




Is my classpath and file structure correct, or perhaps is it the cause of my troubles? I know the data is being retrieved from the database, and being passed to the Tune(ResultSet) constructor, as I am using getter methods to print the values of a temporary Tune object to read its member variables. This would suggest to me that the class is being dynamically loaded by the servlet at this point.

When the Applet receives the serialized Tune object from the Servlet, it also uses the Tune class to interpret the data. Would the Applet also dynamically load the Tune class? I guess it would... perhaps it is failing at the Applet and the Servlet is performing as it should...? Sorry to ramble on... I think I have been on this for too long today (I'me very tired!).

Would someone be kind enough to check out my servlet classpath and directory structure and see if it is correct or not...? If it is, why else could the dynamic loading of the Tune class fail at runtime?
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Where is this CNFE been thrown? By the applet? The Tune class should also be available in the classpath of the applet.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

Your servlet classes should be in a package other than the default.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
That also. All classes should be placed in a package, yes. This applies to all classes, not only servlet classes. You know, classes in the default package is invisible (un-importable) for classes in other packages.
James Gadbury
Greenhorn

Joined: Mar 20, 2009
Posts: 24
Thanks for the quick responses - some silly questions coming up from me...

The CNFE seems to be happening when an attempt to get the input stream is made by the applet (line 80, here: http://java.pastebin.ca/1367713).

I shall package the servlet classes. Should they be in a different named package from the applet's package?)

How do I ensure that Tune.class is being added to the classpath? I have looked at the Build Path Options options under Libraries in Eclipse, but I am unsure if it is Add Class Folder or Add Library (I would rather not add my class to a jar for the time being, to keep things simple). I have also looked at the Applet classpath (see below):



I should really get all of my code pasted back up but I am feeling exhausted and will do that if needs be tomorrow - I originally pasted it all up neatly and it has gone from the pastebin already

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.io.IOException: Server returned HTTP response code: 500
 
Similar Threads
java.io.FileNotFoundException: http://localhost:8080/MyServlets/MyServlet
WAMP/Java/MysqlConnector Issue
HTTP.java in ranch --problem
Please HELP!!! URGENT!!! java.io.IOException: Connection failure with 407
Applet freezes with itext