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);
}
}
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);
}
}
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;
}
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;
}
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();
}
Aggregations