GithubHelp home page GithubHelp logo

spring-one-2014-boot-web's Introduction

Spring Boot for the Web Tier

Introduction

This is code from the ``Spring Boot for the Web Tier'' presentation given at SpringOne 2014. It demonstrates a number of Spring Boot features that are particularly relevant to web developers.

Use git log to see how the application was constructed and git reset --hard if you want to go back to a particular point in time.

Credits

This demonstration uses CSS and Javascript from the ``Text Opening Sequence with CSS Animations'' article by Mary Lou. It also uses Jars from the webjars project.

Building and running the code

This project can be build using Apache Maven from the root directory:

$ mvn clean package

Once build code can be run using java -jar:

$ java -jar target/spring-one-boot-web-0.0.1-SNAPSHOT.jar

In addition, if you want to run the Apache HTTP SSL demo you will need docker (see instructions below).

Demos

Static Content

Static content is served from src/main/resources/public. You can see an index.html file which is automatically mapped to http://localhost:8080/. You can also see how a custom src/main/resources/favicon.ico file can be used.

Additional this project demonstrates how jQuery can be loaded from a `webjar'' and how wro4j can be used to process a `less css file.

Dynamic Content

The /hello/{name} endpoint demonstrates how dynamic content can be created using Groovy templates. It also shows internationalization using Spring’s MessageSource interface.

The /convert endpoint shows how a custom HttpMessageConverter can be used. Notice that ExampleRestController returns a list, which is converted by ListHttpMessageConverter. If you comment out the @Component annotation from ListHttpMessageConverter you’ll see a standard JSON response instead.

HTTPD Proxy

The /whoami endpoint can be used to show how Apache HTTPD can be used as an SSL terminating proxy in front of a Spring Boot application. For convenience a dockerfile is provided to create a configured HTTPD installation.

To build the docker image:

$ docker build -t springone/httpd-proxy httpd-docker

When running image you need to ensure that a TOMCAT_HOST environment variable has been set to the IP address of your local machine. The following commands should work on most machines:

$ export TOMCAT_HOST=$(ifconfig | sed -En '/docker/,+2d;s/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p' | head -n 1)
$ docker run -i -d -p 8081:80 -p 8082:443 -e TOMCAT_HOST springone/httpd-proxy

If you have problems check that TOMCAT_HOST has the correct IP address.

To test the application you can first curl directly to your running application:

$ curl http://127.0.0.1:8080/whoami
$ curl -k https://127.0.0.1:8080/whoami

The first command should return http://127.0.0.1:8080, the second should fail because SSL hasn’t been configured.

To test via the HTTPD proxy:

$ curl http://127.0.0.1:8081/whoami
$ curl -k http://127.0.0.1:8082/whoami

or if you’re on a mac using boot2docker:

$ curl http://$(boot2docker ip 2>/dev/null):8081/whoami
$ curl -k https://$(boot2docker ip 2>/dev/null):8082/whoami

This time you should see a different IP address and the second command should report a https:// address.

spring-one-2014-boot-web's People

Contributors

philwebb avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.