use of lucee.runtime.CFMLFactory in project Lucee by lucee.
the class CFMLEngineImpl method serviceFile.
@Override
public void serviceFile(HttpServlet servlet, HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException {
req = new HTTPServletRequestWrap(req);
CFMLFactory factory = getCFMLFactory(servlet.getServletConfig(), req);
ConfigWeb config = factory.getConfig();
PageSource ps = config.getPageSourceExisting(null, null, req.getServletPath(), false, true, true, false);
if (ps == null) {
rsp.sendError(404);
} else {
Resource res = ps.getResource();
if (res == null) {
rsp.sendError(404);
} else {
ReqRspUtil.setContentLength(rsp, res.length());
String mt = servlet.getServletContext().getMimeType(req.getServletPath());
if (!StringUtil.isEmpty(mt))
ReqRspUtil.setContentType(rsp, mt);
IOUtil.copy(res, rsp.getOutputStream(), true);
}
}
}
use of lucee.runtime.CFMLFactory in project Lucee by lucee.
the class GatewayEngineImpl method call.
public Object call(String cfcPath, String id, String functionName, Struct arguments, boolean cfcPeristent, Object defaultValue) throws PageException {
String requestURI = toRequestURI(cfcPath);
PageContext oldPC = ThreadLocalPageContext.get();
PageContextImpl pc = null;
try {
pc = createPageContext(requestURI, id, functionName, arguments, cfcPeristent, true);
String ext = ResourceUtil.getExtension(cfcPath, null);
ConfigWeb config = (ConfigWeb) ThreadLocalPageContext.getConfig();
int dialect = ext == null ? CFMLEngine.DIALECT_CFML : config.getFactory().toDialect(ext);
// ThreadLocalPageContext.register(pc);
Component cfc = getCFC(pc, requestURI);
if (cfc.containsKey(functionName)) {
if (dialect == CFMLEngine.DIALECT_LUCEE)
pc.execute(requestURI, true, false);
else
pc.executeCFML(requestURI, true, false);
// Result
return pc.variablesScope().get(AMF_FORWARD, null);
}
} finally {
CFMLFactory f = config.getFactory();
f.releaseLuceePageContext(pc, true);
ThreadLocalPageContext.register(oldPC);
}
return defaultValue;
}
use of lucee.runtime.CFMLFactory in project Lucee by lucee.
the class GatewayEngineImpl method getComponent.
public Object getComponent(String cfcPath, String id) throws PageException {
String requestURI = toRequestURI(cfcPath);
PageContext oldPC = ThreadLocalPageContext.get();
PageContextImpl pc = null;
try {
pc = createPageContext(requestURI, id, "init", null, false, true);
// ThreadLocalPageContext.register(pc);
return getCFC(pc, requestURI);
} finally {
CFMLFactory f = config.getFactory();
f.releaseLuceePageContext(pc, true);
ThreadLocalPageContext.register(oldPC);
}
}
use of lucee.runtime.CFMLFactory in project Lucee by lucee.
the class CreationImpl method createPageContext.
@Override
public PageContext createPageContext(HttpServletRequest req, HttpServletResponse rsp, OutputStream out) {
Config config = ThreadLocalPageContext.getConfig();
if (!(config instanceof ConfigWeb))
throw new RuntimeException("need a web context to create a PageContext");
CFMLFactory factory = ((ConfigWeb) config).getFactory();
return (PageContext) factory.getPageContext(factory.getServlet(), req, rsp, null, false, -1, false);
}
use of lucee.runtime.CFMLFactory in project Lucee by lucee.
the class ResourceLockImpl method _read.
private void _read(String path) {
long start = -1, now;
Thread t;
do {
if ((t = resources.get(path)) == null) {
// print.ln("read ok");
return;
}
if (t == Thread.currentThread()) {
// aprint.err(path);
Config config = ThreadLocalPageContext.getConfig();
if (config != null)
SystemOut.printDate(config.getErrWriter(), "conflict in same thread: on " + path);
// SystemOut.printDate(config.getErrWriter(),"conflict in same thread: on "+path+"\nStacktrace:\n"+StringUtil.replace(ExceptionUtil.getStacktrace(new Throwable(), false),"java.lang.Throwable\n","",true));
return;
}
// bugfix when lock von totem thread, wird es ignoriert
if (!t.isAlive()) {
resources.remove(path);
return;
}
if (start == -1)
start = System.currentTimeMillis();
try {
token.wait(lockTimeout);
now = System.currentTimeMillis();
if ((start + lockTimeout) <= now) {
Config config = ThreadLocalPageContext.getConfig();
if (config != null) {
PageContextImpl pc = null;
String add = "";
if (config instanceof ConfigWeb) {
CFMLFactory factory = ((ConfigWeb) config).getFactory();
if (factory instanceof CFMLFactoryImpl) {
Map<Integer, PageContextImpl> pcs = ((CFMLFactoryImpl) factory).getActivePageContexts();
Iterator<PageContextImpl> it = pcs.values().iterator();
PageContextImpl tmp;
while (it.hasNext()) {
tmp = it.next();
if (t == tmp.getThread()) {
pc = tmp;
break;
}
}
}
}
if (pc != null) {
add = " The file is locked by a request on the following URL " + ReqRspUtil.getRequestURL(pc.getHttpServletRequest(), true) + ", that request started " + (System.currentTimeMillis() - pc.getStartTime()) + "ms ago.";
}
SystemOut.printDate(config.getErrWriter(), "timeout after " + (now - start) + " ms (" + (lockTimeout) + " ms) occured while accessing file [" + path + "]." + add);
} else
SystemOut.printDate("timeout (" + (lockTimeout) + " ms) occured while accessing file [" + path + "].");
return;
}
} catch (InterruptedException e) {
}
} while (true);
}
Aggregations