You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@jakarta.apache.org by "David M. Karr" <dk...@tcsi.com> on 2000/10/09 18:06:52 UTC

Deploy semi-dynamic content (XML) separately from WAR file?

I'm looking at deploying a web application that uses JSP for
presentation, and XML/XSLT for dynamic content.  I could easily just
package it all into a deployed WAR file, and when the content changes,
I just redeploy the whole thing.  That seems pretty odd to me.  If my
"dynamic content" was obtained from a database, I certainly wouldn't
redeploy the entire application each time the database changed.

The "xsl:apply" tag from "taglibs" allows the specification of a
"context-relative" path to an XML data file (runtime settable).  I'd
like to be able to deploy the WAR with a property that states the root
of the XML data repository, so the XML data can be stored "outside" of
the WAR.  The property part seems feasible, but since the XML file
location is "context-relative", does that mean the file cannot reside
outside of the WAR file?  Perhaps this means I can't use the raw file
name, and I have to use the "class" approach for providing the data
(using the "nameXml" property instead of the "xml" property).

I'd also like to allow for the possibility of the content changing
while the application is running.  I would guess that means I should
use a "file semaphore" whose presence means that the database is in
the middle of being changed (there may be two or more interdependent
data files), and my use of "xsl:apply" would have to be wrapped with a
check for the "file semaphore", which would cause a relatively
friendly "data presently unavailable" message to appear in place of
the formatted XML data.

Are there any obvious issues or solutions that I'm not seeing here?
Note that outside of a trivial servlet application, this will be my
first "web" application, although I've being Javaing for 3 years.

-- 
===============================================================================
David M. Karr     ; dkarr@tcsi.com  ; w:(425)487-8312 ; TCSI & Best Consulting
Software Engineer ; Unix/Java/C++/X ; BrainBench CJ12P (#12004)


Re: Deploy semi-dynamic content (XML) separately from WAR file?

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
"David M. Karr" wrote:

> I'm looking at deploying a web application that uses JSP for
> presentation, and XML/XSLT for dynamic content.  I could easily just
> package it all into a deployed WAR file, and when the content changes,
> I just redeploy the whole thing.  That seems pretty odd to me.  If my
> "dynamic content" was obtained from a database, I certainly wouldn't
> redeploy the entire application each time the database changed.

That's for sure.

>
> The "xsl:apply" tag from "taglibs" allows the specification of a
> "context-relative" path to an XML data file (runtime settable).  I'd
> like to be able to deploy the WAR with a property that states the root
> of the XML data repository, so the XML data can be stored "outside" of
> the WAR.  The property part seems feasible, but since the XML file
> location is "context-relative", does that mean the file cannot reside
> outside of the WAR file?  Perhaps this means I can't use the raw file
> name, and I have to use the "class" approach for providing the data
> (using the "nameXml" property instead of the "xml" property).
>
> I'd also like to allow for the possibility of the content changing
> while the application is running.  I would guess that means I should
> use a "file semaphore" whose presence means that the database is in
> the middle of being changed (there may be two or more interdependent
> data files), and my use of "xsl:apply" would have to be wrapped with a
> check for the "file semaphore", which would cause a relatively
> friendly "data presently unavailable" message to appear in place of
> the formatted XML data.
>
> Are there any obvious issues or solutions that I'm not seeing here?
> Note that outside of a trivial servlet application, this will be my
> first "web" application, although I've being Javaing for 3 years.
>

I would approach your scenario like this:

* Write a simple servlet that provides the XML content dynamically.
  It could either read from files (and you can configure it with a pathname
  anywhere on your filesystem) or reads from the database and constructs
  the correct XML dynamically.

* Map this servlet (in the web.xml file) to a particular context-relative path.
  One convenient way to do this would be to map it to a pattern like this:

        <servlet-mapping>
            <servlet-name>LookupServlet</servlet-name>
            <url-pattern>/lookup/*</url-pattern>
        </servlet-mapping>

  in which case your servlet would be able to call request.getPathInfo()
  to see the part of the request that came after the servlet name, and can
  use that to decide what data to return.  The servlet can also use request
  parameters for this purpose.

* Use this servlet in the XSL taglib as the source of your dynamic data:

        <xsl:apply xsl="/mystylesheet.xsl">
            <xsl:include page="/lookup/customer?id=123"/>
        </xsl:apply>

  which would tell your servlet to lookup customer 123 and format it
  appropriately.

Craig McClanahan

====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat