Create REST APIs with JSP and SQL Tag library.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/ISSUE_TEMPLATE
src/main
.gitignore
.travis.yml
LICENSE
README.md
pom.xml

README.md

MASON Tweet

Build Status

Mason is an open-source, lightweight data access layer for REST resources designed to be used in Java web applications. It handles incoming API requests and routes the parameters to these resources.

Mason Resources

Mason resources are Plain Old JSPs with neat tag libraries. Mason doesn't encourage using scriptlets in Resource JSPs.

A Mason resource file represents a REST resource and contains JSP which describes the operations to be performed when an HTTP request is made to the resource.

Mason Query

Currently you can write inline queries in the resources. But we are working towards moving the queries outside the JSPs Issue #11, so you can reference them and queries become reusable. This will be done via query files.

How does Mason run APIs ?

Mason Jar

Mason Jar

Clone and package the project with mvn

mvn clean package

After that you can find mtg-mason-1.0.jar inside the target folder. You can use this jar as a dependency in your Java webapp.

How to use mason in your Webapp

  1. Place the mason jar file in {webAppDir}/WEB-INF/lib

  2. Download jstl jar file and place it inside {webAppDir}/WEB-INF/lib

  3. Create a folder {webAppDir}/WEB-INF/resources/{resourceVersion} and place your jsp files here.

  4. Import mtg-mason.tld inside your jsp file. This taglib is present inside the mason jar and enables usage of the mtg prefix. You will also need to import the jstl taglib. Your jsp file should contain the following

<% @taglib uri="mtg-mason.tld" prefix="mtg" %>
<% @taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<% @taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<% @taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
  1. Add the following filter inside {webAppDir}/WEB-INF/web.xml
<filter>
    <filter-name>RestRouterFilter</filter-name>
    <filter-class>com.metamug.api.filters.RestRouterFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>RestRouterFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

All requests made to the jsp resources are routed through this filter.

  1. Configure your data source in {webAppDir}/META-INF/context.xml file.

You can take a look at the sample webapp.

JDBC Drivers

Except for javaee-web-api since that would be present in your application server and any one out of HSQL, MySQL or PostgreSQL dependency. We also support Oracle database but due to licensing reason we can't ship oracle jdbc driver along with our MTG SERVER. So in case you are using Oracle database you'll have to manually install its driver as dependency and use that in this project. Instructions are given regarding how to do the same in below link(s) (You can refer either of them).

https://www.mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository/ OR https://stackoverflow.com/a/1074971/4800126

Data Format Support

Mason supports application/xml, applicaton/json and application/json+dataset Read More about how it is used here. https://metamug.com/docs/api-request

How To Contribute

Fork this repo and submit a PR against the listed issues. We will provide certificates to all those who succcessfully contribute and help close existing issues and submit new features.