use of lucee.runtime.net.http.HttpServletResponseDummy 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.net.http.HttpServletResponseDummy in project Lucee by lucee.
the class CFMLEngineImpl method cli.
@Override
public void cli(Map<String, String> config, ServletConfig servletConfig) throws IOException, JspException, ServletException {
ServletContext servletContext = servletConfig.getServletContext();
HTTPServletImpl servlet = new HTTPServletImpl(servletConfig, servletContext, servletConfig.getServletName());
// webroot
String strWebroot = config.get("webroot");
if (StringUtil.isEmpty(strWebroot, true))
throw new IOException("missing webroot configuration");
Resource root = ResourcesImpl.getFileResourceProvider().getResource(strWebroot);
root.mkdirs();
// serverName
String serverName = config.get("server-name");
if (StringUtil.isEmpty(serverName, true))
serverName = "localhost";
// uri
String strUri = config.get("uri");
if (StringUtil.isEmpty(strUri, true))
throw new IOException("missing uri configuration");
URI uri;
try {
uri = lucee.commons.net.HTTPUtil.toURI(strUri);
} catch (URISyntaxException e) {
throw Caster.toPageException(e);
}
// cookie
Cookie[] cookies;
String strCookie = config.get("cookie");
if (StringUtil.isEmpty(strCookie, true))
cookies = new Cookie[0];
else {
Map<String, String> mapCookies = HTTPUtil.parseParameterList(strCookie, false, null);
int index = 0;
cookies = new Cookie[mapCookies.size()];
Entry<String, String> entry;
Iterator<Entry<String, String>> it = mapCookies.entrySet().iterator();
Cookie c;
while (it.hasNext()) {
entry = it.next();
c = ReqRspUtil.toCookie(entry.getKey(), entry.getValue(), null);
if (c != null)
cookies[index++] = c;
else
throw new IOException("cookie name [" + entry.getKey() + "] is invalid");
}
}
// header
Pair[] headers = new Pair[0];
// parameters
Pair[] parameters = new Pair[0];
// attributes
StructImpl attributes = new StructImpl();
ByteArrayOutputStream os = new ByteArrayOutputStream();
HttpServletRequestDummy req = new HttpServletRequestDummy(root, serverName, uri.getPath(), uri.getQuery(), cookies, headers, parameters, attributes, null, null);
req.setProtocol("CLI/1.0");
HttpServletResponse rsp = new HttpServletResponseDummy(os);
serviceCFML(servlet, req, rsp);
String res = os.toString(ReqRspUtil.getCharacterEncoding(null, rsp).name());
System.out.println(res);
}
use of lucee.runtime.net.http.HttpServletResponseDummy in project Lucee by lucee.
the class CallerResponseStreamResult method call.
@Override
public final String call() throws PageException {
ThreadLocalPageContext.register(pc);
// make sure content is not compressed
pc.getRootOut().setAllowCompression(false);
String str = null;
try {
_call(parent, pc);
} finally {
try {
HttpServletResponseDummy rsp = (HttpServletResponseDummy) pc.getHttpServletResponse();
Charset cs = ReqRspUtil.getCharacterEncoding(pc, rsp);
// if(enc==null) enc="ISO-8859-1";
// make sure content is flushed
pc.getOut().flush();
pc.getConfig().getFactory().releasePageContext(pc);
// TODO add support for none string content
str = IOUtil.toString((new ByteArrayInputStream(baos.toByteArray())), cs);
} catch (Exception e) {
SystemOut.printDate(e);
}
}
return str;
}
use of lucee.runtime.net.http.HttpServletResponseDummy in project Lucee by lucee.
the class UDFCaller2 method call.
@Override
public final Data<P> call() throws PageException {
ThreadLocalPageContext.register(pc);
// make sure content is not compressed
pc.getRootOut().setAllowCompression(false);
String str = null;
Object result = null;
try {
if (namedArguments != null)
result = udf.callWithNamedValues(pc, namedArguments, doIncludePath);
else
result = udf.call(pc, arguments, doIncludePath);
} finally {
try {
HttpServletResponseDummy rsp = (HttpServletResponseDummy) pc.getHttpServletResponse();
Charset cs = ReqRspUtil.getCharacterEncoding(pc, rsp);
// if(enc==null) enc="ISO-8859-1";
// make sure content is flushed
pc.getOut().flush();
pc.getConfig().getFactory().releasePageContext(pc);
// TODO add support for none string content
str = IOUtil.toString((new ByteArrayInputStream(baos.toByteArray())), cs);
} catch (Exception e) {
SystemOut.printDate(e);
}
}
return new Data<P>(str, result, passed);
}
use of lucee.runtime.net.http.HttpServletResponseDummy in project Lucee by lucee.
the class ModernAppListener method createPageContext.
private PageContextImpl createPageContext(CFMLFactory factory, Component app, String applicationName, String cfid, Collection.Key methodName, boolean register, long timeout) throws PageException {
Resource root = factory.getConfig().getRootDirectory();
String path = app.getPageSource().getRealpathWithVirtual();
// Request
HttpServletRequestDummy req = new HttpServletRequestDummy(root, "localhost", path, "", null, null, null, null, null, null);
if (!StringUtil.isEmpty(cfid))
req.setCookies(new Cookie[] { new Cookie("cfid", cfid), new Cookie("cftoken", "0") });
// Response
OutputStream os = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
// File based output stream
/*try {
Resource out = factory.getConfig().getConfigDir().getRealResource("output/"+methodName.getString()+".out");
out.getParentResource().mkdirs();
os = out.getOutputStream(false);
}
catch (IOException e) {}*/
HttpServletResponseDummy rsp = new HttpServletResponseDummy(os);
// PageContext
PageContextImpl pc = (PageContextImpl) factory.getLuceePageContext(factory.getServlet(), req, rsp, null, false, -1, false, register, timeout, true, false);
// ApplicationContext
ClassicApplicationContext ap = new ClassicApplicationContext(factory.getConfig(), applicationName, false, app == null ? null : ResourceUtil.getResource(pc, app.getPageSource(), null));
initApplicationContext(pc, app);
ap.setName(applicationName);
ap.setSetSessionManagement(true);
// if(!ap.hasName())ap.setName("Controler")
// Base
pc.setBase(app.getPageSource());
return pc;
}
Aggregations