Diff for revision 1226
=== modified file 'src/com/pugh/sockso/web/ServerThread.java'
--- src/com/pugh/sockso/web/ServerThread.java 2010-01-05 23:36:21 +0000
+++ src/com/pugh/sockso/web/ServerThread.java 2010-02-18 08:21:19 +0000
@@ -20,8 +20,6 @@
import java.net.Socket;
import java.net.SocketException;
-import java.sql.SQLException;
-
import org.apache.log4j.Logger;
public class ServerThread extends Thread {
@@ -93,40 +91,7 @@
&& !req.getHeader("User-Agent").contains("Safari")
);
- //
- // are we set up to log requests?
- //
-
- if ( p.get(Constants.WWW_LOG_REQUESTS_ENABLED).equals(p.YES) ) {
- final RequestLogger logger = new DbRequestLogger( db );
- logger.log(
- user,
- client.getInetAddress().getHostAddress(),
- req.getResource(),
- req.getHeader( "User-Agent" ),
- req.getHeader( "Referer" ),
- req.getHeader( "Cookie" )
- );
- }
-
- //
- // dispatch the action...
- //
-
- final WebAction action = dispatcher.getAction( req );
-
- if ( action == null )
- throw new BadRequestException( locale.getString("www.error.unknownRequest"), 400 );
- else {
- // inject common dependencies...
- action.init( req, res, user, locale );
- if ( p.get(Constants.WWW_USERS_REQUIRE_LOGIN).equals(p.YES)
- && user == null
- && action.requiresLogin() )
- res.redirect( "/user/login" );
- else
- action.handleRequest();
- }
+ process( user, req, locale, res );
}
@@ -161,6 +126,52 @@
}
/**
+ * Process a request and generate a response
+ *
+ * @param user
+ * @param req
+ * @param locale
+ * @param res
+ *
+ * @throws Exception
+ *
+ */
+
+ protected void process( final User user, final Request req, final Locale locale, final Response res ) throws Exception {
+
+ //
+ // are we set up to log requests?
+ //
+ if ( p.get(Constants.WWW_LOG_REQUESTS_ENABLED).equals(p.YES) ) {
+ final RequestLogger logger = new DbRequestLogger( db );
+ logger.log( user, client.getInetAddress().getHostAddress(),
+ req.getResource(), req.getHeader("User-Agent"),
+ req.getHeader("Referer"), req.getHeader("Cookie") );
+ }
+
+ //
+ // dispatch the action...
+ //
+
+ final WebAction action = dispatcher.getAction( req );
+
+ if ( action == null ) {
+ throw new BadRequestException(locale.getString("www.error.unknownRequest"), 400);
+ }
+
+ else {
+ // inject common dependencies...
+ action.init(req, res, user, locale);
+ if (p.get(Constants.WWW_USERS_REQUIRE_LOGIN).equals(p.YES) && user == null && action.requiresLogin()) {
+ res.redirect("/user/login");
+ } else {
+ action.handleRequest();
+ }
+ }
+
+ }
+
+ /**
* shows an error, and sends the status code in the response
*/
=== modified file 'test/com/pugh/sockso/web/ServerThreadTest.java'
--- test/com/pugh/sockso/web/ServerThreadTest.java 2009-05-10 22:31:07 +0000
+++ test/com/pugh/sockso/web/ServerThreadTest.java 2010-02-18 08:21:19 +0000
@@ -62,6 +62,10 @@
}
+ public void testSlashFaviconRequestsIgnored() {
+ // @TODO
+ }
+
/**
* returns a socket whose getInmputStream will produce
* a stream with the specified data