use of org.apache.tomcat.util.http.CookieProcessor in project tomcat by apache.
the class StandardContextSF method storeChildren.
/**
* Store the specified context element children.
*
* @param aWriter Current output writer
* @param indent Indentation level
* @param aContext Context to store
* @param parentDesc The element description
* @throws Exception Configuration storing error
*/
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aContext, StoreDescription parentDesc) throws Exception {
if (aContext instanceof StandardContext) {
StandardContext context = (StandardContext) aContext;
// Store nested <Listener> elements
LifecycleListener[] listeners = context.findLifecycleListeners();
ArrayList<LifecycleListener> listenersArray = new ArrayList<>();
for (LifecycleListener listener : listeners) {
if (!(listener instanceof ThreadLocalLeakPreventionListener)) {
listenersArray.add(listener);
}
}
storeElementArray(aWriter, indent, listenersArray.toArray());
// Store nested <Valve> elements
Valve[] valves = context.getPipeline().getValves();
storeElementArray(aWriter, indent, valves);
// Store nested <Loader> elements
Loader loader = context.getLoader();
storeElement(aWriter, indent, loader);
// Store nested <Manager> elements
if (context.getCluster() == null || !context.getDistributable()) {
Manager manager = context.getManager();
storeElement(aWriter, indent, manager);
}
// Store nested <Realm> element
Realm realm = context.getRealm();
if (realm != null) {
Realm parentRealm = null;
// @TODO is this case possible?
if (context.getParent() != null) {
parentRealm = context.getParent().getRealm();
}
if (realm != parentRealm) {
storeElement(aWriter, indent, realm);
}
}
// Store nested resources
WebResourceRoot resources = context.getResources();
storeElement(aWriter, indent, resources);
// Store nested <WrapperListener> elements
String[] wLifecycles = context.findWrapperLifecycles();
getStoreAppender().printTagArray(aWriter, "WrapperListener", indent + 2, wLifecycles);
// Store nested <WrapperLifecycle> elements
String[] wListeners = context.findWrapperListeners();
getStoreAppender().printTagArray(aWriter, "WrapperLifecycle", indent + 2, wListeners);
// Store nested <Parameter> elements
ApplicationParameter[] appParams = context.findApplicationParameters();
storeElementArray(aWriter, indent, appParams);
// Store nested naming resources elements (EJB,Resource,...)
NamingResourcesImpl nresources = context.getNamingResources();
storeElement(aWriter, indent, nresources);
// Store nested watched resources <WatchedResource>
String[] wresources = context.findWatchedResources();
wresources = filterWatchedResources(context, wresources);
getStoreAppender().printTagArray(aWriter, "WatchedResource", indent + 2, wresources);
// Store nested <JarScanner> elements
JarScanner jarScanner = context.getJarScanner();
storeElement(aWriter, indent, jarScanner);
// Store nested <CookieProcessor> elements
CookieProcessor cookieProcessor = context.getCookieProcessor();
storeElement(aWriter, indent, cookieProcessor);
}
}
use of org.apache.tomcat.util.http.CookieProcessor in project tomcat by apache.
the class Request method parseCookies.
/**
* Parse cookies. This only parses the cookies into the memory efficient
* ServerCookies structure. It does not populate the Cookie objects.
*/
protected void parseCookies() {
if (cookiesParsed) {
return;
}
cookiesParsed = true;
ServerCookies serverCookies = coyoteRequest.getCookies();
serverCookies.setLimit(connector.getMaxCookieCount());
CookieProcessor cookieProcessor = getContext().getCookieProcessor();
cookieProcessor.parseCookieHeader(coyoteRequest.getMimeHeaders(), serverCookies);
}
use of org.apache.tomcat.util.http.CookieProcessor in project tomcat by apache.
the class Request method convertCookies.
/**
* Converts the parsed cookies (parsing the Cookie headers first if they
* have not been parsed) into Cookie objects.
*/
protected void convertCookies() {
if (cookiesConverted) {
return;
}
cookiesConverted = true;
if (getContext() == null) {
return;
}
parseCookies();
ServerCookies serverCookies = coyoteRequest.getCookies();
CookieProcessor cookieProcessor = getContext().getCookieProcessor();
int count = serverCookies.getCookieCount();
if (count <= 0) {
return;
}
cookies = new Cookie[count];
int idx = 0;
for (int i = 0; i < count; i++) {
ServerCookie scookie = serverCookies.getCookie(i);
try {
/*
we must unescape the '\\' escape character
*/
Cookie cookie = new Cookie(scookie.getName().toString(), null);
int version = scookie.getVersion();
cookie.setVersion(version);
scookie.getValue().getByteChunk().setCharset(cookieProcessor.getCharset());
cookie.setValue(unescape(scookie.getValue().toString()));
cookie.setPath(unescape(scookie.getPath().toString()));
String domain = scookie.getDomain().toString();
if (domain != null) {
//avoid NPE
cookie.setDomain(unescape(domain));
}
String comment = scookie.getComment().toString();
cookie.setComment(version == 1 ? unescape(comment) : null);
cookies[idx++] = cookie;
} catch (IllegalArgumentException e) {
// Ignore bad cookie
}
}
if (idx < count) {
Cookie[] ncookies = new Cookie[idx];
System.arraycopy(cookies, 0, ncookies, 0, idx);
cookies = ncookies;
}
}
use of org.apache.tomcat.util.http.CookieProcessor in project tomee by apache.
the class TomcatWebAppBuilder method beforeStart.
/**
* {@inheritDoc}
*/
@Override
public void beforeStart(final StandardContext standardContext) {
if (standardContext.getResources() != null && LazyStopStandardRoot.class.isInstance(standardContext.getResources())) {
// reset after reload
Reflections.set(standardContext, "resources", LazyStopStandardRoot.class.cast(standardContext.getResources()).getDelegate());
}
final ServletContext sc = standardContext.getServletContext();
if (sc != null && !SystemInstance.get().getOptions().get(OPENEJB_JSESSION_ID_SUPPORT, true)) {
final Set<SessionTrackingMode> defaultTrackingModes = sc.getEffectiveSessionTrackingModes();
if (defaultTrackingModes.contains(SessionTrackingMode.URL)) {
final Set<SessionTrackingMode> newModes = new HashSet<>();
newModes.remove(SessionTrackingMode.URL);
sc.setSessionTrackingModes(newModes);
}
}
initContextLoader(standardContext);
// used to add custom filters first - our arquillian integration uses it for instance
// needs to be done now (= before start event) because of addFilterMapBefore() usage
final String filters = SystemInstance.get().getProperty("org.apache.openejb.servlet.filters");
if (filters != null) {
final String[] names = filters.split(",");
for (final String name : names) {
final String[] clazzMapping = name.split("=");
final FilterDef filterDef = new FilterDef();
filterDef.setFilterClass(clazzMapping[0]);
filterDef.setFilterName(clazzMapping[0]);
standardContext.addFilterDef(filterDef);
final FilterMap filterMap = new FilterMap();
filterMap.setFilterName(clazzMapping[0]);
filterMap.addURLPattern(clazzMapping[1]);
standardContext.addFilterMapBefore(filterMap);
}
}
// mainly to get back compatibility with tomcat <= 8.0
final String cookieProcessor = SystemInstance.get().getProperty("tomee.tomcat.cookieProcessor");
if (cookieProcessor != null) {
// not that important for now if we use the container loader, we mainly want to be able to access
// the legacy one
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
final Class<?> cookieProcessorClass = contextClassLoader.loadClass(cookieProcessor.trim());
standardContext.setCookieProcessor(CookieProcessor.class.cast(cookieProcessorClass.newInstance()));
} catch (final Exception e) {
throw new IllegalArgumentException("Cannot set CookieProcessor: " + cookieProcessor);
}
}
}
Aggregations