import org.apache.ecs.*;
import org.apache.ecs.html.*;

import org.apache.jetspeed.portal.portlets.AbstractPortlet;
import org.apache.turbine.util.RunData;

import org.apache.soap.util.xml.*;
import org.apache.soap.*;

import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;

import java.io.*;
import java.net.*;
import java.util.Vector;

public class ZipCodesPortlet extends AbstractPortlet {
	
    static {
      System.getProperties().put( "proxySet", "true" );
      System.getProperties().put( "proxyHost", "192.168.64.235");
      System.getProperties().put( "proxyPort", "3128" );
    }	

    public String rtnZipInfoCSV(String zip) {
    
          
      URL url = null;
      
      try {
        url=new URL("http://services.pagedownweb.com/ZipCodes.asmx");
      } catch (MalformedURLException mue) {
        
        return mue.getMessage();
        
	}

     //This is the main SOAP object

     Call soapCall = new Call();
     
     //Use SOAP encoding
     soapCall.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
     
     //This is the remote object we're asking for the price
     soapCall.setTargetObjectURI("ZipCodes");
     
     //This is the name of the method on the above object
     soapCall.setMethodName("rtnZipInfoCSV");
     
     //We need to send the ISBN number as an input parameter to the method
     Vector soapParams = new Vector();
     
     //name, type, value, encoding style
     Parameter zipParam = new Parameter("zip",String.class,zip,null);
     
     soapParams.addElement(zipParam);
     
     soapCall.setParams(soapParams);
     
     try {
     	
     	//Invoke the remote method on the object
     	Response soapResponse = soapCall.invoke(url,"");
     	
     	//Check to see if there is an error, return 'N/A"
     	if (soapResponse.generatedFault()) {
            return"N/A";
        } else {
           
           //read result
           Parameter soapResult = soapResponse.getReturnValue();
           
           //get a string from the result
           return soapResult.getValue().toString();
          }
      } catch (SOAPException se) {
      	  
      	   return se.getMessage();
      	}
    }
    
    public ConcreteElement getContent(RunData runData) {
    	
    	StringElement zip = new StringElement();
    	
    	zip.addElement("Get Zipcode Details"+rtnZipInfoCSV("45873"));
    	
    	return zip;
    }
}          	
               
