/*
 * Created on 25 nov. 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package localhost.Axis1_2.HelloWorld_jws;

import java.net.URL;

import javax.xml.soap.MessageFactory;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPFactory;
import javax.xml.soap.SOAPMessage;

/**
 * @author Xavier
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class TestSAAJ {

	public static void main(String[] args) {
		try {
		MessageFactory factory = MessageFactory.newInstance();
		SOAPMessage message = factory.createMessage(); 
		SOAPBody body = message.getSOAPBody();
		SOAPFactory soapFactory = SOAPFactory.newInstance();
		Name bodyName = soapFactory.createName("sayWhat","ns1", "http://localhost:8080/Axis1_2/HelloWorld.jws");
		SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
		SOAPConnectionFactory connFactory = SOAPConnectionFactory.newInstance();
		SOAPConnection con = connFactory.createConnection(); 

		
		URL endpoint = new URL("http://localhost:8080/Axis1_2/HelloWorld.jws");
		SOAPMessage response = con.call(message, endpoint); 
		
		SOAPElement sayWhatReturn = (SOAPElement) ((SOAPElement)response.getSOAPBody().getChildElements().next()).getChildElements().next();
		System.out.println("response = "+sayWhatReturn.getFirstChild().getNodeValue());
		
		//System.out.println("response"+response.toString());
		}
		catch (Exception ex){
			ex.printStackTrace();
		}
	}
}
