SourceForge.net Logo

RTP - Demo

Real Time Pricing - a Demo Application: Integration using Web Services - Apache Axis

  www.theopenstack.com .

 

Simulating the back-end web service:


First we need to simulate a Web service. With Apache Axist its very simple.
  1. Write the Java code for the web service - ProductProceWS.java. The getProducts method is shown here:
    public Vector getProducts(String ipStr){
    
      Vector productVector = new  Vector ();
    
      if(ipStr.equals("w") || ipStr.equals("ws") ||ipStr.equals("W") || ipStr.equals("WS") ){
    
    	String product1 = "WS,WS Product1, Product1 From WS";
    	productVector.add(product1);
    	String product2 = "WS,WS Product2, Product2 From WS";
    	productVector.add(product2);
    	
    	}
    	return productVector ;
     
      }
    
    It basically takes a search string and returns a hard coded search result - a vector of product Strings in CSV format.
  2. Download and extract Axis zip file from the apache web site.
  3. After extracting, you will notice a 'webapp' folder created under the Axis installation directory. This folder has the axis web application. Copy this web app (its also called axis) under your tomcat webapp directory.
  4. Verify the axis installation by going to the Happy Axis page as mentioned in the Axis documentation.
  5. Now copy the java file ProductProceWS.java as ProductProceWS.jws under this axis directory copied on Tomcat. JWS stands for Java Web Service.
  6. Thats all your web service is ready. Verify by going to "localhost:8080/axis/ProductProceWS.jws?wsdl". The WSDL should look like this.

Invoking this web service:

Now that you have the web service defined, to invoke the service is also very simple. (The following code already exists as part of the RTPDEMO zip file, this is just an explaination of the same)
Use WSDL2Java tool on the WSDL file to generate the following java files:
The following lines in the WSAdapter use these auto generated classes to invoke the service:
ProductPriceWSServiceLocator  sl = new ProductPriceWSServiceLocator();

ProductPriceWS  ws = sl.getProductPriceWS();
Vector  pv = ws.getProducts(nameSearchString);