package caTraffic.bean;

import oracle.soap.transport.http.OracleSOAPHTTPConnection;
import java.net.URL;
import org.apache.soap.Constants;
import org.apache.soap.Fault;
import org.apache.soap.SOAPException;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Parameter;
import org.apache.soap.rpc.Response;
import java.util.Vector;
import java.util.Properties;
/**
 * Generated by the Oracle9i JDeveloper Web Services Stub/Skeleton Generator.
 * Provides information on California Highway Conditions.
 */

public class CATrafficServiceProxy implements java.io.Serializable 
{
  public String endpoint = "http://services.xmethods.net:80/soap/servlet/rpcrouter";
  private OracleSOAPHTTPConnection m_httpConnection = null;

  public CATrafficServiceProxy()
  {
    m_httpConnection = new OracleSOAPHTTPConnection();
  }
	
  public void setHttpProxy(String host,String port)
  {
    // set the http proxy properties .
	m_httpConnection.setProxyHost(host);
	int inPort = 0;
	if(port != null)
	{
		inPort = Integer.getInteger(port).intValue();
	}
	m_httpConnection.setProxyPort(inPort);
  }

  public String getTraffic(String hwynums) throws Exception
  {
    String returnVal = null;
	String host = null;
	String port = null;
	host = System.getProperty("http.proxyHost");
	port = System.getProperty("http.proxyPort");
    URL endpointURL = new URL(endpoint);
    Call call = new Call();
	if(host != null)
		m_httpConnection.setProxyHost(host);
    if(port != null)
	{
		Integer inPort = new Integer(port);
		m_httpConnection.setProxyPort(inPort.intValue());
	}
    call.setSOAPTransport(m_httpConnection);
    call.setTargetObjectURI("urn:xmethods-CATraffic");
    call.setMethodName("getTraffic");
    call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
    Vector params = new Vector();
    params.addElement(new Parameter("hwynums", String.class, hwynums, null));
    call.setParams(params);

    Response response = call.invoke(endpointURL, "");

    if (!response.generatedFault())
    {
      Parameter result = response.getReturnValue();
      returnVal = (String)result.getValue();
    }
      else
      {
        Fault fault = response.getFault();
        throw new SOAPException(fault.getFaultCode(), fault.getFaultString());
      }

    return returnVal;
  }

  public String formatText(String str)
  {
    String returnVal = null;
    StringBuffer strBuf = new StringBuffer(str);
    int idx = 0;
    for(;;)
    {
      idx = strBuf.toString().indexOf("\n",idx);
      if(idx == -1)
        break;
      strBuf = strBuf.insert(idx,"<BR>");
      idx += 5;
    } 
    returnVal = strBuf.toString();
    return returnVal;
  } 
  
  public void setMaintainSession(boolean maintainSession)
  {
    m_httpConnection.setMaintainSession(maintainSession);
  }

  public boolean getMaintainSession()
  {
    return m_httpConnection.getMaintainSession();
  }

  public void setTransportProperties(Properties props)
  {
    m_httpConnection.setProperties(props);
  }

  public Properties getTransportProperties()
  {
    return m_httpConnection.getProperties();
  }

}