FileDocCategorySizeDatePackage
WeatherClient.javaAPI DocExample1789Wed Feb 27 11:46:14 GMT 2002javasoap.book.ch8

WeatherClient

public class WeatherClient 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("recordTemperature");
      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);

      sub = doc.createElement("temperature");
      txt = doc.createTextNode("");
      txt.setData("52.3");
      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);
      }