Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cleanup

  • Loading branch information...
commit a7ffe802f6c601e195b485101e4ecf8eb917aefb 1 parent 4a44268
@jamesward authored
View
33 README.md
@@ -0,0 +1,33 @@
+Containerless Spring MVC
+------------------------
+
+Run Spring MVC in a self-contained / containerless application.
+
+### Run Locally
+
+Build with Maven:
+
+ mvn package
+
+Run:
+
+ java -cp target/classes:target/dependency/* com.jamesward.Webapp
+
+Open:
+
+> [http://localhost:8080](http://localhost:8080)
+
+
+### Run on Heroku
+
+Create an app:
+
+ heroku create
+
+Deploy:
+
+ git push heroku master
+
+Open:
+
+ heroku open
View
6 pom.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
- <groupId>com.example</groupId>
- <artifactId>springmvc-https-enforcer</artifactId>
+ <groupId>com.jamesward</groupId>
+ <artifactId>containerless-spring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
@@ -19,7 +19,7 @@
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
- <version>8.1.3.v20120416</version>
+ <version>8.1.5.v20120716</version>
</dependency>
</dependencies>
View
39 src/main/java/com/jamesward/HttpsEnforcer.java
@@ -1,39 +0,0 @@
-package com.jamesward;
-
-import javax.servlet.*;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-public class HttpsEnforcer implements Filter {
-
- private FilterConfig filterConfig;
-
- public static final String X_FORWARDED_PROTO = "x-forwarded-proto";
-
- @Override
- public void init(FilterConfig filterConfig) throws ServletException {
- this.filterConfig = filterConfig;
- }
-
- @Override
- public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
-
- HttpServletRequest request = (HttpServletRequest) servletRequest;
- HttpServletResponse response = (HttpServletResponse) servletResponse;
-
- if (request.getHeader(X_FORWARDED_PROTO) != null) {
- if (request.getHeader(X_FORWARDED_PROTO).indexOf("https") != 0) {
- response.sendRedirect("https://" + request.getServerName() + request.getPathInfo());
- return;
- }
- }
-
- filterChain.doFilter(request, response);
- }
-
- @Override
- public void destroy() {
- // nothing
- }
-}
View
1  src/main/java/com/jamesward/WebConfig.java
@@ -1,6 +1,5 @@
package com.jamesward;
-import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;
View
4 src/main/java/com/jamesward/Webapp.java
@@ -6,9 +6,6 @@
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
-import javax.servlet.DispatcherType;
-import java.util.EnumSet;
-
public class Webapp {
@@ -21,7 +18,6 @@ public static void main(String[] args) throws Exception {
final ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
context.addServlet(servletHolder, "/*");
- context.addFilter(HttpsEnforcer.class, "/*", EnumSet.of(DispatcherType.REQUEST));
String webPort = System.getenv("PORT");
if (webPort == null || webPort.isEmpty()) {
View
2  src/main/resources/assets/index.html
@@ -1,6 +1,6 @@
<!doctype html>
<html>
<body>
-hello, HTTPS
+hello, world
</body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.