diff --git a/Foundation Web Application/src/com/foundation/web/DefaultResourceRequestHandler.java b/Foundation Web Application/src/com/foundation/web/DefaultResourceRequestHandler.java index 7d3c4c0..f872490 100644 --- a/Foundation Web Application/src/com/foundation/web/DefaultResourceRequestHandler.java +++ b/Foundation Web Application/src/com/foundation/web/DefaultResourceRequestHandler.java @@ -7,13 +7,22 @@ import com.foundation.web.WebApplication.PathSubstitution; import com.foundation.web.interfaces.IConnectionContext; import com.foundation.web.interfaces.IRequest; import com.foundation.web.interfaces.IResponse; +import com.foundation.web.interfaces.ISession; public class DefaultResourceRequestHandler extends ResourceRequestHandler { private IHashMap nameSubstitutionMap = new LiteHashMap(10); private IHashMap pathSubstitutionMap = new LiteHashMap(10); +/** + * DefaultResourceRequestHandler constructor. + */ public DefaultResourceRequestHandler() { - }//DefaultResourceRequestHandler()// +/* (non-Javadoc) + * @see com.foundation.web.ResourceRequestHandler#processWebSocketUpgrade(com.foundation.web.interfaces.IRequest, com.foundation.web.interfaces.IResponse, com.foundation.web.interfaces.ISession, boolean, boolean, com.foundation.web.interfaces.IConnectionContext, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) + */ +public void processWebSocketUpgrade(IRequest request, IResponse response, ISession session, boolean isSecure, boolean clientHadBadSession, IConnectionContext connectionContext, String connection, String secWebSocketKey, String secWebSocketProtocol, String secWebSocketVersion, String origin) { + response.setError(IResponse.ERROR_UPGRADE_REJECTED); +}//processWebSocketUpgrade()// /** * Adds a resource name subtitution mapping where the old resource name will be replaced by the new resource name automatically prior to the request being processed. * @param oldName The old resource name. diff --git a/Foundation Web Application/src/com/foundation/web/ForwardingDomain.java b/Foundation Web Application/src/com/foundation/web/ForwardingDomain.java index 696e5a6..e066231 100644 --- a/Foundation Web Application/src/com/foundation/web/ForwardingDomain.java +++ b/Foundation Web Application/src/com/foundation/web/ForwardingDomain.java @@ -223,6 +223,11 @@ public String getErrorHeader(int errorCode) { public ISession getSession(String sessionId) { return null; }//getSession()// +/* (non-Javadoc) + * @see com.foundation.web.interfaces.IWebApplication#handleWebSocketUpgrade(com.foundation.web.interfaces.IRequest, com.foundation.web.interfaces.IResponse, com.foundation.web.interfaces.ISession, boolean, boolean, com.foundation.web.interfaces.IConnectionContext, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) + */ +public void handleWebSocketUpgrade(IRequest request, IResponse response, ISession session, boolean isSecure, boolean clientHadBadSession, IConnectionContext connectionContext, String connection, String secWebSocketKey, String secWebSocketProtocol, String secWebSocketVersion, String origin) { +}//handleWebSocketUpgrade()// /* (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, com.foundation.web.interfaces.IConnectionContext) */ diff --git a/Foundation Web Application/src/com/foundation/web/IWebServerApplicationDefaults.java b/Foundation Web Application/src/com/foundation/web/IWebServerApplicationDefaults.java index 9a7270f..3bec09b 100644 --- a/Foundation Web Application/src/com/foundation/web/IWebServerApplicationDefaults.java +++ b/Foundation Web Application/src/com/foundation/web/IWebServerApplicationDefaults.java @@ -85,4 +85,6 @@ public interface IWebServerApplicationDefaults { "

For Apple Safari

" + "

Safari has a built in auto update system, but if you are still having problems you can reinstall it: Go to the Apple Safari website and click the \"Download Now\" link and follow the instructions.

" + ""; + public static final String UPGRADE_FAILED = + "Socket upgrade request failed or was rejected."; }//IWebServerApplicationDefaults// \ No newline at end of file diff --git a/Foundation Web Application/src/com/foundation/web/PassThroughDomain.java b/Foundation Web Application/src/com/foundation/web/PassThroughDomain.java index 6a5c2bc..b020942 100644 --- a/Foundation Web Application/src/com/foundation/web/PassThroughDomain.java +++ b/Foundation Web Application/src/com/foundation/web/PassThroughDomain.java @@ -262,6 +262,12 @@ public String getErrorHeader(int errorCode) { public ISession getSession(String sessionId) { return null; }//getSession()// +/* (non-Javadoc) + * @see com.foundation.web.interfaces.IWebApplication#handleWebSocketUpgrade(com.foundation.web.interfaces.IRequest, com.foundation.web.interfaces.IResponse, com.foundation.web.interfaces.ISession, boolean, boolean, com.foundation.web.interfaces.IConnectionContext, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) + */ +public void handleWebSocketUpgrade(IRequest request, IResponse response, ISession session, boolean isSecure, boolean clientHadBadSession, IConnectionContext connectionContext, String connection, String secWebSocketKey, String secWebSocketProtocol, String secWebSocketVersion, String origin) { + //Shouldn't ever get here I don't think.// +}//handleWebSocketUpgrade()// /* (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, com.foundation.web.interfaces.IConnectionContext) */ diff --git a/Foundation Web Application/src/com/foundation/web/ResourceRequestHandler.java b/Foundation Web Application/src/com/foundation/web/ResourceRequestHandler.java index 43a3e13..f56c13d 100644 --- a/Foundation Web Application/src/com/foundation/web/ResourceRequestHandler.java +++ b/Foundation Web Application/src/com/foundation/web/ResourceRequestHandler.java @@ -47,6 +47,10 @@ public ResourceRequestHandler() { Debug.log("Failed to read the framework.js file from the framework jar.", e); }//catch// }//ResourceRequestHandler()// +/** + * Gives the web application a chance to handle the web socket upgrade. + */ +public abstract void processWebSocketUpgrade(IRequest request, IResponse response, ISession session, boolean isSecure, boolean clientHadBadSession, IConnectionContext connectionContext, String connection, String secWebSocketKey, String secWebSocketProtocol, String secWebSocketVersion, String origin); /** * Allows the handler to substitute one path for another. * @param path The path that was provided by the client. diff --git a/Foundation Web Application/src/com/foundation/web/WebApplication.java b/Foundation Web Application/src/com/foundation/web/WebApplication.java index f7e1e3b..9a1933e 100644 --- a/Foundation Web Application/src/com/foundation/web/WebApplication.java +++ b/Foundation Web Application/src/com/foundation/web/WebApplication.java @@ -642,6 +642,10 @@ public IContent getErrorContent(int errorCode) { result = new HtmlContent(TLS_FAILURE); break; }//case// + case IResponse.ERROR_UPGRADE_REJECTED: { + result = new HtmlContent(UPGRADE_FAILED); + break; + }//case// }//case// return result; @@ -670,10 +674,25 @@ public String getErrorHeader(int errorCode) { result = "HTTP/1.1 200 Browser Upgrade Required\r\n"; break; }//case// + case IResponse.ERROR_UPGRADE_REJECTED: { + result = "HTTP/1.1 100 Socket Upgrade Failed/Rejected\r\n"; + break; + }//case// }//case// return result; }//getErrorHeader()// +/* (non-Javadoc) + * @see com.foundation.web.interfaces.IWebApplication#handleWebSocketUpgrade(com.foundation.web.interfaces.IRequest, com.foundation.web.interfaces.IResponse, com.foundation.web.interfaces.ISession, boolean, boolean, com.foundation.web.interfaces.IConnectionContext, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) + */ +public void handleWebSocketUpgrade(IRequest request, IResponse response, ISession session, boolean isSecure, boolean clientHadBadSession, IConnectionContext connectionContext, String connection, String secWebSocketKey, String secWebSocketProtocol, String secWebSocketVersion, String origin) { + if(resourceRequestHandler != null) { + resourceRequestHandler.processWebSocketUpgrade(request, response, session, isSecure, clientHadBadSession, connectionContext, connection, secWebSocketKey, secWebSocketProtocol, secWebSocketVersion, origin); + }//if// + else { + response.setError(IResponse.ERROR_UPGRADE_REJECTED); + }//else// +}//handleWebSocketUpgrade()// /* (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, com.foundation.web.interfaces.IConnectionContext) */