public HttpSession getSession(boolean create) {
if (crossContext) {
// There cannot be a session if no context has been assigned yetif (context == null)
return (null);
// Return the current session if it exists and is validif (session != null && session.isValid()) {
return (session.getSession());
}
HttpSession other = super.getSession(false);
if (create && (other == null)) {
// First create a session in the first context: the problem is// that the top level request is the only one which can // create the cookie safely
other = super.getSession(true);
}
if (other != null) {
Session localSession = null;
try {
localSession =
context.getManager().findSession(other.getId());
if (localSession != null && !localSession.isValid()) {
localSession = null;
}
} catch (IOException e) {
// Ignore
}
if (localSession == null && create) {
localSession =
context.getManager().createSession(other.getId());
}
if (localSession != null) {
localSession.access();
session = localSession;
return session.getSession();
}
}
returnnull;
} else {
returnsuper.getSession(create);
}
}
public ServletContext getContext(String uri) {
// Validate the format of the specified argumentif (uri == null || !uri.startsWith("/")) {
returnnull;
}
Context child = null;
try {
// Look for an exact match
Container host = context.getParent();
child = (Context) host.findChild(uri);
// Non-running contexts should be ignored.if (child != null && !child.getState().isAvailable()) {
child = null;
}
// Remove any version information and use the mapperif (child == null) {
int i = uri.indexOf("##");
if (i > -1) {
uri = uri.substring(0, i);
}
// Note: This could be more efficient with a dedicated Mapper// method but such an implementation would require some// refactoring of the Mapper to avoid copy/paste of// existing code.
MessageBytes hostMB = MessageBytes.newInstance();
hostMB.setString(host.getName());
MessageBytes pathMB = MessageBytes.newInstance();
pathMB.setString(uri);
MappingData mappingData = new MappingData();
((Engine) host.getParent()).getService().findConnectors()[0].getMapper().map(
hostMB, pathMB, null, mappingData);
child = (Context) mappingData.context;
}
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
returnnull;
}
if (child == null) {
returnnull;
}
if (context.getCrossContext()) {
// If crossContext is enabled, can always return the contextreturn child.getServletContext();
} elseif (child == context) {
// Can still return the current contextreturn context.getServletContext();
} else {
// Nothing to returnreturnnull;
}
}