Modified the web server to allow connection related data to be stored in the connection's context by the application. This modifies the contract (interfaces) between the framework and application code, requiring changes to the application (breaks backward compatibility).
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.foundation.web;
|
||||
|
||||
import com.foundation.web.interfaces.IConnectionContext;
|
||||
import com.foundation.web.interfaces.IRequest;
|
||||
import com.foundation.web.interfaces.IResponse;
|
||||
import com.foundation.web.interfaces.ISession;
|
||||
@@ -14,14 +15,15 @@ public interface IResourceRequestHandler {
|
||||
/**
|
||||
* Gets a resource from the file system. The implementor can validate that the user has the rights to access the resource and can ensure that there is an SSL connection if needed.
|
||||
* <p>A simple implementation will simply call: <code>response.setContentResource(requestPath, request.getCacheDate());</code>, a more complex implementation will test for an SSL connection for secure resources, and will ensure the user is logged in and has rights to access the resource for rights oriented resources.</p>
|
||||
* @param requestPath The path to the requested resource. This is the request's URI already mapped to an actual resource.
|
||||
* @param requestPath The path to the requested resource. This is the request's URI already mapped to an actual resource (same as calling request.getUri()).
|
||||
* @param request The request metadata.
|
||||
* @param response The response metadata.
|
||||
* @param sessionData The non-secure session data.
|
||||
* @param secureSessionData The secure session data, or null if the request was made over an insecure connection or no secure session data exists.
|
||||
* @param isSecure Whether the request was made over a secure connection and provided the correct secure id.
|
||||
* @param connectionContext The context object for the connection (socket) between the client (web browser) and server (web server).
|
||||
*/
|
||||
public void processRequest(String requestPath, IRequest request, IResponse response, SessionData sessionData, SecureSessionData secureSessionData, boolean isSecure);
|
||||
public void processRequest(String requestPath, IRequest request, IResponse response, SessionData sessionData, SecureSessionData secureSessionData, boolean isSecure, IConnectionContext connectionContext);
|
||||
/**
|
||||
* Calls a handler to access the requested resource. The implementor can validate that the user has the rights to access the resource and can ensure that there is an SSL connection if needed.
|
||||
* <p>A simple implementation will simply call: <code>response.setContentResource(requestPath, request.getCacheDate());</code>, a more complex implementation will test for an SSL connection for secure resources, and will ensure the user is logged in and has rights to access the resource for rights oriented resources.</p>
|
||||
@@ -32,8 +34,9 @@ public void processRequest(String requestPath, IRequest request, IResponse respo
|
||||
* @param sessionData The non-secure session data.
|
||||
* @param secureSessionData The secure session data, or null if the request was made over an insecure connection or no secure session data exists.
|
||||
* @param isSecure Whether the request was made over a secure connection and provided the correct secure id.
|
||||
* @param connectionContext The context object for the connection (socket) between the client (web browser) and server (web server).
|
||||
*/
|
||||
public void processRequest(IWebRequestHandler handler, String requestPath, IRequest request, IResponse response, SessionData sessionData, SecureSessionData secureSessionData, boolean isSecure);
|
||||
public void processRequest(IWebRequestHandler handler, String requestPath, IRequest request, IResponse response, SessionData sessionData, SecureSessionData secureSessionData, boolean isSecure, IConnectionContext connectionContext);
|
||||
/**
|
||||
* Gets the maximum size of message allowed by the application beyond the header (for upload only).
|
||||
* @param request The request whose header has been read, but whose body has not yet been read.
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.foundation.web;
|
||||
|
||||
/**
|
||||
* An interface implemented by objects stored in the SessionData's application data mapping (as the value) when the object wants notification that the session has been released.
|
||||
*/
|
||||
public interface ISessionLifecycleAware {
|
||||
/**
|
||||
* Called when the session is released.
|
||||
*/
|
||||
public void release();
|
||||
}//ISessionLifecycleAware//
|
||||
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
package com.foundation.web;
|
||||
|
||||
import com.foundation.web.interfaces.IConnectionContext;
|
||||
import com.foundation.web.interfaces.IRequest;
|
||||
import com.foundation.web.interfaces.IResponse;
|
||||
import com.foundation.web.SecureSessionData;
|
||||
@@ -22,7 +23,8 @@ public interface IWebRequestHandler {
|
||||
* @param request The request metadata.
|
||||
* @param response The response metadata.
|
||||
* @param sessionData The application specific data object associated with this user's session.
|
||||
* @param connectionContext The context object for the connection (socket) between the client (web browser) and server (web server).
|
||||
* @param secureSessionData The application specific data object associated with this user's session if the user made the request over a secure connection and used the correct secure session identifier, otherwise null.
|
||||
*/
|
||||
public void processRequest(IRequest request, IResponse response, SessionData sessionData, SecureSessionData secureSessionData);
|
||||
public void processRequest(IRequest request, IResponse response, SessionData sessionData, SecureSessionData secureSessionData, IConnectionContext connectionContext);
|
||||
}//IWebRequestHandler//
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.foundation.web;
|
||||
|
||||
import com.foundation.web.interfaces.IConnectionContext;
|
||||
import com.foundation.web.interfaces.IRequest;
|
||||
import com.foundation.web.interfaces.IResponse;
|
||||
import com.foundation.web.interfaces.ISession;
|
||||
@@ -10,12 +11,13 @@ import com.foundation.web.interfaces.ISession;
|
||||
public interface IWebdavRequestHandler {
|
||||
/**
|
||||
* Processes the incoming web dav request.
|
||||
* @param requestPath The path to the requested resource. This is the request's URI already mapped to an actual resource.
|
||||
* @param requestPath The path to the requested resource. This is the request's URI already mapped to an actual resource (same as calling request.getUri()).
|
||||
* @param request The request metadata.
|
||||
* @param response The response metadata.
|
||||
* @param sessionData The non-secure session data.
|
||||
* @param secureSessionData The secure session data, or null if the request was made over an insecure connection or no secure session data exists.
|
||||
* @param isSecure Whether the request was made over a secure connection and provided the correct secure id.
|
||||
* @param connectionContext The context object for the connection (socket) between the client (web browser) and server (web server).
|
||||
*/
|
||||
public void processRequest(String requestPath, IRequest request, IResponse response, SessionData sessionData, SecureSessionData secureSessionData, boolean isSecure);
|
||||
public void processRequest(String requestPath, IRequest request, IResponse response, SessionData sessionData, SecureSessionData secureSessionData, boolean isSecure, IConnectionContext connectionContext);
|
||||
}//IWebdavRequestHandler//
|
||||
@@ -9,6 +9,7 @@ import com.common.util.IIterator;
|
||||
import com.common.util.IList;
|
||||
import com.common.util.LiteHashMap;
|
||||
import com.foundation.event.IRequestHandler;
|
||||
import com.foundation.web.interfaces.ISessionLifecycleAware;
|
||||
|
||||
/**
|
||||
* Contains the basic information about a user web session.
|
||||
|
||||
@@ -714,9 +714,9 @@ protected String processResourceName(String resourceName) {
|
||||
return (String) nameSubstitutionMap.get(resourceName);
|
||||
}//processResourceName()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.web.interfaces.IWebApplication#processRequest(com.foundation.web.interfaces.IRequest, com.foundation.web.interfaces.IResponse, com.foundation.web.interfaces.ISession, boolean, boolean)
|
||||
* @see com.foundation.web.interfaces.IWebApplication#processRequest(com.foundation.web.interfaces.IRequest, com.foundation.web.interfaces.IResponse, com.foundation.web.interfaces.ISession, boolean, boolean, com.foundation.web.interfaces.IConnectionContext)
|
||||
*/
|
||||
public void processRequest(final IRequest request, final IResponse response, final ISession session, final boolean isSecure, final boolean clientHadBadSession) {
|
||||
public void processRequest(final IRequest request, final IResponse response, final ISession session, final boolean isSecure, final boolean clientHadBadSession, final IConnectionContext connectionContext) {
|
||||
int requestType = request.getRequestType();
|
||||
boolean isGetPostOrHead = requestType == IRequest.TYPE_GET || requestType == IRequest.TYPE_POST || requestType == IRequest.TYPE_HEAD;
|
||||
boolean isWebdav = requestType == IRequest.TYPE_WEBDAV_COPY || requestType == IRequest.TYPE_WEBDAV_LOCK || requestType == IRequest.TYPE_WEBDAV_MKCOL || requestType == IRequest.TYPE_WEBDAV_MOVE || requestType == IRequest.TYPE_WEBDAV_PROPFIND || requestType == IRequest.TYPE_WEBDAV_PROPPATCH || requestType == IRequest.TYPE_WEBDAV_UNLOCK;
|
||||
@@ -804,12 +804,12 @@ public void processRequest(final IRequest request, final IResponse response, fin
|
||||
IRunnable runnable = new IRunnable() {
|
||||
public Object run() {
|
||||
if(resourceRequestHandler != null) {
|
||||
resourceRequestHandler.processRequest(handler, requestPath, request, response, (SessionData) session.getApplicationData(), (SecureSessionData) (isSecure ? session.getApplicationSecureData() : null), isSecure);
|
||||
resourceRequestHandler.processRequest(handler, requestPath, request, response, (SessionData) session.getApplicationData(), (SecureSessionData) (isSecure ? session.getApplicationSecureData() : null), isSecure, connectionContext);
|
||||
}//if//
|
||||
else {
|
||||
try {
|
||||
//Note: Synchronization on the session is not necessary now that we single thread all requests for a given session.//
|
||||
handler.processRequest(request, response, (SessionData) session.getApplicationData(), isSecure ? (SecureSessionData) session.getApplicationSecureData() : null);
|
||||
handler.processRequest(request, response, (SessionData) session.getApplicationData(), isSecure ? (SecureSessionData) session.getApplicationSecureData() : null, connectionContext);
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
@@ -858,7 +858,7 @@ public void processRequest(final IRequest request, final IResponse response, fin
|
||||
}//else if//
|
||||
else {
|
||||
//TODO: Should we synchronize on the session here? The app code could interact with the session and cause problems otherwise.
|
||||
resourceRequestHandler.processRequest(path, request, response, (SessionData) session.getApplicationData(), (SecureSessionData) (isSecure ? session.getApplicationSecureData() : null), isSecure);
|
||||
resourceRequestHandler.processRequest(path, request, response, (SessionData) session.getApplicationData(), (SecureSessionData) (isSecure ? session.getApplicationSecureData() : null), isSecure, connectionContext);
|
||||
}//else//
|
||||
}//else if//
|
||||
else if(isWebdav) {
|
||||
@@ -867,7 +867,7 @@ public void processRequest(final IRequest request, final IResponse response, fin
|
||||
}//if//
|
||||
else {
|
||||
synchronized(session) {
|
||||
webdavRequestHandler.processRequest(path, request, response, (SessionData) session.getApplicationData(), (SecureSessionData) (isSecure ? session.getApplicationSecureData() : null), isSecure);
|
||||
webdavRequestHandler.processRequest(path, request, response, (SessionData) session.getApplicationData(), (SecureSessionData) (isSecure ? session.getApplicationSecureData() : null), isSecure, connectionContext);
|
||||
//Update the repository with the session changes as necessary.//
|
||||
((WebSession) session).updateRepository();
|
||||
}//synchronized//
|
||||
|
||||
Reference in New Issue
Block a user