Giter Club home page Giter Club logo

jersey-mvc-jsp-freemarker-with-embedded-tomcat's Introduction

jersey-mvc-jsp-freemarker-with-embedded-tomcat

Build Status

This is a simple application that aims to create a REST full web services using embedded tomcat and jersey, for configuration information use yml file. This application also uses jsp and freemarker template that is rendered through REST api call. It mainly focuses to register the object instance to ResourceConfig instead of registering class.

Application Used
  • Tomcat v8.x
  • Jersey v2.5.1
  • JSP
  • YML
  • Freemarker
  • HTML/Angular/JavaScript

Application creates two tomcat context path. one for REST full api end point is /api and another one for web page is /webapp that is directly load from tomcat webapp base directory location /src/main/webapp.

File base = new File("src/main/webapp");
Context context = tomcat.addContext("/api", base.getAbsolutePath());
tomcat.addWebapp(null, "/webapp", base.getAbsolutePath());

This application uses a yml file for application configuration. First read configuration.yml file and pass the configuration to application.

#configuration.yml
#setting server configuration
server:
  port: 9292

#configure user name
user: "eigenharsha"

ResourceConfig (Jersey specific)

ResourceConfig is an extension of JAX-RS Application class but it provides some registration methods to make registering resources and providers more friendly. This applciation registered resource through class instance using public ResourceConfig register(Object component).

JspMvcFeature and FreemarkerMvcFeature used for jsp and freemarker template, html/angular/javascript directly loaded in web browser.

final ResourceConfig config = new ResourceConfig()
    .packages(Main.class.getPackage().getName())
    .register(new Resource(new Core(), configuration)) // create instance of Resource and dynamically register
    .register(JspMvcFeature.class) // register jspMVC
    .register(FreemarkerMvcFeature.class) // register FreemarkerMVC
    .property(ServletProperties.FILTER_FORWARD_ON_404, true);

return new ServletContainer(config);

An in-depth tutorial for Programmatic API for Building Resources is available here.

This project requires maven.

Get started

$ git clone https://github.com/eigenharsha/jersey-mvc-jsp-freemarker-with-embedded-tomcat.git
$ cd jersey-mvc-jsp-freemarker-with-embedded-tomcat
$ mvn clean install

Deploy on Heroku

I created a Procfile for deploying on Heroku. An in-depth tutorial for deploying on Heroku is available here.

$ web: sh target/bin/webapp

When this application be deployed then we will be able to access this REST services

Resource Endpoint
Dynamically created resource invoked http://localhost:9292/api/resource
Fetch user information from YML file http://localhost:9292/api/resource/user
Freemarker template http://localhost:9292/api/resource/freemarker
Jsp template http://localhost:9292/api/resource/jsp
HTML page http://localhost:9292/webapp/index.html

Questions or suggestions? Please don't hesitate to email me at [email protected]

jersey-mvc-jsp-freemarker-with-embedded-tomcat's People

Contributors

eigenharsha avatar

Watchers

James Cloos avatar  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.