Skip to content

Commit

Permalink
centralise Cookie class reference
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Mar 15, 2024
1 parent 1dc639a commit e50fa18
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 43 deletions.
12 changes: 6 additions & 6 deletions core/src/main/java/lucee/aprint.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import java.util.Map;
import java.util.Set;

import javax.servlet.http.Cookie;

import org.w3c.dom.Attr;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
Expand All @@ -50,6 +48,7 @@
import lucee.runtime.engine.CFMLEngineImpl;
import lucee.runtime.exp.PageException;
import lucee.runtime.op.Caster;
import lucee.runtime.thread.SerializableCookie;
import lucee.runtime.type.QueryImpl;

/**
Expand Down Expand Up @@ -309,10 +308,11 @@ private static void _eo(PrintStream ps, Object o) {
else if (o instanceof Node) _eo(ps, (Node) o);
else if (o instanceof Throwable) _eo(ps, (Throwable) o);
else if (o instanceof Attributes) _eo(ps, (Attributes) o);
else if (o instanceof Cookie) {
Cookie c = (Cookie) o;
ps.println("Cookie(name:" + c.getName() + ";domain:" + c.getDomain() + ";maxage:" + c.getMaxAge() + ";path:" + c.getPath() + ";value:" + c.getValue() + ";version:"
+ c.getVersion() + ";secure:" + c.getSecure() + ")");
else if (SerializableCookie.isCookie(o)) {

ps.println("Cookie(name:" + SerializableCookie.toCookie(o).getName() + ";domain:" + SerializableCookie.toCookie(o).getDomain() + ";maxage:"
+ SerializableCookie.toCookie(o).getMaxAge() + ";path:" + SerializableCookie.toCookie(o).getPath() + ";value:" + SerializableCookie.toCookie(o).getValue()
+ ";version:" + SerializableCookie.toCookie(o).getVersion() + ";secure:" + SerializableCookie.toCookie(o).getSecure() + ")");
}
else if (o instanceof InputSource) {
InputSource is = (InputSource) o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
import lucee.runtime.exp.PageException;
import lucee.runtime.exp.PageRuntimeException;
import lucee.runtime.op.Caster;
import lucee.runtime.thread.SerializableCookie;
import lucee.runtime.thread.ThreadUtil;
import lucee.runtime.type.Array;
import lucee.runtime.type.StructImpl;
import lucee.servlet.ServletContants;

public class CFMLResourceProvider implements ResourceProviderPro {

Expand Down Expand Up @@ -101,7 +101,7 @@ private PageContext getPageContext(PageContext pc) {

Config c = ThreadLocalPageContext.getConfig();
if (c instanceof ConfigWeb) {
return ThreadUtil.createPageContext((ConfigWeb) c, DevNullOutputStream.DEV_NULL_OUTPUT_STREAM, "localhost", "/", "", ServletContants.COOKIES0, new Pair[0], null,
return ThreadUtil.createPageContext((ConfigWeb) c, DevNullOutputStream.DEV_NULL_OUTPUT_STREAM, "localhost", "/", "", SerializableCookie.COOKIES0, new Pair[0], null,
new Pair[0], new StructImpl(), false, -1);
}
try {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/lucee/runtime/ComponentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import lucee.runtime.op.Duplicator;
import lucee.runtime.op.ThreadLocalDuplication;
import lucee.runtime.op.date.DateCaster;
import lucee.runtime.thread.SerializableCookie;
import lucee.runtime.thread.ThreadUtil;
import lucee.runtime.type.ArrayImpl;
import lucee.runtime.type.Collection;
Expand Down Expand Up @@ -113,7 +114,6 @@
import lucee.runtime.type.util.StructSupport;
import lucee.runtime.type.util.StructUtil;
import lucee.runtime.type.util.UDFUtil;
import lucee.servlet.ServletContants;

/**
* %**% MUST add handling for new attributes (style, namespace, serviceportname, porttypename,
Expand Down Expand Up @@ -2230,7 +2230,7 @@ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundExcept
pcCreated = true;
ConfigWeb config = (ConfigWeb) ThreadLocalPageContext.getConfig();
Pair[] parr = new Pair[0];
pc = ThreadUtil.createPageContext(config, DevNullOutputStream.DEV_NULL_OUTPUT_STREAM, "localhost", "/", "", ServletContants.COOKIES0, parr, null, parr,
pc = ThreadUtil.createPageContext(config, DevNullOutputStream.DEV_NULL_OUTPUT_STREAM, "localhost", "/", "", SerializableCookie.COOKIES0, parr, null, parr,
new StructImpl(), true, -1);

}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/lucee/runtime/config/CFConfigImport.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
import lucee.runtime.exp.PageException;
import lucee.runtime.interpreter.JSONExpressionInterpreter;
import lucee.runtime.op.Caster;
import lucee.runtime.thread.SerializableCookie;
import lucee.runtime.type.Array;
import lucee.runtime.type.Collection;
import lucee.runtime.type.Collection.Key;
import lucee.runtime.type.KeyImpl;
import lucee.runtime.type.Struct;
import lucee.runtime.util.Cast;
import lucee.runtime.util.PageContextUtil;
import lucee.servlet.ServletContants;

public class CFConfigImport {

Expand Down Expand Up @@ -120,7 +120,7 @@ public Struct execute(boolean throwException) throws PageException {
try {
if (pc == null) {

pc = PageContextUtil.getPageContext(config, null, (File) SystemUtil.getTempDirectory(), "localhost", "/", "", ServletContants.COOKIES0, null, null, null,
pc = PageContextUtil.getPageContext(config, null, (File) SystemUtil.getTempDirectory(), "localhost", "/", "", SerializableCookie.COOKIES0, null, null, null,
DevNullOutputStream.DEV_NULL_OUTPUT_STREAM, true, 100000, false);
unregister = true;

Expand Down
7 changes: 2 additions & 5 deletions core/src/main/java/lucee/runtime/debug/DebuggerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

import javax.servlet.http.HttpServletResponse;

import lucee.commons.io.SystemUtil;
import lucee.commons.io.SystemUtil.TemplateLine;
import lucee.commons.io.res.util.ResourceSnippet;
Expand Down Expand Up @@ -788,9 +786,8 @@ public Struct getDebuggingData(PageContext pc, boolean addAddionalInfo) throws D
//////////////////////////////////////////
if (threadName != null) debugging.setEL(KeyConstants._threadName, threadName);

HttpServletResponse rsp = pc.getHttpServletResponse();
debugging.setEL(KeyConstants._statusCode, rsp.getStatus());
debugging.setEL(KeyConstants._contentType, rsp.getContentType());
debugging.setEL(KeyConstants._statusCode, pc.getHttpServletResponse().getStatus());
debugging.setEL(KeyConstants._contentType, pc.getHttpServletResponse().getContentType());
// TODO ContentLength ReqRspUtil?

debugging.setEL(KeyConstants._starttime, new DateTimeImpl(starttime, false));
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/lucee/runtime/engine/CFMLEngineImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
import lucee.runtime.op.StringsImpl;
import lucee.runtime.osgi.OSGiUtil;
import lucee.runtime.schedule.SchedulerImpl;
import lucee.runtime.thread.SerializableCookie;
import lucee.runtime.thread.ThreadUtil;
import lucee.runtime.type.Struct;
import lucee.runtime.type.StructImpl;
Expand Down Expand Up @@ -182,7 +183,6 @@
import lucee.runtime.util.ZipUtilImpl;
import lucee.runtime.video.VideoUtil;
import lucee.runtime.video.VideoUtilImpl;
import lucee.servlet.ServletContants;
import lucee.servlet.http.HTTPServletImpl;

/**
Expand Down Expand Up @@ -1619,7 +1619,7 @@ public void cli(Map<String, String> config, ServletConfig servletConfig) throws
// cookie
Cookie[] cookies;
String strCookie = config.get("cookie");
if (StringUtil.isEmpty(strCookie, true)) cookies = ServletContants.COOKIES0;
if (StringUtil.isEmpty(strCookie, true)) cookies = SerializableCookie.COOKIES0;
else {
Map<String, String> mapCookies = HTTPUtil.parseParameterList(strCookie, false, null);
int index = 0;
Expand Down Expand Up @@ -1865,7 +1865,7 @@ public void run() {
attrs.setEL(KeyConstants._client, "lucee-listener-1-0");

pc = ThreadUtil.createPageContext((ConfigWeb) config, DevNullOutputStream.DEV_NULL_OUTPUT_STREAM, "localhost", requestURI, queryString,
ServletContants.COOKIES0, headers, null, new Pair[0], attrs, true, Long.MAX_VALUE);
SerializableCookie.COOKIES0, headers, null, new Pair[0], attrs, true, Long.MAX_VALUE);
}
else {
Map<String, Object> headers = new HashMap<String, Object>();
Expand All @@ -1876,7 +1876,7 @@ public void run() {
File root = new File(config.getRootDirectory().getAbsolutePath());
CreationImpl cr = (CreationImpl) CreationImpl.getInstance(engine);
ServletConfig sc = cr.createServletConfig(root, null, null);
pc = PageContextUtil.getPageContext(config, sc, root, "localhost", requestURI, queryString, ServletContants.COOKIES0, headers, null, attrs,
pc = PageContextUtil.getPageContext(config, sc, root, "localhost", requestURI, queryString, SerializableCookie.COOKIES0, headers, null, attrs,
DevNullOutputStream.DEV_NULL_OUTPUT_STREAM, true, Long.MAX_VALUE,
Caster.toBooleanValue(SystemUtil.getSystemPropOrEnvVar("lucee.ignore.scopes", null), false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
import lucee.runtime.ext.function.Function;
import lucee.runtime.net.http.ReqRspUtil;
import lucee.runtime.op.Caster;
import lucee.runtime.thread.SerializableCookie;
import lucee.runtime.thread.ThreadUtil;
import lucee.runtime.type.Collection.Key;
import lucee.runtime.type.Struct;
import lucee.runtime.type.StructImpl;
import lucee.runtime.type.util.CollectionUtil;
import lucee.servlet.ServletContants;

public final class CreatePageContext implements Function {

Expand Down Expand Up @@ -99,7 +99,7 @@ public static Pair<String, Object>[] toPair(Struct sct, boolean doStringCast) th
}

public static Cookie[] toCookies(Struct sct) throws PageException {
if (sct == null) return ServletContants.COOKIES0;
if (sct == null) return SerializableCookie.COOKIES0;
Iterator<Entry<Key, Object>> it = sct.entryIterator();
Entry<Key, Object> e;
List<Cookie> cookies = new ArrayList<Cookie>();
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/lucee/runtime/future/CallableUDF.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import lucee.commons.io.DevNullOutputStream;
import lucee.commons.lang.Pair;
import lucee.runtime.listener.ApplicationContext;
import lucee.runtime.PageContext;
import lucee.runtime.config.ConfigWeb;
import lucee.runtime.engine.ThreadLocalPageContext;
import lucee.runtime.listener.ApplicationContext;
import lucee.runtime.net.http.HttpUtil;
import lucee.runtime.net.http.ReqRspUtil;
import lucee.runtime.thread.SerializableCookie;
Expand Down Expand Up @@ -43,7 +43,7 @@ public CallableUDF(PageContext parent, UDF udf, Object arg) {
headers = HttpUtil.cloneHeaders(req);
attributes = HttpUtil.getAttributesAsStruct(req);
requestTimeout = parent.getRequestTimeout();

// ApplicationContext
ac = parent.getApplicationContext();

Expand All @@ -60,7 +60,7 @@ public Object call() throws Exception {
DevNullOutputStream os = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
pc = ThreadUtil.createPageContext(cw, os, serverName, requestURI, queryString, SerializableCookie.toCookies(cookies), headers, null, parameters, attributes, true, -1);
pc.setRequestTimeout(requestTimeout);

pc.setApplicationContext(ac);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import java.util.List;
import java.util.Map.Entry;

import javax.servlet.http.Cookie;

import lucee.commons.io.DevNullOutputStream;
import lucee.commons.io.log.LogUtil;
import lucee.commons.io.res.Resource;
Expand Down Expand Up @@ -60,6 +58,7 @@
import lucee.runtime.op.Decision;
import lucee.runtime.op.Duplicator;
import lucee.runtime.orm.ORMUtil;
import lucee.runtime.thread.SerializableCookie;
import lucee.runtime.type.Array;
import lucee.runtime.type.ArrayImpl;
import lucee.runtime.type.Collection;
Expand Down Expand Up @@ -374,7 +373,7 @@ private PageContextImpl createPageContext(CFMLFactory factory, Component app, St

// 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") });
if (!StringUtil.isEmpty(cfid)) req.setCookies(SerializableCookie.toCookies(SerializableCookie.toCookie("cfid", cfid), SerializableCookie.toCookie("cftoken", "0")));

// Response
OutputStream os = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import lucee.runtime.exp.PageServletException;
import lucee.runtime.op.Caster;
import lucee.runtime.op.date.DateCaster;
import lucee.runtime.thread.SerializableCookie;
import lucee.runtime.type.Collection;
import lucee.runtime.type.Collection.Key;
import lucee.runtime.type.KeyImpl;
Expand All @@ -77,7 +78,6 @@
import lucee.runtime.type.util.ArrayUtil;
import lucee.runtime.type.util.ListUtil;
import lucee.runtime.util.EnumerationWrapper;
import lucee.servlet.ServletContants;

/**
* extends an existing {@link HttpServletRequest} with the possibility to reread the input as many
Expand Down Expand Up @@ -412,7 +412,7 @@ public synchronized void disconnect(PageContextImpl pc) {
for (int i = 0; i < _cookies.length; i++)
disconnectData.cookies[i] = _cookies[i];
}
else disconnectData.cookies = ServletContants.COOKIES0;
else disconnectData.cookies = SerializableCookie.COOKIES0;
}

disconnectData.authType = req.getAuthType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
import lucee.commons.lang.Pair;
import lucee.commons.net.URLEncoder;
import lucee.runtime.op.Caster;
import lucee.runtime.thread.SerializableCookie;
import lucee.runtime.type.dt.DateTimeImpl;
import lucee.servlet.ServletContants;

/**
*
*/
public final class HttpServletResponseDummy implements HttpServletResponse, Serializable {

private Cookie[] cookies = ServletContants.COOKIES0;
private Cookie[] cookies = SerializableCookie.COOKIES0;
private Pair<String, Object>[] headers = new Pair[0];
private int status = 200;
private String statusCode = "OK";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
import lucee.commons.lang.Pair;
import lucee.commons.net.URLEncoder;
import lucee.runtime.op.Caster;
import lucee.runtime.thread.SerializableCookie;
import lucee.runtime.type.dt.DateTimeImpl;
import lucee.servlet.ServletContants;

/**
*
*/
public final class HttpServletResponseWrap extends HttpServletResponseWrapper implements HttpServletResponse, Serializable {

private Cookie[] cookies = ServletContants.COOKIES0;
private Cookie[] cookies = SerializableCookie.COOKIES0;
private Pair[] headers = new Pair[0];
private int status = 200;
private String statusCode = "OK";
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/lucee/runtime/net/http/HttpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
import lucee.runtime.PageContext;
import lucee.runtime.config.Config;
import lucee.runtime.engine.ThreadLocalPageContext;
import lucee.runtime.thread.SerializableCookie;
import lucee.runtime.type.Struct;
import lucee.runtime.type.StructImpl;
import lucee.servlet.ServletContants;

public class HttpUtil {

Expand Down Expand Up @@ -104,7 +104,7 @@ public static Pair<String, String>[] cloneParameters(HttpServletRequest req) {

public static Cookie[] cloneCookies(Config config, HttpServletRequest req) {
Cookie[] src = ReqRspUtil.getCookies(req, CharsetUtil.getWebCharset());
if (src == null) return ServletContants.COOKIES0;
if (src == null) return SerializableCookie.COOKIES0;

Cookie[] dest = new Cookie[src.length];
for (int i = 0; i < src.length; i++) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/lucee/runtime/net/http/ReqRspUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
import lucee.runtime.security.ScriptProtect;
import lucee.runtime.text.xml.XMLCaster;
import lucee.runtime.text.xml.XMLUtil;
import lucee.runtime.thread.SerializableCookie;
import lucee.runtime.type.UDF;
import lucee.runtime.type.util.CollectionUtil;
import lucee.servlet.ServletContants;

public final class ReqRspUtil {

Expand Down Expand Up @@ -175,7 +175,7 @@ public static Cookie[] getCookies(HttpServletRequest req, Charset charset) {
}
}

if (cookies == null) return ServletContants.COOKIES0;
if (cookies == null) return SerializableCookie.COOKIES0;

return cookies;
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/lucee/runtime/tag/TagUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import lucee.runtime.op.Caster;
import lucee.runtime.reflection.Reflector;
import lucee.runtime.reflection.pairs.MethodInstance;
import lucee.runtime.thread.SerializableCookie;
import lucee.runtime.thread.ThreadUtil;
import lucee.runtime.type.Collection;
import lucee.runtime.type.Collection.Key;
Expand All @@ -64,7 +65,6 @@
import lucee.runtime.type.StructImpl;
import lucee.runtime.type.util.ArrayUtil;
import lucee.runtime.type.util.KeyConstants;
import lucee.servlet.ServletContants;
import lucee.transformer.library.tag.TagLib;
import lucee.transformer.library.tag.TagLibTag;
import lucee.transformer.library.tag.TagLibTagAttr;
Expand Down Expand Up @@ -237,7 +237,7 @@ public static void addTagMetaData(ConfigWebPro cw, lucee.commons.io.log.Log log)

PageContextImpl pc = null;
try {
pc = ThreadUtil.createPageContext(cw, DevNullOutputStream.DEV_NULL_OUTPUT_STREAM, "localhost", "/", "", ServletContants.COOKIES0, new Pair[0], null, new Pair[0],
pc = ThreadUtil.createPageContext(cw, DevNullOutputStream.DEV_NULL_OUTPUT_STREAM, "localhost", "/", "", SerializableCookie.COOKIES0, new Pair[0], null, new Pair[0],
new StructImpl(), false, -1);

}
Expand Down
Loading

0 comments on commit e50fa18

Please sign in to comment.