FileDocCategorySizeDatePackage
DirectedQuoteProxyService.javaAPI DocExample3006Tue Jan 15 12:19:46 GMT 2002javasoap.book.ch10.services

DirectedQuoteProxyService

public class DirectedQuoteProxyService extends Object

Fields Summary
static final String
TARGETADDRESS
static final String
DEFAULTTARGET
Constructors Summary
public DirectedQuoteProxyService()


     
   
Methods Summary
public javasoap.book.ch9.services.ProxyQuotegetQuote(Header hdr, java.lang.String symbol)

      
      String target = getTargetAddress(hdr);

      URL url = new URL(target);

      SOAPMappingRegistry smr = new SOAPMappingRegistry();

      BeanSerializer beanSer = new BeanSerializer();

      smr.mapTypes(Constants.NS_URI_SOAP_ENC,
        new QName("http://www.themindelectric.com/package/javasoap.book.ch9.services/", 
                 "Quote"),
                 RemoteQuote.class, beanSer, beanSer);
    
      Call call = new Call();
      call.setSOAPMappingRegistry(smr);
      call.setTargetObjectURI("XYZ");
      call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);

      String stock = symbol;

      Vector params = new Vector();
      params.addElement(new Parameter("stock", String.class, stock, null));
      call.setParams(params);
      
      call.setMethodName("getQuote");
      Response resp = call.invoke(url, "");
      ProxyQuote quote = new ProxyQuote();
      if (resp.generatedFault()) {
         throw new Exception("Service Call Failed");
      }
      else { 
         Parameter ret = resp.getReturnValue();
         RemoteQuote value = (RemoteQuote)ret.getValue();
         quote.setStockSymbol(value.get_symbol());
         quote.setLast(value.get_lastPrice());
         quote.setDiff(value.get_change());
         quote.setTime(value.get_timeStamp());
         quote.setVol(value.get_volume());
      }

      return quote;
   
java.lang.StringgetTargetAddress(Header header)


      String target = DEFAULTTARGET;

      Vector entries = header.getHeaderEntries();
      for (int i = 0; i < entries.size(); i++) {
         Element el = (Element)entries.elementAt(i);
         String name = el.getLocalName();
         String val = el.getAttributeNS(Constants.NS_URI_SOAP_ENV,
            Constants.ATTR_MUST_UNDERSTAND);

         if (name.equals(TARGETADDRESS)) {
            target = el.getFirstChild().getNodeValue();
         }
         else if (val != null && val.equals("1")) {
            if (!name.equals(TARGETADDRESS))
            throw new SOAPException("MustUnderstand",
              "Service Doesn't Understand Header Element: " + name);
         }
      }

      return target;