Simple Web Services


By far the easiest and quickest way to deploy a Java Web service is through Axis' Java Web Service (JWS) facility. JWS lets you place a Java file in your Web application directory structure, and Axis will automatically find it, compile it, and deploy the methods automatically. Using the example from Chapter 3, we have the JWS (or Java) file shown in Listing 4.2.

Listing 4.2 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              truefalse 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);     } } 

All you need to do is place this file in the Axis webapps directory structure with a .jws extension instead of .java . So, to access this example on the CD, because it is in the ch3/ex2 directory, the URL for this Web service would be http://localhost:8080/bws/ch3/ex2/InventoryCheck.jws. It's as easy as that.

One important thing to remember is that all public methods will be available as Web services. So, use JWS files with care.



Building Web Services with Java. Making Sense of XML, SOAP, WSDL and UDDI
Building Web Services with Java: Making Sense of XML, SOAP, WSDL and UDDI
ISBN: B000H2MZZY
EAN: N/A
Year: 2001
Pages: 130

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net