import java.io.*;
import java.util.*;
import java.net.*;
import org.w3c.dom.*;

import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;

import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.encoding.*;
import org.apache.soap.encoding.soapenc.*;
import org.apache.soap.rpc.*;
import org.apache.xerces.dom.DocumentImpl;

import java.security.*;
import javax.security.cert.X509Certificate;
import javax.net.ssl.*;
import com.sun.net.ssl.*;


public class SoapCall
{
   static String Mtds      = "ProcessRequest";
   static String urlstr    = "https://soapserver/rpcrouter";
   
   
   static String URI       = "urn:processrequest";
   static URL    url       = null;
   
   /*---------------------------------------------------------------------*/
   /*   SoapCall ...                                                      */
   /*---------------------------------------------------------------------*/
   private static void SoapCall( Element el ) throws Exception
   {
      url       = new URL( urlstr );
      Call call = new Call();
      call.setTargetObjectURI( URI );
      call.setMethodName( Mtds );
      call.setEncodingStyleURI( Constants.NS_URI_LITERAL_XML );
     	Vector params = new Vector();
    	params.addElement( new Parameter( "request", Element.class, el, Constants.NS_URI_LITERAL_XML ) );
    	call.setParams( params );
    	Response resp = call.invoke( url, "" );
    	if( !resp.generatedFault() )
    	{
      	Parameter ret   = resp.getReturnValue();
				Element retEl   = (Element)ret.getValue();
      }
			else
      { 
				System.out.println( "Call Failed" );
      }
   		url = null;
			call = null;
   
   }


   /*---------------------------------------------------------------------*/
   /*   main ...                                                          */
   /*---------------------------------------------------------------------*/
   public static void main(String[] args) throws Exception 
   {
			System.setProperty( "java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol" );
    	java.security.Security.addProvider( new com.sun.net.ssl.internal.ssl.Provider() ); 
			(new Thread()
			{
				public void run() 
				{
	    		SecureRandom sr = new SecureRandom();
					sr.nextInt();
					try
					{
						SSLContext sc = SSLContext.getInstance("TLS");
						sc.init(null, null, sr);
					}
					catch(NoSuchAlgorithmException e){}
					catch(KeyManagementException e){}
				}
			}).start();


		
			createElementtoSend();
	
   }
   
   /*--------------------------------------------------------------------*/
   /*                                                                    */
   /*  createElementtoSend                                               */
   /*--------------------------------------------------------------------*/
   public static void createElementtoSend() throws Exception
   {
      Document doc     = new DocumentImpl();
      Element  myElement = doc.createElement( "");
      //I am using the same example from the mailing list email.
      myElement.setAttribute( "data", "Steps to send email\n1)  Type the text that you want to send\n2)  Send the email" );
      doc.appendChild( myElement);
      SoapCall( myElement );
   }
   
   
}