Git Product home page Git Product logo

wai-servlet's Introduction

wai-servlet

CircleCI

Library to integrate eta wai applications with the servlet api

Getting Started

  • Visit the Getting Started eta instructions to build and install the library and the examples
  • In src/Network/Wai/Servlet/Examples.hs you can find some examples of wai applications and code to generate a servlet class that can be deployed in your favorite servlet container.
  • There are two options to deploy wai-servlet apps: generating a war file to be deployed in a servlet container or run it directly in a embedded one; this is the way more similar to use wai warp for haskell wai applications.

Running an application in a embedded servlet container

  • You need to install and set the wai-servlet-jetty-adapter package as a dependency. Currently is the unique adapter implemented for wai-servlet.
  • You have to import the module Network.Wai.Servlet.Handler.Jetty with the run function and call it with the port server and your application:
{-# LANGUAGE OverloadedStrings #-}
import Network.HTTP.Types                 (status200)
import Network.Wai
import Network.Wai.Servlet
import Network.Wai.Servlet.Handler.Jetty

appSimple :: Application
appSimple _ respond = respond $
   responseLBS status200 [("Content-Type", "text/plain")] "Hello World"

main = run 3000 appSimple

Generating a war to be deployed in a servlet container

  • This option supposes some manual steps. There is plans to make etlas build automatically a war file, tracked in this issue.
  • The main function to generate the servlet is Network.Wai.Servlet.makeServiceMethod for example:
{-# LANGUAGE OverloadedStrings #-}
import Java
import Network.Wai
import Network.HTTP.Types                 (status200)
import Network.Wai.Servlet

appSimple :: Application
appSimple _ respond = respond $
   responseLBS status200 [("Content-Type", "text/plain")] "Hello World"

servSimple :: DefaultWaiServletApplication
servSimple = makeServiceMethod appSimple

foreign export java "service" servSimple :: DefaultWaiServletApplication
  • This code will generate a network.wai.servlet.DefaultWaiServlet java class that extends javax.servlet.GenericServlet suitable to use in a standard war file
  • To generate the war you have to create the standard directory structure:
    • webApp
      • static resources (jsp,html,etc)
      • META-INF
      • WEB-INF
        • web.xml (required if you use servlets)
        • classes
        • lib
          • wai-servlet-app.jar
  • The web.xml for the default wai servlet could be
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5" 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_2_5.xsd">
	<display-name>wai-servlet-test</display-name>

	<servlet>
		<servlet-name>wai-servlet</servlet-name>
		<servlet-class>network.wai.servlet.DefaultWaiServlet</servlet-class>
	</servlet>
	
	<servlet-mapping>
		<servlet-name>wai-servlet</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
	
</web-app>

wai-servlet's People

Contributors

jneira avatar rahulmutt avatar

Stargazers

 avatar

Watchers

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