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;


public class CurrencyConverterStub
{
  public String endpoint = "http://localhost:8888/Workspace2-Project2-context-root/CurrencyConverter";
  private OracleSOAPHTTPConnection m_httpConnection = null;

  public CurrencyConverterStub()
  {
    m_httpConnection = new OracleSOAPHTTPConnection();
  }

  public Float convert(String fromCurrency, String toCurrency, Float amount) throws Exception
  {
    Float returnVal = null;

    URL endpointURL = new URL(endpoint);
    Call call = new Call();
    call.setSOAPTransport(m_httpConnection);
    call.setTargetObjectURI("CurrencyConverter");
    call.setMethodName("convert");
    call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
    Vector params = new Vector();
    params.addElement(new Parameter("fromCurrency", String.class, fromCurrency, null));
    params.addElement(new Parameter("toCurrency", String.class, toCurrency, null));
    params.addElement(new Parameter("amount", Float.class, amount, null));
    call.setParams(params);

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

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

    return returnVal;
  }

  public Float exchangeRate(String from, String to) throws Exception
  {
    Float returnVal = null;

    URL endpointURL = new URL(endpoint);
    Call call = new Call();
    call.setSOAPTransport(m_httpConnection);
    call.setTargetObjectURI("CurrencyConverter");
    call.setMethodName("exchangeRate");
    call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
    Vector params = new Vector();
    params.addElement(new Parameter("from", String.class, from, null));
    params.addElement(new Parameter("to", String.class, to, null));
    call.setParams(params);

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

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

    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();
  }
}
E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy