/**
         * Service.
         */
        public override void service(HttpServletRequest request,
                                     HttpServletResponse response)

        {
            Env         env = null;
            WriteStream ws  = null;

            QuercusHttpServletRequest  req = new QuercusHttpServletRequestImpl(request);
            QuercusHttpServletResponse res = new QuercusHttpServletResponseImpl(response);

            try {
                string path = getPath(req);

                QuercusPage page;

                try {
                    page = getQuercus().parse(path);
                }
                catch (FileNotFoundException e) {
                    // php/2001
                    log.log(Level.FINER, e.ToString(), e);

                    response.sendError(HttpServletResponse.SC_NOT_FOUND);

                    return;
                }

                ws = openWrite(response);

                // php/2002
                // for non-Resin containers
                // for servlet filters that do post-request work after Quercus
                ws.setDisableCloseSource(true);

                // php/6006
                ws.setNewlineString("\n");

                QuercusContext quercus = getQuercus();

                env = quercus.createEnv(page, ws, req, res);

                // php/815d
                env.setPwd(path.getParent());

                quercus.setServletContext(new QuercusServletContextImpl(_servletContext));

                try {
                    env.start();

                    // php/2030, php/2032, php/2033
                    // Jetty hides server classes from web-app
                    // http://docs.codehaus.org/display/JETTY/Classloading
                    //
                    // env.setGlobalValue("request", env.wrapJava(request));
                    // env.setGlobalValue("response", env.wrapJava(response));
                    // env.setGlobalValue("servletContext", env.wrapJava(_servletContext));

                    StringValue prepend
                        = quercus.getIniValue("auto_prepend_file").ToStringValue(env);
                    if (prepend.length() > 0)
                    {
                        string prependPath = env.lookup(prepend);

                        if (prependPath == null)
                        {
                            env.error(L.l("auto_prepend_file '{0}' not found.", prepend));
                        }
                        else
                        {
                            QuercusPage prependPage = getQuercus().parse(prependPath);
                            prependPage.executeTop(env);
                        }
                    }

                    env.executeTop();

                    StringValue append
                        = quercus.getIniValue("auto_append_file").ToStringValue(env);
                    if (append.length() > 0)
                    {
                        string appendPath = env.lookup(append);

                        if (appendPath == null)
                        {
                            env.error(L.l("auto_append_file '{0}' not found.", append));
                        }
                        else
                        {
                            QuercusPage appendPage = getQuercus().parse(appendPath);
                            appendPage.executeTop(env);
                        }
                    }
                    //   return;
                }
                catch (QuercusExitException e) {
                    throw e;
                }
                catch (QuercusErrorException e) {
                    throw e;
                }
                catch (QuercusLineRuntimeException e) {
                    log.log(Level.FINE, e.ToString(), e);

                    ws.println(e.getMessage());
                    //  return;
                }
                catch (QuercusValueException e) {
                    log.log(Level.FINE, e.ToString(), e);

                    ws.println(e.ToString());

                    //  return;
                }
                catch (StackOverflowError e) {
                    RuntimeException myException
                        = new RuntimeException(L.l("StackOverflowError at {0}", env.getLocation()), e);

                    throw myException;
                }
                catch (Throwable e) {
                    if (response.isCommitted())
                    {
                        e.printStackTrace(ws.getPrintWriter());
                    }

                    ws = null;

                    throw e;
                }
                finally {
                    if (env != null)
                    {
                        env.close();
                    }

                    // don't want a flush for an exception
                    if (ws != null && env.getDuplex() == null)
                    {
                        ws.close();
                    }
                }
            }
            catch (QuercusDieException e) {
                // normal exit
                log.log(Level.FINE, e.ToString(), e);
            }
            catch (QuercusExitException e) {
                // normal exit
                log.log(Level.FINER, e.ToString(), e);
            }
            catch (QuercusErrorException e) {
                // error exit
                log.log(Level.FINE, e.ToString(), e);
            }
            catch (RuntimeException e) {
                throw e;
            }
            catch (Throwable e) {
                handleThrowable(response, e);
            }
        }
예제 #2
0
 public override bool HeadersSent()
 {
     return(_HttpServletResponse.isCommitted());
 }