Revision [1086]

This is an old revision of EmbeddingServlet made by DavidLee on 2009-12-03 10:29:30.

 

Embedding xmlsh as a Servlet


Xmlsh comes with a generic Servlet class which can be used, extended, or you can write your own.
This is based on J2EE Servlet Containers but is only tested with Tomcat 6.

The Servlet can is registered using the standard WAR file structure which you must create youself.
When the servlet is bound to a URI, the file portion of the URI is mapped to a server side directory and executes xmlsh scripts from within that directory.

For example, given this example web.xml file

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

  <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
    version="2.4">

   
  <description>xmlsh tomcat application</description>
  <servlet>
      <servlet-name>XmlshServlet</servlet-name>
      <servlet-class>org.xmlsh.servlet.XmlshServlet</servlet-class>
      <init-param>
       
      <param-name>root</param-name>
      <param-value>/var/xmlsh</param-value>
      </init-param>
     
     <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>XmlshServlet</servlet-name>
        <url-pattern>*.xsh</url-pattern>
    </servlet-mapping>
     
</web-app>



Request to http://host/xmlsh/script.xsh then the corresponding script in /var/xmlsh/script.xsh is executed.
If a GET request is performed then the input to the script is null. If a POST command is performed then the input to the script is the body of the POST command. The output of the script becomes the response body.

The content-type of the response body is set to the content-type property of the shell after invocation of the script.

Examples

Example
The following script invokes an xslt command on the input and outputs the result to the output, setting the content type to "text/html"

set -content-type text/html
xslt1 -f /test/spl.xsl


To Do

Currently no arguments are passed to the servlet script. I am considering passing query args from the request as arguments to the script.




There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki