O'Reilly logo

Java and SOAP by Robert Englander

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.7. Passing Parameters

So far, the examples in this chapter have used methods that don't contain any parameters. We'll now spend a little time looking at how parameters are passed. Let's create a service called urn:StockPriceService, implemented by the javasoap.book.ch4.StockPrice class. The getPrice( ) method takes parameters for the stock symbol as well as the currency. The method always returns the float value of 75.33 — not a very interesting stock, but at least it won't go down. Seriously though, we're just interested in how parameters are passed. The details of accessing a database or data feed to find a stock price are, for the moment, left to you.

package javasoap.book.ch4;
public class StockPrice {
   public float getPrice(String stock, String currency) {
      float result;
      // determine the price for stock and return it
      // in the specified currency
      result = (float)75.33;
      return result;
   }
}

We'll gloss over the deployment details, both for Apache SOAP and GLUE, since we've spent much of this chapter on that subject. Here's the Apache SOAP deployment descriptor for the StockPriceService implemented by the StockPrice class. The service uses application-level scope, and contains a single method called getPrice that retrieves the current trading price of a stock using a specified currency.

<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment" id="urn:StockPriceService"> <isd:provider type="java" scope="Application" methods="getPrice"> <isd:java class="javasoap.book.ch4.StockPrice" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required