package tests.omnitide;

import java.util.*;
import java.net.*;
import org.apache.soap.*;
import org.apache.soap.encoding.*;
import org.apache.soap.encoding.soapenc.*;
import org.apache.soap.rpc.*;
import org.apache.soap.util.xml.*;

import edu.mit.wi.omnigene.omnitide.encoding.*;

public class SimpleURLServiceClient
{

    public static void main(String[] args) throws Exception 
    {
	System.out.println("Starting test...");

       // Address of SOAP router 
       URL url = new URL("http://bismuth:9090/soap/servlet/rpcrouter");

       // Map the types
       SOAPMappingRegistry smr = new SOAPMappingRegistry();

       URLSerializer us = new URLSerializer();
       URLDeserializer ud = new URLDeserializer();
       smr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName("urn:SimpleURLService", "url"),
		    URL.class, us, ud);

       // Build the call
       Call call = new Call();
       call.setSOAPMappingRegistry(smr);
       call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
       call.setTargetObjectURI("urn:SimpleURLService");
       call.setMethodName("serviceMethod");

       Vector params = new Vector();
       params.addElement(new Parameter("url", URL.class, url, null));
       call.setParams(params);

       System.out.println("Calling service method...");

       // Invoke the call to the SOAP server
       Response resp = null;
       try 
       {
         resp = call.invoke(url,"");
       }
       catch (SOAPException se)
       {
	   System.out.println("\nCaught SOAPException (" + se.getFaultCode() + "): " + 
			      se.getMessage());
	   System.out.println("Ending abnormally...\n");
	   return;
       }

       // Check the response
       if (!resp.generatedFault())
       {
	   Parameter ret = resp.getReturnValue();
	   String value = (String)ret.getValue();
	   System.out.println("Return value: " + value);
       }
       else
       {
	   Fault fault = resp.getFault();

	   System.out.println("\nGenerated fault: ");
	   System.out.println("  Fault Code = " + fault.getFaultCode());
	   System.out.println("  Fault String = " + fault.getFaultString());
	   System.out.println("Ending abnormally...\n");
       }

    }

}




















