use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class ChildThreadImpl method execute.
public PageException execute(Config config) {
PageContext oldPc = ThreadLocalPageContext.get();
Page p = page;
PageContextImpl pc = null;
try {
// deamon
if (this.pc != null) {
pc = this.pc;
ThreadLocalPageContext.register(pc);
} else // task
{
ConfigWebImpl cwi;
try {
cwi = (ConfigWebImpl) config;
DevNullOutputStream os = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
pc = ThreadUtil.createPageContext(cwi, os, serverName, requestURI, queryString, SerializableCookie.toCookies(cookies), headers, null, parameters, attributes, true, -1);
pc.setRequestTimeout(requestTimeout);
p = PageSourceImpl.loadPage(pc, cwi.getPageSources(oldPc == null ? pc : oldPc, null, template, false, false, true));
// p=cwi.getPageSources(oldPc,null, template, false,false,true).loadPage(cwi);
} catch (PageException e) {
return e;
}
pc.addPageSource(p.getPageSource(), true);
}
threadScope = pc.getThreadScope(KeyConstants._cfthread, null);
pc.setCurrentThreadScope(new ThreadsImpl(this));
pc.setThread(Thread.currentThread());
// String encodings = pc.getHttpServletRequest().getHeader("Accept-Encoding");
Undefined undefined = pc.us();
Argument newArgs = new ArgumentThreadImpl((Struct) Duplicator.duplicate(attrs, false));
LocalImpl newLocal = pc.getScopeFactory().getLocalInstance();
// Key[] keys = attrs.keys();
Iterator<Entry<Key, Object>> it = attrs.entryIterator();
Entry<Key, Object> e;
while (it.hasNext()) {
e = it.next();
newArgs.setEL(e.getKey(), e.getValue());
}
newLocal.setEL(KEY_ATTRIBUTES, newArgs);
Argument oldArgs = pc.argumentsScope();
Local oldLocal = pc.localScope();
int oldMode = undefined.setMode(Undefined.MODE_LOCAL_OR_ARGUMENTS_ALWAYS);
pc.setFunctionScopes(newLocal, newArgs);
try {
p.threadCall(pc, threadIndex);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
if (!Abort.isSilentAbort(t)) {
ConfigWeb c = pc.getConfig();
if (c instanceof ConfigImpl) {
ConfigImpl ci = (ConfigImpl) c;
Log log = ci.getLog("thread");
if (log != null)
LogUtil.log(log, Log.LEVEL_ERROR, this.getName(), t);
}
PageException pe = Caster.toPageException(t);
if (!serializable)
catchBlock = pe.getCatchBlock(pc.getConfig());
return pe;
}
} finally {
completed = true;
pc.setFunctionScopes(oldLocal, oldArgs);
undefined.setMode(oldMode);
// pc.getScopeFactory().recycle(newArgs);
pc.getScopeFactory().recycle(pc, newLocal);
if (pc.getHttpServletResponse() instanceof HttpServletResponseDummy) {
HttpServletResponseDummy rsp = (HttpServletResponseDummy) pc.getHttpServletResponse();
pc.flush();
contentType = rsp.getContentType();
Pair<String, Object>[] _headers = rsp.getHeaders();
if (_headers != null)
for (int i = 0; i < _headers.length; i++) {
if (_headers[i].getName().equalsIgnoreCase("Content-Encoding"))
contentEncoding = Caster.toString(_headers[i].getValue(), null);
}
}
}
} finally {
pc.getConfig().getFactory().releaseLuceePageContext(pc, true);
pc = null;
if (oldPc != null)
ThreadLocalPageContext.register(oldPc);
}
return null;
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class ORMUtil method getDataSourceName.
public static String getDataSourceName(PageContext pc, Component cfc, String defaultValue) {
pc = ThreadLocalPageContext.get(pc);
// datasource defined with cfc
Struct meta = null;
try {
meta = cfc.getMetaData(pc);
String datasourceName = Caster.toString(meta.get(KeyConstants._datasource, null), null);
if (!StringUtil.isEmpty(datasourceName, true)) {
return datasourceName.trim();
}
} catch (PageException e) {
}
DataSource ds = getDefaultDataSource(pc, null);
if (ds != null)
return ds.getName();
return defaultValue;
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class OSGiUtil method toVersion.
public static Version toVersion(String version, Version defaultValue) {
if (StringUtil.isEmpty(version))
return defaultValue;
// String[] arr = ListUtil.listToStringArray(version, '.');
String[] arr;
try {
arr = ListUtil.toStringArrayTrim(ListUtil.listToArray(version.trim(), '.'));
} catch (PageException e) {
// should not happen
return defaultValue;
}
Integer major, minor, micro;
String qualifier;
if (arr.length == 1) {
major = Caster.toInteger(arr[0], null);
minor = 0;
micro = 0;
qualifier = null;
} else if (arr.length == 2) {
major = Caster.toInteger(arr[0], null);
minor = Caster.toInteger(arr[1], null);
micro = 0;
qualifier = null;
} else if (arr.length == 3) {
major = Caster.toInteger(arr[0], null);
minor = Caster.toInteger(arr[1], null);
micro = Caster.toInteger(arr[2], null);
qualifier = null;
} else {
major = Caster.toInteger(arr[0], null);
minor = Caster.toInteger(arr[1], null);
micro = Caster.toInteger(arr[2], null);
qualifier = arr[3];
}
if (major == null || minor == null || micro == null)
return defaultValue;
if (qualifier == null)
return new Version(major, minor, micro);
return new Version(major, minor, micro, qualifier);
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class Reflector method getConstructorInstance.
public static ConstructorInstance getConstructorInstance(Class clazz, Object[] args, ConstructorInstance defaultValue) {
args = cleanArgs(args);
// getConstructors(clazz);
Constructor[] constructors = cStorage.getConstructors(clazz, args.length);
if (constructors != null) {
Class[] clazzArgs = getClasses(args);
// exact comparsion
outer: for (int i = 0; i < constructors.length; i++) {
if (constructors[i] != null) {
Class[] parameterTypes = constructors[i].getParameterTypes();
for (int y = 0; y < parameterTypes.length; y++) {
if (toReferenceClass(parameterTypes[y]) != clazzArgs[y])
continue outer;
}
return new ConstructorInstance(constructors[i], args);
}
}
// like comparsion
outer: for (int i = 0; i < constructors.length; i++) {
if (constructors[i] != null) {
Class[] parameterTypes = constructors[i].getParameterTypes();
for (int y = 0; y < parameterTypes.length; y++) {
if (!like(clazzArgs[y], toReferenceClass(parameterTypes[y])))
continue outer;
}
return new ConstructorInstance(constructors[i], args);
}
}
// convert comparsion
ConstructorInstance ci = null;
int _rating = 0;
outer: for (int i = 0; i < constructors.length; i++) {
if (constructors[i] != null) {
RefInteger rating = (constructors.length > 1) ? new RefIntegerImpl(0) : null;
Class[] parameterTypes = constructors[i].getParameterTypes();
Object[] newArgs = new Object[args.length];
for (int y = 0; y < parameterTypes.length; y++) {
try {
newArgs[y] = convert(args[y], toReferenceClass(parameterTypes[y]), rating);
} catch (PageException e) {
continue outer;
}
}
if (ci == null || rating.toInt() > _rating) {
if (rating != null)
_rating = rating.toInt();
ci = new ConstructorInstance(constructors[i], newArgs);
}
// return new ConstructorInstance(constructors[i],newArgs);
}
}
return ci;
}
return defaultValue;
// throw new NoSuchMethodException("No matching Constructor for "+clazz.getName()+"("+getDspMethods(getClasses(args))+") found");
}
use of lucee.runtime.exp.PageException 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);
}
}
Aggregations