-----------------------------
Please read the FAQ!
<http://java.apache.org/faq/>
-----------------------------

[EMAIL PROTECTED] wrote:

> [snip]

> Craig, you are right. Server is returning an error
> because there is some intenal error within
> JServ/servlet.  This happens only with javascript.
> No problem with HTML.
>

The first thing that would be useful is the text of the rest of the error message 
(i.e. the next few
lines after the DOCTYPE line).  That will tell you what error Apache is concerned 
about, although it
sounds like it might be a generic "Error 500: Internal Server Error" from the sounds 
of the rest of the
problem.

>
> I see the following error in JServ mod_jserv.log file :
>
> [21/09/1999 06:28:34:900] (EMERGENCY) ajp11: cannot scan servlet headers
> [21/09/1999 06:28:34:900] (ERROR) an error returned handling request via protocol 
>"ajpv11"
>

There are many possible causes for this, but the most likely is an unchecked exception 
(like a
NullPointerException) in the servlet code, or Java code called by that servlet.  You 
should also be
seeing a stack traceback in the logs that tells you where the error actually occurred.

>
> When and why does this error occur ?
> This might be too often asked error on this list. But,
> I couldn't find relevant info in docs or faqs.
>
> My servlet code is as follows :
>
> import java.io.*;
> import java.net.*;
> import java.util.*;
> import java.lang.reflect.*;
>
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class MyServlet extends HttpServlet {
>
>     public String getServletInfo() {
>         return "MyServlet 1.0 by Ramesh";
>     }
>
>     public void doGet(HttpServletRequest req, HttpServletResponse res)
>                                 throws IOException {
>
>        MyServletBackend backend = new MyServletBackend();
>        backend.doGet(req, res);
>
>     }
> }
>

Well, it's unlikely that you got any exceptions out of this code itself -- but an 
exception that occurs
inside the MyServletBackend class will cause exactly the same problems as an exception 
in the servlet
itself.  One way to help track it down would be to make sure you have JServ logging 
enabled, and then
change your doGet method like this:

    public void doGet(HttpServletRequest req, HttpServletResponse res)
        throws IOException {

        MyServletBackend backend = null;
        try {
            backend = new MyServletBackend();
            backend.doGet(req, res);
        } catch (Exception e) {
            log(e, "MyBackend Threw An Exception!");
        }

    }

This will log the error message and stack trace for the exception to the JServ log 
file.  In addition,
because the exception was swallowed by your servlet instead of being passed on to 
Apache JServ, you
shouldn't trigger the Apache error.  The output will either have nothing at all, or be 
partially
completed, depending on how far in the error occurred.

>
> That's all is in the servlet.  For simplicity, I put everything else in 
>MyServletBackend to workaround
> concurrency problems though there is a better way
> using  "sychronized"
>

Putting everything in the back end like this will actually perform better, if you can 
afford the memory
space for the multiple MyBackend objects that might be created for simultaneous 
requests.  However, if
the MyBackend class uses shared resources internally in an unsafe manner, this does 
nothing by itself to
take care of multithreading problems.

>
> If I use MyServletBackend directly, this error doesn't
> come, however, I face multi threading issues.
>

Yep, that would be consistent with what we are seeing (if MyBackend throws an 
exception, you see an
Apache error).  The stack trace is a key tool in figuring out exactly where the 
problem occurred,
although we obviously can't help you much with what is actually going wrong without 
the code.

Programming for a multithreading server is fundamentally the art of being paranoid -- 
ask yourself "what
is the worst possible combination of simultaneous requests that can happen" and 
programming to make sure
that this situation is handled correctly, because it's bound to happen at some point 
in real life.  Once
you get that one fixed, go to the second-worst situation and so on, until you think 
you have them all.
But don't be surprised if you miss some.

It's difficult to test these kind of things, but you might want to create a testbed 
program that runs
multiple threads so that you can simulate what really happens when running inside the 
servlet engine.

>
> Thanks all for your help. I am heading in the
> right direction.
>
> Ramesh
>

Craig McClanahan




--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html>
Problems?:           [EMAIL PROTECTED]

Reply via email to