Call google web service and deal with the return with SOAPMessage : SOAP « Web Services SOA « Java Tutorial






import java.io.FileInputStream;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;

public class GoogleSearch {
  public static void main(String args[]) throws Exception {
    URL url = new URL("http://api.google.com/GoogleSearch.wsdl");
    QName serviceName = new QName("urn:GoogleSearch", "GoogleSearchService");
    QName portName = new QName("urn:GoogleSearch", "GoogleSearchPort");
    Service service = Service.create(url, serviceName);
    Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class,
        Service.Mode.MESSAGE);

    SOAPMessage request = MessageFactory.newInstance().createMessage(null,
        new FileInputStream("yourGoogleKey.xml"));

    SOAPMessage response = dispatch.invoke(request);
    response.writeTo(System.out);
  }
}








26.2.SOAP
26.2.1.Create SOAP message
26.2.2.Generate DOM with SOAP message
26.2.3.Output SOAP message with XML transformer
26.2.4.Generate DSA key pair
26.2.5.Use DSA key pair to generate XML Signature
26.2.6.Sign SOAP message
26.2.7.Call google web service and deal with the return with SOAPMessage
26.2.8.Sending a SOAP Message
26.2.9.Processing a SOAP Message