use of lucee.runtime.net.http.HttpServletRequestDummy 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.HttpServletRequestDummy in project Lucee by lucee.
the class ThreadUtil method cloneHttpServletRequest.
public static HttpServletRequest cloneHttpServletRequest(PageContext pc) {
Config config = pc.getConfig();
HttpServletRequest req = pc.getHttpServletRequest();
HttpServletRequestDummy dest = HttpServletRequestDummy.clone(config, config.getRootDirectory(), req);
return dest;
}
use of lucee.runtime.net.http.HttpServletRequestDummy in project Lucee by lucee.
the class ThreadUtil method createPageContext.
/**
* @param config
* @param os
* @param serverName
* @param requestURI
* @param queryString
* @param cookies
* @param headers
* @param parameters
* @param attributes
* @param register
* @param timeout timeout in ms, if the value is smaller than 1 it is ignored and the value comming from the context is used
* @return
*/
public static PageContextImpl createPageContext(ConfigWeb config, OutputStream os, String serverName, String requestURI, String queryString, Cookie[] cookies, Pair[] headers, byte[] body, Pair[] parameters, Struct attributes, boolean register, long timeout) {
CFMLFactory factory = config.getFactory();
HttpServletRequest req = new HttpServletRequestDummy(config.getRootDirectory(), serverName, requestURI, queryString, cookies, headers, parameters, attributes, null, body);
req = new HTTPServletRequestWrap(req);
HttpServletResponse rsp = createHttpServletResponse(os);
return (PageContextImpl) factory.getLuceePageContext(factory.getServlet(), req, rsp, null, false, -1, false, register, timeout, false, false);
}
use of lucee.runtime.net.http.HttpServletRequestDummy 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