import java.net.*;
import java.security.*;
import java.util.*;
import javax.net.ssl.*;
import javax.security.cert.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
import org.apache.soap.transport.http.*;


public final class HelloClient {


    public static void main ( String [] args ) {

        String name = "ICREDIBLE HULK";

        try {
            String urlString = "http://MY_IP/soap/servlet/rpcrouter";
                System.out.println ( "\nURL is:\n" );
                System.out.println ( urlString );
            }

            URL url = new URL ( urlString );

            Call call = new Call ();
            call.setTargetObjectURI ( "urn" );
            call.setMethodName ( "sayHelloTo" );
            call.setEncodingStyleURI ( Constants.NS_URI_SOAP_ENC );

            call.setTimeout ( 60000 ); // Max time to wait for an answer

            Vector params = new Vector ();
            params.addElement ( new Parameter ( "name", String.class,
                                name, null ) );
            call.setParams ( params );

            System.out.println ( call );

            Response resp = call.invoke ( url, "" );

            if ( ! resp.generatedFault () ) {

                System.out.println ( resp );

	        Object retValue = resp.getReturnValue ().getValue ();

                System.out.println ( retValue );
            }
            else {
                System.err.println ( "\nERROR\nERROR\n" + resp +
                                     "\nERROR\nERROR\n" );
            }
        }
        catch ( SOAPException soapExc ) {

            System.out.println ( "\nCaught SOAPException:\n" );
            System.out.println ( "Handle it...." );
            soapExc.printStackTrace ();
            System.exit ( 0 );
	}
        catch ( Exception exc ) {

            System.out.println ( "\nAaargh something was going wrong!\n" );
            exc.printStackTrace ();
            System.exit ( 0 );
        }
    }
}
