FileDocCategorySizeDatePackage
TemperatureClient.javaAPI DocExample1639Wed Feb 27 11:47:04 GMT 2002javasoap.book.ch8

TemperatureClient

public class TemperatureClient extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)


      DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder();
      Document doc = xdb.newDocument();
      
      Element elem = 
                doc.createElementNS(Constants.NS_URI_SOAP_ENV,
                "SOAP-ENV:Envelope");
      doc.appendChild(elem);
      
      Element sub = 
                doc.createElementNS(Constants.NS_URI_SOAP_ENV,
                "SOAP-ENV:Body");

      elem.appendChild(sub);
      elem = sub;

      sub = doc.createElement("getTemperature");
      sub.setAttribute("xmlns", "urn:WeatherDiary");
      elem.appendChild(sub);

      sub = doc.createElement("zipcode");
      Text txt = doc.createTextNode("");
      txt.setData("12345");
      sub.appendChild(txt);
      elem.appendChild(sub);

      Envelope msgEnv = Envelope.unmarshall 
                           (doc.getDocumentElement ());

      URL url = new URL(
          "http://georgetown:8080/soap/servlet/messagerouter");

      Message msg = new Message ();
      msg.send (url, "", msgEnv);
      
      SOAPTransport st = msg.getSOAPTransport ();
      BufferedReader br = st.receive ();
      String line;
      while ((line = br.readLine ()) != null) {
         System.out.println (line);
      }