package geoip;

import java.io.IOException;

import org.codehaus.xfire.client.ClientHandler;
import org.codehaus.xfire.client.http.SoapHttpClient;
import org.codehaus.xfire.xmlbeans.client.XMLBeansClientHandler;
import org.codehaus.xfire.fault.XFireFault;

import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;

import net.webservicex.GetGeoIPResponseDocument;
import net.webservicex.GetGeoIPDocument;
import net.webservicex.GetGeoIPContextDocument;
import net.webservicex.GetGeoIPContextResponseDocument;

/**
 * Auto-generated client stub for GeoIPService.
 *
 * TODO: Use correct SOAP version from WSDL
 */
 public class GeoIPSoapClient
{
    private String url = "http://www.webservicex.net/geoipservice.asmx";
	private static final String ENCODING = "UTF-8";
	
	private XmlOptions options;
	
    public GeoIPSoapClient()
    {
        options = new XmlOptions();
        options.setCharacterEncoding(ENCODING);
    }	

    public GeoIPSoapClient(XmlOptions options)
    {
        this.options = options;
    }
    
    public String getServiceUrl()
    {
        return url;
    }

    public void setServiceUrl(String url)
    {
        this.url = url;
    }

    public GetGeoIPResponseDocument GetGeoIP(  GetGeoIPDocument parameters )
        throws IOException, XFireFault
    {
        XMLBeansClientHandler handler = new XMLBeansClientHandler(options);
        XMLBeansClientHandler headerHandler = getHeaderHandler();
        
        XmlObject[] request = new XmlObject[] 
        {
 			parameters  
		};

        handler.setRequest(request);
        
        XmlObject[] headers = new XmlObject[] 
        {

		};
				
        headerHandler.setRequest(headers);
        SoapHttpClient client = new SoapHttpClient(handler, headerHandler, getServiceUrl());
        client.setAction("http://www.webservicex.net/GetGeoIP");
        client.setEncoding(ENCODING);
    
        client.invoke();
        return (GetGeoIPResponseDocument) handler.getResponse()[0];
    }

    public GetGeoIPContextResponseDocument GetGeoIPContext(  GetGeoIPContextDocument parameters )
        throws IOException, XFireFault
    {
        XMLBeansClientHandler handler = new XMLBeansClientHandler(options);
        XMLBeansClientHandler headerHandler = getHeaderHandler();
        
        XmlObject[] request = new XmlObject[] 
        {
 			parameters  
		};

        handler.setRequest(request);
        
        XmlObject[] headers = new XmlObject[] 
        {

		};
				
        headerHandler.setRequest(headers);
        SoapHttpClient client = new SoapHttpClient(handler, headerHandler, getServiceUrl());
        client.setAction("http://www.webservicex.net/GetGeoIPContext");
        client.setEncoding(ENCODING);
    
        client.invoke();
        return (GetGeoIPContextResponseDocument) handler.getResponse()[0];
    }


    /**
     * Gets the HeaderHandler.  Override this or fill this in
     * to provide your own HeaderHandler.
     * @return null by default.
     */
    public XMLBeansClientHandler getHeaderHandler()
    {
    	return new XMLBeansClientHandler(options);
    }
}
