Search in sources :

Example 1 with PageServletException

use of lucee.runtime.exp.PageServletException in project Lucee by lucee.

the class RPCServer method doGet.

/**
 * Process GET requests. This includes handoff of pseudo-SOAP requests
 *
 * @param request request in
 * @param response request out
 * @throws ServletException
 */
public void doGet(HttpServletRequest request, HttpServletResponse response, Component component) throws ServletException {
    PrintWriter writer = new FilterPrintWriter(response);
    try {
        if (!doGet(request, response, writer, component)) {
            ReqRspUtil.setContentType(response, "text/html; charset=utf-8");
            writer.println("<html><h1>" + lucee.runtime.config.Constants.NAME + " Webservice</h1>");
            writer.println(Messages.getMessage("reachedServlet00"));
            writer.println("<p>" + Messages.getMessage("transportName00", "<b>http</b>"));
            writer.println("</html>");
        }
    } catch (Throwable e) {
        ExceptionUtil.rethrowIfNecessary(e);
        if (e instanceof InvocationTargetException)
            e = ((InvocationTargetException) e).getTargetException();
        if (e instanceof PageException)
            throw new PageServletException((PageException) e);
        throw new ServletException(e);
    }
}
Also used : ServletException(javax.servlet.ServletException) PageServletException(lucee.runtime.exp.PageServletException) PageException(lucee.runtime.exp.PageException) FilterPrintWriter(org.apache.axis.transport.http.FilterPrintWriter) PageServletException(lucee.runtime.exp.PageServletException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PrintWriter(java.io.PrintWriter) FilterPrintWriter(org.apache.axis.transport.http.FilterPrintWriter)

Example 2 with PageServletException

use of lucee.runtime.exp.PageServletException in project Lucee by lucee.

the class CFMLEngineImpl method _service.

private void _service(HttpServlet servlet, HttpServletRequest req, HttpServletResponse rsp, short type) throws ServletException, IOException {
    CFMLFactoryImpl factory = (CFMLFactoryImpl) getCFMLFactory(servlet.getServletConfig(), req);
    // is Lucee dialect enabled?
    if (type == Request.TYPE_LUCEE) {
        if (!((ConfigImpl) factory.getConfig()).allowLuceeDialect()) {
            try {
                PageContextImpl.notSupported();
            } catch (ApplicationException e) {
                throw new PageServletException(e);
            }
        }
    }
    boolean exeReqAsync = exeRequestAsync();
    PageContextImpl pc = factory.getPageContextImpl(servlet, req, rsp, null, false, -1, false, !exeReqAsync, false, -1, true, false, false);
    try {
        Request r = new Request(pc, type);
        if (exeReqAsync) {
            r.start();
            long ended = -1;
            do {
                SystemUtil.wait(Thread.currentThread(), 1000);
                // done?
                if (r.isDone()) {
                    // print.e("mas-done:"+System.currentTimeMillis());
                    break;
                } else // reach request timeout
                if (ended == -1 && (pc.getStartTime() + pc.getRequestTimeout()) < System.currentTimeMillis()) {
                    // print.e("req-time:"+System.currentTimeMillis());
                    CFMLFactoryImpl.terminate(pc, false);
                    ended = System.currentTimeMillis();
                // break; we do not break here, we give the thread itself the chance to end we need the exception output
                } else // the thread itself seem blocked, so we release this thread
                if (ended > -1 && ended + 10000 <= System.currentTimeMillis()) {
                    // print.e("give-up:"+System.currentTimeMillis());
                    break;
                }
            } while (true);
        } else // run in thread coming from servlet engine
        {
            try {
                Request.exe(pc, type, true, false);
            } catch (RequestTimeoutException rte) {
                if (rte.getThreadDeath() != null)
                    throw rte.getThreadDeath();
            } catch (NativeException ne) {
                if (ne.getCause() instanceof ThreadDeath)
                    throw (ThreadDeath) ne.getCause();
            } catch (ThreadDeath td) {
                throw td;
            } catch (Throwable t) {
            }
        }
    } finally {
        factory.releaseLuceePageContext(pc, !exeReqAsync);
    }
}
Also used : RequestTimeoutException(lucee.runtime.exp.RequestTimeoutException) ApplicationException(lucee.runtime.exp.ApplicationException) CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) PageServletException(lucee.runtime.exp.PageServletException) PageContextImpl(lucee.runtime.PageContextImpl) NativeException(lucee.runtime.exp.NativeException)

Example 3 with PageServletException

use of lucee.runtime.exp.PageServletException in project Lucee by lucee.

the class CFMLEngineImpl method getConfigDirectory.

/**
 * loads Configuration File from System, from init Parameter from web.xml
 *
 * @param sg
 * @param configServer
 * @param countExistingContextes
 * @return return path to directory
 */
private Resource getConfigDirectory(ServletConfig sg, ConfigServerImpl configServer, int countExistingContextes, RefBoolean isCustomSetting) throws PageServletException {
    isCustomSetting.setValue(true);
    ServletContext sc = sg.getServletContext();
    String strConfig = sg.getInitParameter("configuration");
    if (StringUtil.isEmpty(strConfig))
        strConfig = sg.getInitParameter("lucee-web-directory");
    if (StringUtil.isEmpty(strConfig))
        strConfig = System.getProperty("lucee.web.dir");
    if (StringUtil.isEmpty(strConfig)) {
        isCustomSetting.setValue(false);
        strConfig = "{web-root-directory}/WEB-INF/lucee/";
    } else // only for backward compatibility
    if (strConfig.startsWith("/WEB-INF/lucee/"))
        strConfig = "{web-root-directory}" + strConfig;
    strConfig = StringUtil.removeQuotes(strConfig, true);
    // static path is not allowed
    if (countExistingContextes > 1 && strConfig != null && strConfig.indexOf('{') == -1) {
        String text = "static path [" + strConfig + "] for servlet init param [lucee-web-directory] is not allowed, path must use a web-context specific placeholder.";
        System.err.println(text);
        throw new PageServletException(new ApplicationException(text));
    }
    strConfig = SystemUtil.parsePlaceHolder(strConfig, sc, configServer.getLabels());
    ResourceProvider frp = ResourcesImpl.getFileResourceProvider();
    Resource root = frp.getResource(ReqRspUtil.getRootPath(sc));
    Resource res;
    Resource configDir = ResourceUtil.createResource(res = root.getRealResource(strConfig), FileUtil.LEVEL_PARENT_FILE, FileUtil.TYPE_DIR);
    if (configDir == null) {
        configDir = ResourceUtil.createResource(res = frp.getResource(strConfig), FileUtil.LEVEL_GRAND_PARENT_FILE, FileUtil.TYPE_DIR);
    }
    if (configDir == null && !isCustomSetting.toBooleanValue()) {
        try {
            res.createDirectory(true);
            configDir = res;
        } catch (IOException e) {
            throw new PageServletException(Caster.toPageException(e));
        }
    }
    if (configDir == null) {
        throw new PageServletException(new ApplicationException("path [" + strConfig + "] is invalid"));
    }
    if (!configDir.exists() || ResourceUtil.isEmptyDirectory(configDir, null)) {
        Resource railoRoot;
        // there is a railo directory
        if (configDir.getName().equals("lucee") && (railoRoot = configDir.getParentResource().getRealResource("railo")).isDirectory()) {
            try {
                copyRecursiveAndRename(railoRoot, configDir);
            } catch (IOException e) {
                try {
                    configDir.createDirectory(true);
                } catch (IOException ioe) {
                }
                return configDir;
            }
            // zip the railo-server di and delete it (optional)
            try {
                Resource p = railoRoot.getParentResource();
                CompressUtil.compress(CompressUtil.FORMAT_ZIP, railoRoot, p.getRealResource("railo-web-context-old.zip"), false, -1);
                ResourceUtil.removeEL(railoRoot, true);
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
        } else {
            try {
                configDir.createDirectory(true);
            } catch (IOException e) {
            }
        }
    }
    return configDir;
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) ResourceProvider(lucee.commons.io.res.ResourceProvider) Resource(lucee.commons.io.res.Resource) ServletContext(javax.servlet.ServletContext) PageServletException(lucee.runtime.exp.PageServletException) IOException(java.io.IOException)

Example 4 with PageServletException

use of lucee.runtime.exp.PageServletException in project Lucee by lucee.

the class BodyTagTryCatchFinallyImpl method doCatch.

@Override
public void doCatch(Throwable t) throws Throwable {
    ExceptionUtil.rethrowIfNecessary(t);
    if (t instanceof PageServletException) {
        PageServletException pse = (PageServletException) t;
        t = pse.getPageException();
    }
    if (bodyContent != null) {
        if (t instanceof AbortException) {
            bodyContent.writeOut(bodyContent.getEnclosingWriter());
        }
        bodyContent.clearBuffer();
    }
    throw t;
}
Also used : PageServletException(lucee.runtime.exp.PageServletException) AbortException(lucee.runtime.exp.AbortException)

Example 5 with PageServletException

use of lucee.runtime.exp.PageServletException in project Lucee by lucee.

the class CFTag method _doCFCCatch.

public void _doCFCCatch(Throwable t, String source, boolean throwIfCFCNotExists) throws PageException {
    writeEnclosingWriter();
    // remove PageServletException wrap
    if (t instanceof PageServletException) {
        PageServletException pse = (PageServletException) t;
        t = pse.getPageException();
    }
    // abort
    try {
        if (lucee.runtime.exp.Abort.isAbort(t)) {
            if (bodyContent != null) {
                bodyContent.writeOut(bodyContent.getEnclosingWriter());
                bodyContent.clearBuffer();
            }
            throw Caster.toPageException(t);
        }
    } catch (IOException ioe) {
        throw Caster.toPageException(ioe);
    }
    if (throwIfCFCNotExists && cfc == null)
        throw Caster.toPageException(t);
    try {
        if (cfc != null && cfc.contains(pageContext, ON_ERROR)) {
            PageException pe = Caster.toPageException(t);
            // Object rtn=cfc.call(pageContext, ON_ERROR, new Object[]{pe.getCatchBlock(pageContext),source});
            Struct args = new StructImpl(Struct.TYPE_LINKED);
            args.set(CFCATCH, pe.getCatchBlock(ThreadLocalPageContext.getConfig(pageContext)));
            args.set(SOURCE, source);
            Object rtn = cfc.callWithNamedValues(pageContext, ON_ERROR, args);
            if (Caster.toBooleanValue(rtn, false))
                throw t;
        } else
            throw t;
    } catch (Throwable th) {
        ExceptionUtil.rethrowIfNecessary(th);
        writeEnclosingWriter();
        _doCFCFinally();
        throw Caster.toPageException(th);
    }
    writeEnclosingWriter();
}
Also used : PageException(lucee.runtime.exp.PageException) StructImpl(lucee.runtime.type.StructImpl) PageServletException(lucee.runtime.exp.PageServletException) IOException(java.io.IOException) Struct(lucee.runtime.type.Struct)

Aggregations

PageServletException (lucee.runtime.exp.PageServletException)7 ApplicationException (lucee.runtime.exp.ApplicationException)3 IOException (java.io.IOException)2 ServletContext (javax.servlet.ServletContext)2 PageException (lucee.runtime.exp.PageException)2 PrintWriter (java.io.PrintWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 ServletException (javax.servlet.ServletException)1 ServletRequest (javax.servlet.ServletRequest)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Resource (lucee.commons.io.res.Resource)1 ResourceProvider (lucee.commons.io.res.ResourceProvider)1 CFMLFactoryImpl (lucee.runtime.CFMLFactoryImpl)1 PageContextImpl (lucee.runtime.PageContextImpl)1 AbortException (lucee.runtime.exp.AbortException)1 NativeException (lucee.runtime.exp.NativeException)1 RequestTimeoutException (lucee.runtime.exp.RequestTimeoutException)1 Struct (lucee.runtime.type.Struct)1 StructImpl (lucee.runtime.type.StructImpl)1