Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/delibero.git

Removed resolver dependency on app. Researched servlet map; abandoned approach due to WAR dependency.

AuthorDave Jarvis <email>
Date2015-01-22 19:59:38 GMT-0800
Commit79c5d065824f10bbcf2d97c6deeee7575ecf85df
Parent503c725
build.gradle
}
-
// Deploy static content into the resources/static directory.
task copyResources << {
compile "org.eclipse.jetty:jetty-xml:9.2.6.v20141205"
compile "org.eclipse.jetty:jetty-servlet:9.2.6.v20141205"
- compile "org.eclipse.jetty:jetty-io:9.2.6.v20141205"
+ compile "org.eclipse.jetty:jetty-webapp:9.2.6.v20141205"
// Logging, security, and persistence are cross-cutting concerns
resources/WEB-INF/web.xml
+<?xml version="1.0" encoding="utf-8"?>
+<web-app version="3.0"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
+ <listener>
+ <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
+ </listener>
+
+ <context-param>
+ <param-name>shiroConfigLocations</param-name>
+ <param-value>auth.properties</param-value>
+ </context-param>
+
+ <filter>
+ <filter-name>ShiroFilter</filter-name>
+ <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>ShiroFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ <dispatcher>REQUEST</dispatcher>
+ <dispatcher>FORWARD</dispatcher>
+ <dispatcher>INCLUDE</dispatcher>
+ <dispatcher>ERROR</dispatcher>
+ </filter-mapping>
+</web-app>
+
resources/auth.properties
post_auth = org.apache.shiro.web.filter.authc.FormAuthenticationFilter
-get_auth.loginUrl = /app/login
-get_auth.successUrl = /app/home
+post_auth.loginUrl = /app/login
+post_auth.successUrl = /app/home
-#authc.usernameParam = account
-#authc.passwordParam = password
+post_auth.usernameParam = account
+post_auth.passwordParam = password
[urls]
-/app/new = get_auth
+/app/new = post_auth
#/app/edit/** = authc
resources/jetty.xml
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
+<!--
+ | http://eclipse.org/jetty/documentation/current/configuring-connectors.html
+ +-->
<Configure id="Discuss" class="org.eclipse.jetty.server.Server">
<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
source/java/to/discuss/Main.java
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.webapp.WebAppContext;
+
import org.eclipse.jetty.servlet.ServletHolder;
public class Main implements Base {
public void run() throws Exception {
- ServletContextHandler context = new ServletContextHandler();
+ WebAppContext context = new WebAppContext();
+ configureWebApp( context );
configureAuthProperties();
configureSystemProperties();
server.start();
server.join();
+ }
+
+ /**
+ * <p>
+ * Ideally these values would be set in jetty.xml, via the Server's
+ * setHandler method taking a HandlerCollection instance. That line of
+ * development leads to the requirement of a WAR file. The path looks like:
+ * (1) update jetty.xml to use a HandlerCollection; (2) add a WebAppContext
+ * handler to the collection; (3) remove servlet map configuration from
+ * within the Java code to within the web.xml file; (4) configure the
+ * web.xml file to use a web-fragment.xml file so that servlet-mapping can
+ * be autogenerated using XSL; (5) add a configuration class definition
+ * <a href="http://eclipse.org/jetty/documentation/current/configuring-webapps.html">to the XML file</a>);
+ * (6) realize that the FragmentConfiguration code specifically requires
+ * a JAR (WAR) file
+ * <a href="https://github.com/jfinal/jetty-server/blob/master/src/main/java/org/eclipse/jetty/webapp/FragmentConfiguration.java">resource</a>.
+ * </p>
+ * <p>
+ * As such, a slight mix of properties files and XML configuration files
+ * are used so that the menu can be used to generate the servlet mapping
+ * without involving a WAR file.
+ * </p>
+ */
+ protected void configureWebApp( WebAppContext context ) {
+ context.setResourceBase( "build/resources" );
+ context.setDescriptor( "WEB-INF/web.xml" );
+ context.setContextPath( "/" );
}
}
- DefaultServlet staticServlet = new DefaultServlet();
- context.addServlet( new ServletHolder( staticServlet ), "/*" );
+ context.addServlet( new ServletHolder( createDefaultServlet() ), "/*" );
+ }
+
+ protected DefaultServlet createDefaultServlet() {
+ return new DefaultServlet();
}
source/java/to/discuss/servlet/App.java
}
+ /**
+ * Returns the transformer factory used to obtain a transformer engine.
+ * The factory has a custom URI resolver necessary to dereference the
+ * "template://discuss.to/app" HREF path.
+ */
protected TransformerFactory getTransformerFactory() {
TransformerFactory factory = TransformerFactory.newInstance();
- factory.setURIResolver( new AppURIResolver( this ) );
+ factory.setURIResolver( new AppURIResolver( getAppName() ) );
return factory;
}
+ /**
+ * Returns the XSL transformer engine.
+ */
protected Transformer getTransformer() throws Exception {
return getTransformerFactory().newTransformer( getStylesheet() );
source/java/to/discuss/util/AppURIResolver.java
import to.discuss.Base;
-import to.discuss.servlet.App;
/**
* Extends java.util.Properties to recursively parse ${property} values.
*/
public class AppURIResolver implements URIResolver, Base {
- private App app;
+ private String appName;
- public AppURIResolver( App app ) {
- setApp( app );
+ /**
+ * Constructs a resolver for applications.
+ *
+ * @param appName The name of the application to use as a path for URI
+ * resolution.
+ */
+ public AppURIResolver( String appName ) {
+ setAppName( appName );
}
}
+ /**
+ * Resolves the filename to use based on the app name.
+ */
private String getStylesheetFilename() {
- return String.format( "xsl%s%s.xsl", FILE_SEP, getApp().getAppName() );
+ return String.format( "xsl%s%s.xsl", FILE_SEP, getAppName() );
}
- private void setApp( App app ) {
- this.app = app;
+ private void setAppName( String appName ) {
+ this.appName = appName;
}
- private App getApp() {
- return this.app;
+ private String getAppName() {
+ return this.appName;
}
}
Delta100 lines added, 20 lines removed, 80-line increase