| compile "org.eclipse.jetty:jetty-servlet:9.2.6.v20141205" | ||
| + // Logging, security, and persistence are cross-cutting concerns | ||
| + //compile "org.aspectj:aspectjrt:1.8.4" | ||
| + | ||
| // Logging | ||
| compile "org.slf4j:slf4j-log4j12:1.7.9" |
| import javax.servlet.http.HttpServletResponse; | ||
| +// Include the status codes. | ||
| +import static javax.servlet.http.HttpServletResponse.*; | ||
| + | ||
| import javax.xml.transform.OutputKeys; | ||
| import javax.xml.transform.Result; | ||
| import javax.xml.transform.Source; | ||
| import javax.xml.transform.stream.StreamResult; | ||
| import javax.xml.transform.stream.StreamSource; | ||
| import javax.xml.transform.TransformerFactory; | ||
| import javax.xml.transform.Transformer; | ||
| -import javax.xml.transform.URIResolver; | ||
| import to.discuss.util.AppURIResolver; | ||
| private HttpServletRequest request; | ||
| private HttpServletResponse response; | ||
| + | ||
| + private int responseStatus = SC_OK; | ||
| public App() { | ||
| protected void sendHeader() throws Exception { | ||
| getResponse().setContentType( getContentType() ); | ||
| - getResponse().setStatus( HttpServletResponse.SC_OK ); | ||
| + getResponse().setStatus( getResponseStatus() ); | ||
| } | ||
| } | ||
| + /** | ||
| + * Retrieves the document requested by the user and transmits the HTML | ||
| + * content to the client. | ||
| + */ | ||
| private void sendContent() throws Exception { | ||
| + | ||
| Transformer transformer = getTransformer(); | ||
| transformer.setOutputProperty( OutputKeys.ENCODING, getEncoding() ); | ||
| protected TransformerFactory getTransformerFactory() { | ||
| TransformerFactory factory = TransformerFactory.newInstance(); | ||
| - URIResolver resolver = factory.getURIResolver(); | ||
| - factory.setURIResolver( new AppURIResolver( this, resolver ) ); | ||
| + factory.setURIResolver( new AppURIResolver( this ) ); | ||
| return factory; | ||
| private HttpServletResponse getResponse() { | ||
| return this.response; | ||
| + } | ||
| + | ||
| + /** | ||
| + * Return HTTP response status to return to the client. | ||
| + * | ||
| + * @return An HTTP status code (200 OK by default). | ||
| + */ | ||
| + private int getResponseStatus() { | ||
| + return this.responseStatus; | ||
| + } | ||
| + | ||
| + /** | ||
| + * Set HTTP response status to return to the client. | ||
| + * | ||
| + * @param responseStatus The status code to send to the client. | ||
| + */ | ||
| + private void setResponseStatus( int responseStatus ) { | ||
| + this.responseStatus = responseStatus; | ||
| } | ||
| } | ||
| import org.eclipse.jetty.servlet.ServletHolder; | ||
| +import org.apache.shiro.SecurityUtils; | ||
| +import org.apache.shiro.config.IniSecurityManagerFactory; | ||
| +import org.apache.shiro.mgt.SecurityManager; | ||
| +import org.apache.shiro.util.Factory; | ||
| + | ||
| import to.discuss.util.ResolvedProperties; | ||
| ServletContextHandler context = new ServletContextHandler(); | ||
| + configureAuthProperties(); | ||
| configureSystemProperties(); | ||
| configureServletMap( context ); | ||
| configureServletDefault( context ); | ||
| server.setHandler( context ); | ||
| server.start(); | ||
| server.join(); | ||
| + } | ||
| + | ||
| + /** | ||
| + * Reads from "auth.properties" to configure the authentication and | ||
| + * authorization provider. | ||
| + */ | ||
| + protected void configureAuthProperties() throws Exception { | ||
| + Factory<SecurityManager> factory = new IniSecurityManagerFactory( | ||
| + "classpath:auth.properties" ); | ||
| + | ||
| + SecurityManager securityManager = factory.getInstance(); | ||
| + SecurityUtils.setSecurityManager( securityManager ); | ||
| } | ||
| + /** | ||
| + * Reads from "system.properties" and calls System.setProperty on | ||
| + * each name/value pair listed in the file. | ||
| + */ | ||
| protected void configureSystemProperties() throws Exception { | ||
| Map<String, String> map = getSystemPropertyMap(); | ||
| /** | ||
| - * Extends java.util.Properties to recursively parse ${property} values. This | ||
| + * Extends java.util.Properties to recursively parse ${property} values. | ||
| */ | ||
| public class AppURIResolver implements URIResolver, Base { | ||
| - private URIResolver delegate; | ||
| private App app; | ||
| - public AppURIResolver( App app, URIResolver delegate ) { | ||
| + public AppURIResolver( App app ) { | ||
| setApp( app ); | ||
| - setDelegate( delegate ); | ||
| } | ||
| private App getApp() { | ||
| return this.app; | ||
| - } | ||
| - | ||
| - private void setDelegate( URIResolver delegate ) { | ||
| - this.delegate = delegate; | ||
| - } | ||
| - | ||
| - private URIResolver getDelegate() { | ||
| - return this.delegate; | ||
| } | ||
| } | ||
| <item id="12">new</item> | ||
| <item id="13">refute</item> | ||
| + <item id="15">log in</item> | ||
| + <item id="14">log out</item> | ||
| </items> | ||
| <menu id="1"> |
| Author | Dave Jarvis <email> |
|---|---|
| Date | 2015-01-19 13:22:12 GMT-0800 |
| Commit | 8dd7d954f82979d6d76b571f3504663153cb3993 |
| Parent | 97d69c5 |
| Delta | 59 lines added, 16 lines removed, 43-line increase |