Results 1 to 1 of 1
- 02-20-2011, 01:31 AM #1
Member
- Join Date
- Jul 2010
- Posts
- 2
- Rep Power
- 0
InputStream/Response from Servlet fails: why?
Hello
I have an applet (where the user logins) & on pressing login button I send the login details to my servlet. In my applet, the function responsible for sending the login details to the servelt & receiving the servlet response object FAILS.
My problem is: I dont know why my function sendObject( Object o ) fails & I dont know how to fix it. Could you help me understand what is wrong & why?
I am using Apache 7.0. I think that receiving the response (getting the input stream) from the servlet fails but I dont know why & logging in was working fine the other day so I know my WEB-INF folder is set up fine & the web.xml is fine.
My function (I document where the function fails):
Java Console Output:Java Code:public ArrayList <Object> sendObject( Object o ) { try { URL servletUrl = new URL( this.getCodeBase(), "Updater" ); // "http://localhost:8080/" ); URLConnection conn = servletUrl.openConnection(); conn.setDoInput( true ); conn.setDoOutput( true ); conn.setUseCaches( false ); conn.setRequestProperty( "Content-Type", "application/x-java-serialized-object" ); OutputStream out = conn.getOutputStream(); ObjectOutputStream objOut = new ObjectOutputStream( out ); objOut.writeObject( o ); objOut.flush(); objOut.close(); // receive result from servlet System.out.println( "Result from applet.getCodeBase()=" + this.getCodeBase() ); // The following line is where I get the exception thrown InputStream instr = conn.getInputStream(); ObjectInputStream inputFromServlet = new ObjectInputStream(instr); ArrayList <Object> result = (ArrayList <Object>) inputFromServlet.readObject(); inputFromServlet.close(); instr.close(); System.out.println( "Contents of output is " ); for (int i=0; i<result.size(); i++) { System.out.println( "" + result.get(i) ); } return result; } catch ( IOException e ) { System.out.println( "In sendObject(): " + e ); } catch ( Exception e ) { System.out.println( "In sendObject(): " + e ); } return null; }
From the Apache log:Result from applet.getCodeBase() = http://localhost:8080/Updater/
In sendObject(): java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/Updater/Updater
localhost_access_log...:20/02/2011 11:15:08 AM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
20/02/2011 11:15:08 AM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
20/02/2011 11:15:23 AM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet Updater as unavailable
20/02/2011 11:15:23 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet Updater
java.lang.NullPointerException
at javax.servlet.GenericServlet.getServletContext(Gen ericServlet.java:125)
at UpdaterServlet.<init>(UpdaterServlet.java:32) // REFER BELOW TO SEE LINE 32 OF THIS FILE
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.apache.catalina.core.DefaultInstanceManager.ne wInstance(DefaultInstanceManager.java:119)
at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.java:1048)
at org.apache.catalina.core.StandardWrapper.allocate( StandardWrapper.java:799)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:135)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:161)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(A ccessLogValve.java:541)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:383)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProce ssor.run(JIoEndpoint.java:288)
at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
at java.lang.Thread.run(Unknown Source)
127.0.0.1 - - [20/Feb/2011:11:15:12 +1100] "GET /Updater/index.html HTTP/1.1" 304 -
127.0.0.1 - - [20/Feb/2011:11:15:15 +1100] "GET /Updater/UpdaterApplet.class HTTP/1.1" 304 -
127.0.0.1 - - [20/Feb/2011:11:15:15 +1100] "GET /Updater/ContentTree.class HTTP/1.1" 304 -
127.0.0.1 - - [20/Feb/2011:11:15:15 +1100] "GET /Updater/ContentMap.class HTTP/1.1" 304 -
127.0.0.1 - - [20/Feb/2011:11:15:15 +1100] "GET /Updater/UpdaterApplet$1.class HTTP/1.1" 304 -
127.0.0.1 - - [20/Feb/2011:11:15:15 +1100] "GET /Updater/SQLInterface.class HTTP/1.1" 304 -
127.0.0.1 - - [20/Feb/2011:11:15:23 +1100] "GET /Updater/ObjSerializationInterface.class HTTP/1.1" 304 -
127.0.0.1 - - [20/Feb/2011:11:15:23 +1100] "POST /Updater/Updater HTTP/1.1" 500 3117
This is the UpdaterServlet.java file (if you see above theres an error at line 32 of this file):
Java Code:public class UpdaterServlet extends HttpServlet { // Class Variables: private static final long serialVersionUID = 1L; private ArrayList <File> localDatabases; private ArrayList <ArrayList <Object>> input; private ArrayList <ArrayList <Object>> output; // Class Methods: public UpdaterServlet() { getServletContext().log( "File open/created" ); // LINE 32 localDatabases = new ArrayList <File>();
Similar Threads
-
connection fails
By jrjan in forum Advanced JavaReplies: 3Last Post: 01-10-2009, 12:15 AM -
Repaint fails when using threads
By rjevans2000 in forum Threads and SynchronizationReplies: 1Last Post: 09-21-2007, 11:22 PM -
Repaint fails when using threads
By rjevans2000 in forum AWT / SwingReplies: 3Last Post: 08-15-2007, 05:42 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks