Fall Semester 2002


More BWS: SOAP

We first make sure we know what code will be discussed.

frilled.cs.indiana.edu%pwd
/nfs/grouchy/home/user2/www/classes/a348-dger/sum2002/notes/axis/examples
frilled.cs.indiana.edu%du -a | grep ch3
1	./src/ch3/ex2/InventoryCheckClient.java
2	./src/ch3/ex2
2	./src/ch3/ex3/InventoryCheckClient.java
3	./src/ch3/ex3
2	./src/ch3/ex4/POSubmissionClient.java
3	./src/ch3/ex4
9	./src/ch3
1	./webapps/bws/ch3/ex1/index.jsp
1	./webapps/bws/ch3/ex1/intro.html
1	./webapps/bws/ch3/ex1/inventoryCheck.jsp
2	./webapps/bws/ch3/ex1/productListing.jsp
1	./webapps/bws/ch3/ex1/toc-prods.html
1	./webapps/bws/ch3/ex1/toc.html
1	./webapps/bws/ch3/ex1/top.html
9	./webapps/bws/ch3/ex1
1	./webapps/bws/ch3/ex2/_buildSKUList.jsp
2	./webapps/bws/ch3/ex2/index.jsp
4	./webapps/bws/ch3/ex2
2	./webapps/bws/ch3/ex3/index.jsp
3	./webapps/bws/ch3/ex3
2	./webapps/bws/ch3/ex4/index.jsp
3	./webapps/bws/ch3/ex4
20	./webapps/bws/ch3
frilled.cs.indiana.edu%
Where do we start?

frilled.cs.indiana.edu%pwd
/nfs/grouchy/home/user2/www/classes/a348-dger/sum2002/notes/axis/examples
frilled.cs.indiana.edu%cat ./webapps/bws/ch3/ex1/index.jsp
<html>

<title>Welcome to SkatesTown!</title>

<frameset rows="100,*" border=0>
  <frame src="top.html" name="top" id="top" scrolling="No">
  <frameset cols="130,*" border=0>
    <frame name="toc" src="toc.html">
    <frame name="body" src="intro.html">
  </frameset>
</frameset>

</html>
frilled.cs.indiana.edu%
Well, that doesn't show us much, so let's look for some more.

frilled.cs.indiana.edu%pwd
/nfs/grouchy/home/user2/www/classes/a348-dger/sum2002/notes/axis/examples/webapps/bws/ch3
frilled.cs.indiana.edu%ls -ld *
drwxr-xr-x   2 dgerman  faculty       512 Jan 21  2002 ex1
drwxr-xr-x   2 dgerman  faculty       512 Jan 21  2002 ex2
drwxr-xr-x   2 dgerman  faculty       512 Jan 21  2002 ex3
drwxr-xr-x   2 dgerman  faculty       512 Jan 21  2002 ex4
frilled.cs.indiana.edu%du -a ex1
1	ex1/index.jsp
1	ex1/intro.html
1	ex1/inventoryCheck.jsp
2	ex1/productListing.jsp
1	ex1/toc-prods.html
1	ex1/toc.html
1	ex1/top.html
9	ex1
frilled.cs.indiana.edu%more ex1/*.html
::::::::::::::
ex1/intro.html
::::::::::::::
<html>
  Talk about who we are...
</html>
::::::::::::::
ex1/toc-prods.html
::::::::::::::
<html>

<a href="intro.html" target="body">Company Info</a><br>
<a href="toc-prods.html" target="toc">Products</a><br>
  <a target="body" href="productListing.jsp?query=all">All</a><br>
  <a target="body" href="productListing.jsp?query=skateboard">Skate Boards</a><br>
  <a target="body" href="productListing.jsp?query=scooter">Scooters</a><br>
  <a target="body" href="productListing.jsp?query=misc">Miscellaneous</a>

</html>
::::::::::::::
ex1/toc.html
::::::::::::::
<html>
<a href="intro.html" target="body">Company Info</a><br>
<a href="toc-prods.html">Products</a>
</html>
::::::::::::::
ex1/top.html
::::::::::::::
<html> <font size="7">Welcome to SkatesTown!</font> 
<hr>
</html>
frilled.cs.indiana.edu%
So we now see that almost everything revolves around productListing.jsp.

frilled.cs.indiana.edu%pwd
/nfs/grouchy/home/user2/www/classes/a348-dger/sum2002/notes/axis/examples/webapps/bws/ch3
frilled.cs.indiana.edu%du -a | grep Listing
2	./ex1/productListing.jsp
frilled.cs.indiana.edu%pwd
/nfs/grouchy/home/user2/www/classes/a348-dger/sum2002/notes/axis/examples/webapps/bws/ch3
frilled.cs.indiana.edu%cat ./ex1/productListing.jsp 
<%@ page import="bws.BookUtil,com.skatestown.data.Product,com.skatestown.backend.ProductDB" %>

<html>

<%
  String prodType = request.getParameter( "query" );
  if (prodType == null) { prodType = "all"; }
%>
  <font size=+1><b>Product Search: <i><%= prodType %></i></b></font><br>
  <form action="inventoryCheck.jsp" method="POST">
  <ol>
<%
  ProductDB  db = BookUtil.getProductDB(application);
  Product[]  prodList = db.getProducts();

  int count = 0;
  for (int i = 0 ; i < prodList.length ; i++ ) {
    if ( prodType.equals("all") || prodType.equals( prodList[i].getType() ) ) {
      if ( count != 0 ) out.println("<hr>");
      count++ ;
%>
    <li> <input type=radio name="sku" value=<%=prodList[i].getSKU()%>>
         <font size=+1><b> <%=prodList[i].getName()%> </font></b>
         - $ <%=prodList[i].getUnitPrice()%>
         <br> <%=prodList[i].getDescription() %>
<%
    }
  }
%>
  </ol>
  Items found: <%= count %> <p>
  Desired quantity: <input type="text" name="num" value="1" size="5">
  <input type="submit" value=" Check inventory ">
  </form>

</html>
frilled.cs.indiana.edu%
The rest of the code is also needed:

And of course, the processing page is important too:

frilled.cs.indiana.edu%pwd
/nfs/grouchy/home/user2/www/classes/a348-dger/sum2002/notes/axis/examples/webapps/bws/ch3
frilled.cs.indiana.edu%du -a . | grep -i inventory
1	./ex1/inventoryCheck.jsp
frilled.cs.indiana.edu%cat ./ex1/inventoryCheck.jsp 
<%@ page import="bws.BookUtil,com.skatestown.data.Product,com.skatestown.backend.ProductDB" %>
<html>
  <%
    String     sku         = request.getParameter( "sku" );
    if (sku == null) {
      out.println("Please, select a product from the list " + 
                  "before checking its availability...");
    } else { 
      String     strQuantity = request.getParameter( "num" );
      if ( strQuantity  == null || strQuantity.equals("") ) strQuantity = "1" ; 
      int quantity = Integer.parseInt( strQuantity );
      ProductDB  db = BookUtil.getProductDB(application);
      Product    p = db.getBySKU(sku);
		
      if (p == null) {
        out.println("Sorry, we no longer carry this product...");
      } else {
  %>
    <font size=+1><b>Product: <%= p.getName()%></b></font><br>
    <%= p.getDescription()%><p>
  <% 
        if ( p.getNumInStock() >= quantity ) 
          out.println( "Yes we have " + quantity );
        else
          out.println( "No we don't have " + quantity + " we only have " + p.getNumInStock());
      }
    }
  %>

</html>
frilled.cs.indiana.edu%
But this is where this first example ends.

So what do we know now?

Here's where the file is
burrowww.cs.indiana.edu% pwd
/nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4/webapps/bws/ch3/ex1
burrowww.cs.indiana.edu% ls -ld ../../resources/products*
-rw-r--r--   1 dgerman  faculty      1365 Nov 25 21:11 ../../resources/products.xml
burrowww.cs.indiana.edu% 
Here's the contents
<?xml version="1.0" encoding="UTF-8"?>
<products>
   <product>
      <sku>947-TI</sku>
      <name>Titanium Glider</name>
      <type>skateboard</type>
      <desc>Street-style titanium skateboard.</desc>
      <price>129.00</price>
      <inStock>36</inStock>
   </product>
   <product>
      <sku>270-SB</sku>
      <name>SuperFlyer</name>
      <type>skateboard</type>
      <desc>Super fast skateboard</desc>
      <price>250.00</price>
      <inStock>6</inStock>
   </product>
   <product>
      <sku>275-SB</sku>
      <name>SuperFlyer II</name>
      <type>skateboard</type>
      <desc>Super fast skateboard - son of SuperFlyer</desc>
      <price>450.00</price>
      <inStock>13</inStock>
   </product>
   <product>
      <sku>912-SK</sku>
      <name>STooter</name>
      <type>scooter</type>
      <desc>Single user scooter - only in red</desc>
      <price>72.00</price>
      <inStock>50</inStock>
   </product>
   <product>
      <sku>318-BP</sku>
      <name>SkatePack 500</name>
      <type>misc</type>
      <desc>Skateboard backpack; five pockets</desc>
      <price>49.95</price>
      <inStock>72</inStock>
   </product>
   <product>
      <sku>008-PR</sku>
      <name>Promo 8</name>
      <type>misc</type>
      <desc>Promotional: SkatesTown stickers</desc>
      <price>0.00</price>
      <inStock>10000</inStock>
   </product>
</products>
And here's where the BookUtil class can be found.

frilled.cs.indiana.edu%pwd
/nfs/grouchy/home/user2/www/classes/a348-dger/sum2002/notes/axis/examples/src/bws
frilled.cs.indiana.edu%ls
BookUtil.java
frilled.cs.indiana.edu%
Here's the contents, that we will have to change soon.

package bws;

import java.io.Reader;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.BufferedInputStream;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import org.w3c.dom.Document;
import org.apache.axis.MessageContext;
import org.apache.axis.transport.http.HTTPConstants;
import com.skatestown.backend.ProductDB;

public class BookUtil {
    static final String SITE_URL_PROPERTY_NAME = "bws.siteUrl";
    static final String DEFAULT_SITE_URL = "http://localhost:8080/bws/";
    static final String AXIS_RELATIVE_URL = "services/";
    
    public static String getSiteUrl() {
        return System.getProperty(SITE_URL_PROPERTY_NAME, DEFAULT_SITE_URL);
    }

    public static String getServiceUrl() {
        return getSiteUrl() + AXIS_RELATIVE_URL;
    }

    public static String getServiceUrl(String localPart) {
        return getServiceUrl() + localPart;
    }

    public static ServletContext getContext(MessageContext ctx) {
        HttpServlet servlet =
            (HttpServlet)ctx.getProperty(HTTPConstants.MC_HTTP_SERVLET);
        return servlet.getServletConfig().getServletContext();
    }
    
    public static String getResourcePath(ServletContext ctx, String path) {
        return ctx.getRealPath(path);
    }

    public static String getResourcePath(MessageContext ctx, String path) {
        return getResourcePath(getContext(ctx), path);
    }

    public static InputStream getResourceInputStream(ServletContext ctx,
                                                     String path)
        throws IOException
    {
        return new BufferedInputStream(new FileInputStream(getResourcePath(ctx, path)));
    }

    public static InputStream getResourceInputStream(MessageContext ctx,
                                                     String path)
        throws IOException
    {
        return getResourceInputStream(getContext(ctx), path);
    }
    
    public static Reader getResourceReader(ServletContext ctx, String path)
        throws IOException
    {
        return new BufferedReader(new FileReader(getResourcePath(ctx, path)));
    }

    public static Reader getResourceReader(MessageContext ctx, String path)
        throws IOException
    {
        return getResourceReader(getContext(ctx), path);
    }

    public static Document getResourceXML(ServletContext ctx, String path)
        throws Exception
    {
        InputStream in = getResourceInputStream(ctx, path);
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.parse(in);
        in.close();
        return doc;
    }

    public static Document getResourceXML(MessageContext ctx, String path)
        throws Exception
    {
        return getResourceXML(getContext(ctx), path);
    }

    public static Document getXML(String realPath) throws Exception {
        InputStream in = new BufferedInputStream(new FileInputStream(realPath));
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.parse(in);
        in.close();
        return doc;
    }

    public static String readResource(ServletContext ctx, String path)
        throws IOException
    {
        Reader rin = getResourceReader(ctx, path);
        return readFile(rin);
    }

    public static String readResource(MessageContext ctx, String path)
        throws IOException
    {
        Reader rin = getResourceReader(ctx, path);
        return readFile(rin);
    }

    public static String readFile(Reader rin) throws IOException {
        char[] buf = new char[2048];
        StringBuffer sb = new StringBuffer();
        int len = -1;
        while ((len = rin.read(buf)) != -1) sb.append(buf, 0, len);
        rin.close();
        return sb.toString();
    }
    
    public static ProductDB getProductDB(ServletContext ctx)
        throws Exception
    {
        Document productXML = getResourceXML(ctx, "/resources/products.xml");
        return new ProductDB(productXML);
    }

    public static ProductDB getProductDB(MessageContext ctx)
        throws Exception
    {
        return getProductDB(getContext(ctx));
    }
}
Here are some predefined variables in JSP:

One of them is used in inventoryCheck.jsp and things should be clear now.

So far, no SOAP. But we're getting there.

The application presented above is a good start, but now SkatesTown's partners are demanding the ability to have their purchasing applications directly inquire about order availability.

So let's install it as a web service.

The web service is here:

frilled.cs.indiana.edu%pwd
/nfs/grouchy/home/user2/www/classes/a348-dger/sum2002/notes/axis/examples/webapps
frilled.cs.indiana.edu%ls -l
total 1
drwxr-xr-x  10 dgerman  faculty       512 Jan 21  2002 bws
frilled.cs.indiana.edu%du -a . | grep -i inventory
1	./bws/ch3/ex1/inventoryCheck.jsp
1	./bws/inventory/InventoryCheck.jws
2	./bws/inventory
frilled.cs.indiana.edu%cat ./bws/inventory/InventoryCheck.jws 
import org.apache.axis.MessageContext;
import bws.BookUtil;
import com.skatestown.data.Product;
import com.skatestown.backend.ProductDB;

/**
 * Inventory check Web service
 */
public class InventoryCheck
{
	/**
	 * Checks inventory availability given a product SKU and
	 * a desired product quantity.
	 *
	 * @param msgContext    This is the Axis message processing context
	 *                      BookUtil needs this to extract deployment
	 *                      information to load the product database.
	 * @param sku           product SKU
	 * @param quantity      quantity desired
	 * @return              true|false based on product availability
	 * @exception Exception most likely a problem accessing the DB
	 */
	public static boolean doCheck(MessageContext msgContext,
                                      String sku, int quantity)
	throws Exception
	{
		ProductDB db = BookUtil.getProductDB(msgContext);
		Product prod = db.getBySKU(sku);
		return (prod != null && prod.getNumInStock() >= quantity);
	}
}
frilled.cs.indiana.edu%
The question is:

Fortunately it's easy to install axis, and we have done that already.

So adding a .jws file is basically nothing.

First, however, we take the service requestor perspective.

There are two files (one includes the other) that help make the call.

burrowww.cs.indiana.edu% pwd
/nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4/webapps/bws
burrowww.cs.indiana.edu% ls -l
total 14
drwxr-xr-x   3 dgerman  faculty       512 Nov 25 23:23 WEB-INF
drwxr-xr-x   3 dgerman  faculty       512 Nov 25 21:11 ch2
drwxr-xr-x   6 dgerman  faculty       512 Nov 25 21:11 ch3
drwxr-xr-x   2 dgerman  faculty       512 Nov 25 21:11 ch4
drwxr-xr-x   8 dgerman  faculty       512 Nov 25 21:11 ch5
-rw-r--r--   1 dgerman  faculty       413 Nov 25 21:15 client-config.xml
-rw-r--r--   1 dgerman  faculty       230 Nov 25 21:11 index.html
drwxr-xr-x   2 dgerman  faculty       512 Nov 25 21:11 inventory
drwxr-xr-x   2 dgerman  faculty       512 Nov 25 21:11 resources
-rw-r--r--   1 dgerman  faculty      3164 Nov 25 21:11 source.html
drwxr-xr-x   2 dgerman  faculty       512 Nov 25 21:11 util
burrowww.cs.indiana.edu% ls ch3
ex1  ex2  ex3  ex4
burrowww.cs.indiana.edu% ls ch3/ex2
_buildSKUList.jsp  index.jsp
burrowww.cs.indiana.edu% cat ch3/ex2/index.jsp 
<%@page import="bws.BookUtil,ch3.ex2.InventoryCheckClient"%>
<%
  String sku = request.getParameter("sku");
  String quantity = request.getParameter("quantity");
%>

<h1>SOAP Inventory Check</h1>
<form action="index.jsp" method="POST">
  <p>Given a SKU and a desired product quantity, this example will make 
  a SOAP call to the inventory check web service.</p>
  <table border="0" cellspacing="3">
    <tr> <td align="right">SKU:</td>
         <td> <%@include file="_buildSKUList.jsp"%> </td> </tr>
    <tr> <td align="right">Quantity:</td>
         <td> <input name="quantity" type="text"
                     value="<%= quantity != null ? quantity : "1"%>">
         </td> </tr>
    <tr> <td align="right"></td>
         <td> <input type="submit" value=" Check inventory "> </td> </tr>
  </table>
</form> <hr>
<%
  if (sku != null) {
    String serviceUrl = BookUtil.getSiteUrl() + "inventory/InventoryCheck.jws";
    InventoryCheckClient invCheck = new InventoryCheckClient(serviceUrl);

    int qty = Integer.parseInt(quantity);
    boolean result = invCheck.doCheck(sku, qty);
    if (result) { out.println("The item is available."); }
    else { out.println("The item is not available."); }
  }
%>
burrowww.cs.indiana.edu% 
Let's see the second file:

burrowww.cs.indiana.edu% cat _bu*.jsp
<%@page import="bws.BookUtil,com.skatestown.data.*"%>
<select name="sku">
<%
  Product[] products = BookUtil.getProductDB(application).getProducts();
  for (int i = 0; i < products.length; ++i) {
    String productSKU = products[i].getSKU();
 %>     
  <option value="<%= productSKU%>" 
          <%= sku != null && sku.equals(productSKU) ? "SELECTED" : ""%>>
          <%= productSKU%>
  </option>
<%
  }
 %>
</select>
        
burrowww.cs.indiana.edu% 
This second file is just a simple, convenient subroutine.

How do we deploy the web service?

Where is it?

(We already know that.)

How is it accessed?

How is it deployed?

To deploy we need to run this first:

burrowww.cs.indiana.edu% pwd
/nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4/webapps/bws/ch3/ex2
burrowww.cs.indiana.edu% ls -l
total 3
-rw-r--r--   1 dgerman  faculty       418 Nov 27 17:24 _buildSKUList.jsp
-rw-r--r--   1 dgerman  faculty      1207 Nov 27 17:17 index.jsp
burrowww.cs.indiana.edu% ls -ld ../../util/*
-rw-r--r--   1 dgerman  faculty       147 Nov 25 21:11 ../../util/_loadParameters.jsp
-rw-r--r--   1 dgerman  faculty      1008 Nov 27 17:37 ../../util/deployServices.jsp
-rw-r--r--   1 dgerman  faculty       673 Nov 25 21:11 ../../util/makeFrames.jsp
-rw-r--r--   1 dgerman  faculty       917 Nov 25 21:11 ../../util/navigation.jsp
-rw-r--r--   1 dgerman  faculty      1035 Nov 25 21:11 ../../util/showChapters.jsp
-rw-r--r--   1 dgerman  faculty       991 Nov 25 21:11 ../../util/showExamples.jsp
burrowww.cs.indiana.edu% cat ../../util/deployServices.jsp
<%@page import="java.io.*,bws.BookUtil,org.apache.axis.client.AdminClient"%>
<title>Services Deployment</title>
<h1>Services Deployment</h1>
<p>Attempting to deploy services...</p>
<%
  String axisUrl = "-l" + BookUtil.getServiceUrl();
  String path = BookUtil.getResourcePath(application, "/resources/deploy.xml");
  StringWriter log = new StringWriter();
%>
<table>
  <tr><td>Target URL:</td><td><%=axisUrl%></td></tr>
  <tr><td>The file to deploy:</td>
      <td><a href="../resources/deploy.xml"><%=path%></a></td></tr>
</table>
<%
  out.flush();
  AdminClient admin = new AdminClient(new PrintWriter(log));    
  String deployXMLResponse = admin.process(new String[] {axisUrl, path});
  String listXMLResponse = admin.process(new String[] {axisUrl, "list"});
%>
<p>Services are successfully deployed.</p>
<hr>
Axis status messages:     <br> <xmp><%=log.toString()   %></xmp>
Axis deployment response: <br> <xmp><%=deployXMLResponse%></xmp>
Axis deployment listing:  <br> <xmp><%=listXMLResponse  %></xmp>

burrowww.cs.indiana.edu% 
And now we realize that BookUtil.getServiceURL() holds the key.

How do we change just that one file?

(Well, we don't have to. We can bypass it.)

burrowww.cs.indiana.edu% cat index.jsp
<%@page import="bws.BookUtil,ch3.ex2.InventoryCheckClient"%>
<%
  String sku = request.getParameter("sku");
  String quantity = request.getParameter("quantity");
%>

<h1>SOAP Inventory Check</h1>
<form action="index.jsp" method="POST">
  <p>Given a SKU and a desired product quantity, this example will make 
  a SOAP call to the inventory check web service.</p>
  <table border="0" cellspacing="3">
    <tr> <td align="right">SKU:</td>
         <td> <%@include file="_buildSKUList.jsp"%> </td> </tr>
    <tr> <td align="right">Quantity:</td>
         <td> <input name="quantity" type="text"
                     value="<%= quantity != null ? quantity : "1"%>">
         </td> </tr>
    <tr> <td align="right"></td>
         <td> <input type="submit" value=" Check inventory "> </td> </tr>
  </table>
</form> <hr>
<%
  if (sku != null) {
    String serviceUrl = // BookUtil.getSiteUrl()
                        "http://burrowww.cs.indiana.edu:10600/bws/"
                        + "inventory/InventoryCheck.jws";
    InventoryCheckClient invCheck = new InventoryCheckClient(serviceUrl);

    int qty = Integer.parseInt(quantity);
    boolean result = invCheck.doCheck(sku, qty);
    if (result) { out.println("The item is available."); }
    else { out.println("The item is not available."); }
  }
%>

burrowww.cs.indiana.edu% 
Don't you feel you have to take a look at ch3.ex2.InventoryCheckClient?

Here it is

frilled.cs.indiana.edu%pwd
/nfs/grouchy/home/user2/www/classes/a348-dger/sum2002/notes/axis/examples
frilled.cs.indiana.edu%du -a . | grep -i InventoryCheckClient
1	./src/ch3/ex2/InventoryCheckClient.java
2	./src/ch3/ex3/InventoryCheckClient.java
frilled.cs.indiana.edu%cat ./src/ch3/ex2/InventoryCheckClient.java
package ch3.ex2;

import org.apache.axis.client.ServiceClient;

/*
 * Inventory check web service client
 */
public class InventoryCheckClient {
    /**
     * Service URL
     */
    String url;
    
    /**
     * Point a client at a given service URL
     */
    public InventoryCheckClient(String url) {
        this.url = url;
    }
    
    /**
     * Invoke the inventory check web service
     */
    public boolean doCheck(String sku, int quantity) throws Exception {
        ServiceClient call = new ServiceClient(url);
        Object[] params = new Object[]{ sku, new Integer(quantity), };
        Boolean result = (Boolean)call.invoke("", "doCheck", params);
        return result.booleanValue();
    }
}
frilled.cs.indiana.edu%
Notice the package, and the location.

As far as Axis is concerned we've added it to our webapps.

(See Advanced Installation in the Axis installation instructions document.)

We have two more examples to go through.

What do they do?

Example 3 (ch3/ex3) simply also sends an e-mail message.

Example 4 does a little bit more.

In this example

Let's see how we do that.

burrowww.cs.indiana.edu% pwd
/nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4/webapps/bws/ch3
burrowww.cs.indiana.edu% ls -l
total 4
drwxr-xr-x   2 dgerman  faculty       512 Nov 27 15:33 ex1
drwxr-xr-x   2 dgerman  faculty       512 Nov 27 18:40 ex2
drwxr-xr-x   2 dgerman  faculty       512 Nov 27 19:08 ex3
drwxr-xr-x   2 dgerman  faculty       512 Nov 27 19:21 ex4
burrowww.cs.indiana.edu% ls ex4
index.jsp
burrowww.cs.indiana.edu% cat ex4/index.jsp
<%@page import="java.io.*,ch3.ex4.POSubmissionClient,bws.BookUtil"%>

<HTML><HEAD><TITLE>PO Submission</TITLE></HEAD><body bgcolor="lightgrey">
  <h1>Purchase Order Submission</h1>
  <p>This example implements a web form driver for SkatesTown's purchase 
  order submission client. You can modify the purchase order on the form 
  if you wish (the default one is from Chapter 2).</p>
<%
  String xml = request.getParameter("xml");
  if (xml == null) {
    xml = BookUtil.readResource(application, "/resources/samplePO.xml");
  }
%>
  <FORM action="index.jsp" method="POST">
    <TEXTAREA NAME="xml" ROWS="12" COLS="90"><%= xml%></TEXTAREA>
    <P></P>
    <INPUT type="SUBMIT" value=" Submit PO ">
  </FORM>
<%
  // Check for form submission
  if (request.getParameter("xml") != null) {
    out.println("<HR>");
    out.println("Sending PO...<br>");

    String serviceUrl = BookUtil.getServiceUrl("POSubmission");
    POSubmissionClient poSubmission = new POSubmissionClient(serviceUrl);
        
    InputStream poXML = new StringBufferInputStream(xml);
    String invoiceXML = poSubmission.invoke(poXML);
                
    out.println("Axis response:<br>");
    out.println("<xmp>" + invoiceXML + "</xmp>");
  }
%>
</BODY></HTML>

burrowww.cs.indiana.edu% 
At some point we will need to deploy the services and get involved more.

But here's a crucial test:

So we need to add a few more .jar files to bws/WEB-INF/lib.

Or, perhaps, we should be deploying the services from somewhere else (our axis).

Let's stay within this one installation.

burrowww.cs.indiana.edu% pwd  
/nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4/webapps/bws/WEB-INF/lib
burrowww.cs.indiana.edu% ls
axis.jar  bws.jar  client-config.xml  log4j-core.jar  wsdl4j.jar  xalan.jar  xerces.jar
burrowww.cs.indiana.edu% cp ../../../axis/WE*/lib/*.jar . 
burrowww.cs.indiana.edu% ls -l
total 4780
-rwxr-xr-x   1 dgerman  faculty    376355 Nov 27 20:25 axis-ant.jar
-rw-r--r--   1 dgerman  faculty   1101593 Nov 27 20:25 axis.jar
-rw-r--r--   1 dgerman  faculty    119528 Nov 25 23:23 bws.jar
-rw-r--r--   1 dgerman  faculty       413 Nov 27 19:55 client-config.xml
-rwxr-xr-x   1 dgerman  faculty     62512 Nov 27 20:25 commons-discovery.jar
-rwxr-xr-x   1 dgerman  faculty     26388 Nov 27 20:25 commons-logging.jar
-rwxr-xr-x   1 dgerman  faculty     35635 Nov 27 20:25 jaxrpc.jar
-rwxr-xr-x   1 dgerman  faculty    378778 Nov 27 20:25 log4j-1.2.4.jar
-rw-r--r--   1 dgerman  faculty     78140 Nov 25 23:23 log4j-core.jar
-rwxr-xr-x   1 dgerman  faculty     18463 Nov 27 20:25 saaj.jar
-rw-r--r--   1 dgerman  faculty    109356 Nov 27 20:25 wsdl4j.jar
-rw-r--r--   1 dgerman  faculty    857692 Nov 25 23:23 xalan.jar
-rw-r--r--   1 dgerman  faculty   1646108 Nov 25 23:23 xerces.jar
burrowww.cs.indiana.edu% 
Now testing happyAxis.jsp should work fine.

It's here that we leave chapter 3 and 4 and move on to chapter 5 (and last).


Last updated: Nov 27, 2002 by Adrian German for A348/A548