Permalink
Browse files

Changed login.nsp into a reuseable servlet. Added Sencha Touch lib.

  • Loading branch information...
1 parent aabf582 commit d9bc3739878d6da596e8a278bbf54aa6709a5c70 @entmike committed Dec 17, 2010
Showing 2,952 changed files with 319,753 additions and 160 deletions.
View
@@ -84,6 +84,7 @@ exports.parseNSP = function(contents) {
exports.create = function(meta) {
// Constructor/Private
+ var lastModified = meta.lastModified;
var options = meta.options || {};
var stats = meta.stats || {};
stats.executions = 0;
@@ -117,7 +118,7 @@ exports.create = function(meta) {
/* Returns the time the HttpServletRequest object was last modified, in milliseconds since midnight January 1, 1970 GMT.
If the time is unknown, this method returns a negative number (the default).
*/
- return -1;
+ return lastModified || -1;
},
doOptions : function(request, response) {
/* Called by the server (via the service method) to allow a servlet to handle a OPTIONS request.
@@ -156,49 +157,66 @@ exports.create = function(meta) {
*/
response.setHeaders(request.getHeaders());
},
- service : function(request, response, callback) {
- /* Receives standard HTTP requests from the public service method and dispatches them to the doXXX methods defined
- in this class. There's no need to override this method.
- */
- var opts;
- switch (request.getMethod()) {
- case "GET" :
- opts = options.doGet; break;
- case "POST" :
- opts = options.doPost; break;
- case "DELETE" :
- opts = options.doDelete; break;
- case "PUT" :
- opts = options.doPut; break;
- case "OPTIONS" :
- this.doOptions(request, response); this.serviceComplete(request, response); break;
- case "TRACE" :
- this.doTrace(request, response); this.serviceComplete(request, response); break;
- default:
- }
- if(opts) {
- if(!opts.async) {
- try{ // Execute Servlet Code
- var async = opts.method.call(this, request, response, callback);
- // Give method a chance to be async if it needs to be
+ doGet : function(request, response, callback) {
+ return this._do(options.doGet, request, response, callback);
+ },
+ doPost : function(request, response, callback) {
+ return this._do(options.doPost, request, response, callback);
+ },
+ doDelete : function(request, response, callback) {
+ return this._do(options.doDelete, request, response, callback);
+ },
+ doPut : function(request, response, callback) {
+ return this._do(options.doPut, request, response, callback);
+ },
+ _do : function(o, request, response, callback) {
+ if(!o) {
+ response.sendError(500, new Error("Method " + request.getMethod() + " not supported for this servlet."));
+ }else{
+ if(!o.async) {
+ try{
+ var async = o.method.call(this, request, response, callback);
if(!async) this.serviceComplete(request, response);
}catch(e){
response.sendError(500, e);
stats.errors++;
}
- }else{ // Asynchronous Call
+ }else{
try{
- opts.method.call(this, request, response, callback);
+ o.method.call(this, request, response, callback);
}catch(e){
response.sendError(500, e);
stats.errors++;
}
}
- return (async)?async:(opts)?opts.async:false;
- }else{
- response.sendError(500, new Error("Method " + request.getMethod() + " not supported for this servlet."));
+ return (async)?async:(o)?o.async:false;
}
-
+ },
+ service : function(request, response, callback) {
+ /* Receives standard HTTP requests from the public service method and dispatches them to the doXXX methods defined
+ in this class. There's no need to override this method.
+ */
+ var opt;
+ var doMethod;
+ switch (request.getMethod()) {
+ case "GET" :
+ return this.doGet.call(this, request, response, callback);
+ break;
+ case "POST" :
+ return this.doPost.call(this, request, response, callback);
+ break;
+ case "DELETE" :
+ return this.doDelete.call(this, request, response, callback);
+ break;
+ case "PUT" :
+ return this.doPut.call(this, request, response, callback);
+ break;
+ case "OPTIONS" :
+ return this.doOptions(request, response); this.serviceComplete(request, response); break;
+ case "TRACE" :
+ return this.doTrace(request, response); this.serviceComplete(request, response); break;
+ default:
+ }
},
serviceComplete : function(request, response, callback) {
// See if session exists. If not, don't make a new one.
View
@@ -1,16 +1,34 @@
exports.create = function(options) {
// Private
var id = options.id;
+ // Node.JS Request Object
var request = options.req;
- var parameters = request.formData;
+ // Cookies
var cookies = options.cookies;
+ // Requested Session ID
var JSESSIONID = options.JSESSIONID;
var servletPath = options.servletPath;
var contextPath = options.contextPath;
var pathInfo = options.pathInfo;
var session;
var sessionManager = options.sessionManager;
+ // IP Address of client
var IP = request.connection.remoteAddress;
+ // Query String
+ var queryString = require('url').parse(request.url).query || "";
+ // Gather up GET and POST parameters
+ var postParameters = request.formData.fields || {};
+ var getParameters = require("querystring").parse(queryString) || {};
+ // Consolidate them
+ var parameters = postParameters;
+ for(gp in getParameters) {
+ if(parameters[gp]) {
+ parameters[gp]="," + getParameters[gp];
+ }else{
+ parameters[gp] = getParameters[gp];
+ }
+ }
+ // console.log(parameters);
// Public
return {
toString : function() { return "HttpServletRequest"; },
@@ -40,8 +58,8 @@ exports.create = function(options) {
getPathInfo : function() {
return pathInfo;
},
- getParameter : function(name) {
- return parameters[name];
+ getParameter : function(p) {
+ return (parameters[p] || null);
},
getParameterNames : function() {
var arr = [];
@@ -56,8 +74,7 @@ exports.create = function(options) {
return request.formData;
},
getQueryString : function() {
- var obj = require('url').parse(request.url).query;
- return obj || "";
+ return queryString;
},
isUserInRole : function(role) { /* Stub */ },
getUserPrincipal : function() { /* Stub */ },
View
@@ -103,7 +103,7 @@ exports.create = function(options) {
};
this.loadServlet(options);
}catch(e){
- console.log("Error initializing servlet [" + meta.name + "]\n\File: [" + servletFile + "].");
+ console.log("Error initializing servlet [" + webConfig.servlets[i].name + "]\n\File: [" + servletFile + "].");
console.log(e.stack.green);
}
}
@@ -211,6 +211,7 @@ exports.create = function(options) {
if(acceptEncoding && acceptEncoding.toLowerCase().indexOf("gzip") > -1) { // Accepts GZIP
if(!response.isCommited()) {
response.setHeader("Content-Encoding", "gzip");
+ // console.log(request.getPathInfo());
gzip({
data : response.getOutputStream(),
callback : function(err,data){
@@ -345,14 +346,15 @@ exports.create = function(options) {
});
if(servlet) { // Servlet Exists
var session = request.getSession(false);
- if(loginConfig.requireAuthentication // If context requires auth...
- && (!session || !session.getAttribute("authenticated")) // and Session is not authenticated...
- && URL!=loginConfig.loginMapping // and URL is not the login URL...
+ if(loginConfig.requireAuthentication // If context requires auth...
+ && (!session || !session.getAttribute("authenticated")) // and Session is not authenticated...
+ && mapping.name != loginConfig.loginServlet // and Servlet is not the Login Servlet...
&& (loginConfig.exceptionPolicy =="whitelist" && !this.getException(mapping.name))
) {
+ console.log("Redirecting to Login Page");
// Redirect to Login Page
response.setStatus(302);
- response.setHeader("Location", path + loginConfig.loginMapping);
+ response.setHeader("Location", path + "/login" + "?redir=" + (encodeURIComponent(path+URL)));
this.handleComplete(request, response);
}else{
var async = servlet.service(request, response, this.handleComplete); // Allow async to be dynamic
@@ -390,7 +392,10 @@ exports.create = function(options) {
getName : function() {
return name;
},
- getServletMappings : getServletMappings,
+ getLoginConfig : function() {
+ return loginConfig;
+ },
+ getServletMappings : getServletMappings,
getException : function(servletName){
if(!loginConfig.exceptions) return false;
for(var i=0;i<loginConfig.exceptions.length;i++){
@@ -451,14 +456,14 @@ exports.create = function(options) {
var servletData = fs.readFileSync(servletFile);
try{
var servletOptions = eval("("+ servletData.toString() +")");
+ var options = {
+ servletOptions : servletOptions,
+ meta : servlet.meta
+ };
+ this.loadServlet(options);
}catch(e2){
console.log(e2.stack.red);
}
- var options = {
- servletOptions : servletOptions,
- meta : servlet.meta
- };
- this.loadServlet(options);
}catch(e){
console.log("Error initializing servlet [" + name + "]\nFile: [" + servletFile + "].");
console.log(e.stack.green);
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit d9bc373

Please sign in to comment.