package complex;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
import javax.wsdl.Definition;
import javax.wsdl.Service;

import org.apache.wsif.util.WSIFUtils;
import org.apache.wsif.WSIFMessage;
import org.apache.wsif.WSIFException;
import org.apache.wsif.WSIFOperation;
import org.apache.wsif.WSIFPort;
import org.apache.wsif.WSIFService;
import org.apache.wsif.WSIFServiceFactory;
import org.apache.wsif.util.WSIFPluggableProviders;
import org.apache.wsif.providers.soap.apacheaxis.WSIFDynamicProvider_ApacheAxis;

import com.indus.banner.components.cdyne.LatLongReturn;
import com.indus.banner.components.cdyne.ZipState;
import java.math.*;

public class Run2 {

    private static void addZip(WSIFPort port) {
        try {
            // create the operation
            // note that we have two operations with the same name, 
            // so we need to specify the name of the input and output 
            // messages as well
            WSIFOperation operation =
                port.createOperation("postZipLookupResult");
                    
            // create the input message associated with this operation
            WSIFMessage input = operation.createInputMessage();

            LatLongReturn inputObject = new LatLongReturn();
        inputObject.setAddressError(false);
        inputObject.setServiceError(false);
        inputObject.setCity("Columbia");
        inputObject.setStateAbbrev("SC");
        inputObject.setZipCode("29223");
        inputObject.setCounty("Richland");
        inputObject.setFromLongitude(new BigDecimal("-74.011926"));
        inputObject.setFromLatitude(new BigDecimal("40.703235"));
        inputObject.setToLongitude(new BigDecimal("-74.011926"));
        inputObject.setToLatitude(new BigDecimal("40.710265"));
        inputObject.setAvgLongitude(new BigDecimal("-74.011926"));
        inputObject.setAvgLatitude(new BigDecimal("40.70025"));
        inputObject.setCMSA("CMSA");
        inputObject.setPMSA("PMSA");

            input.setObjectPart("LatLongReturn", inputObject);

            // do the invocation
            WSIFMessage output = operation.createOutputMessage();
            WSIFMessage fault = operation.createFaultMessage();
 
            // do the invocation
            if (operation.executeRequestResponseOperation(input, output, fault)) 
            {
              System.out.println("Success");
            }
            else {
              System.out.println("Failure");
            }

        } catch (WSIFException we) {
            System.out.println("Got exception from WSIF, details:");
            we.printStackTrace();
        }
    }


    public static void main(String[] args) throws Exception {

        String wsdlLocation = "http://149.24.164.133:8888/xconnectors-web/ZipLookupManager.wsdl";
        String portName = null;
        String operationName = null;
        //String portName = null;
        String portTypeName = null;
        String portTypeNS = null;
        String serviceNS = null;
        String serviceName = null;
        String inputName = null;
        String outputName = null;

        WSIFPluggableProviders.overrideDefaultProvider(
                "http://schemas.xmlsoap.org/wsdl/soap/",
                new WSIFDynamicProvider_ApacheAxis()); 
                
        // create a service factory
        WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
        WSIFService service =
            factory.getService(
                wsdlLocation,
                null,
                null,
                "http://cdyne.components.banner.indus.com",
                null);        
        
        // map types
        service.mapType(
            new QName("http://cdyne.components.banner.indus.com", "LatLongReturn"),
            Class.forName("com.indus.banner.components.cdyne.LatLongReturn"));
        service.mapType(
            new QName("http://cdyne.components.banner.indus.com", "ZipState"),
            Class.forName("com.indus.banner.components.cdyne.ZipState"));
            
        // get the port
        WSIFPort port = service.getPort();

        // add the first address
        addZip(port);
    }
}
