package tutorial.sample9.client;

import java.io.IOException;

import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import javax.xml.rpc.soap.SOAPFaultException;

public class Main{

  public static void main( String[] args ){

    if( args.length == 1 ){
      new Main( args[0] );
    }else{
      throw new IllegalArgumentException( "URL of the service not specified" );
    }
  }

  public Main( String wsdlUrl ){
    try{
      HelloWorldService service = new HelloWorldService_Impl( wsdlUrl );
      HelloWorldServicePort port = service.getHelloWorldServicePort();

      try{
        port.helloCustomFault();
      }catch( HelloWorldException e ){
        System.out.println( e );
        System.out.println( e.getMessage() );
        e.printStackTrace();
      }

      try{
        port.helloSOAPFault();
      }catch( RemoteException e ){
        SOAPFaultException sfe = (SOAPFaultException)e.getCause();
        System.out.println( "Fault Code:" + sfe.getFaultCode() );
        System.out.println( "Fault String:" + sfe.getFaultString() );
        System.out.println( "Fault Actor:" + sfe.getFaultActor() );
        System.out.println( "Fault Detail:" + sfe.getDetail() );
      }
    }catch( IOException e ){
      System.out.println( "Failed to create web service client:" + e );
    }catch( ServiceException e ){
      System.out.println( "Failed to create web service client:" + e );
    }
  }
}

