" -----------------------------------------------------------------------------------------------------------------------------------------------
This file contains code examples described in the User's guide.

The files in this directory are as follows:

	SstWSSampleContainer.xml -  A container deployment descriptor used to initialize a Web services container to host the insurance example.

	VASTInsuranceExample.map - A VisualAge mapping specification file containing rules for mapping XML into the business objects of the insurance
	policy application.
	
	SstWSInsurancePolicyClientInterface.xml - A client service deployment descriptor that describes the resources required for invoking the 
	insurance example.

	SstWSInsurancePolicyInterface.wsdl - The implementation WSDL that describes details for invoking the insurance example

	SstWSInsurancePolicyInterface.xml -  A deployment descriptor that describes the resources for hosting the insurance example.

	VASTInsuranceExampleDatabase.xml  -  An XML file used to supply test data for the insurance example.

	SstWSInsurancePolicyInterface-interface.wsdl  - The interface WSDL for the insurance example which describes the abstract interfaces of
	all operations supported by the SstWSInsurancePolicyInterface service.

------------------------------------------------------------------------------------------------------------------------------------------------------------ "

	" Generate the Web services interface files required for invocation of operations in the SstWSInsurancePolicyInterface service "
    SstWSXmlGeneration  forClass: SstWSInsurancePolicyInterface


	" Start an HTTP file server to serve required service deployment files "
	 |server|
     server := SstHttpServerExample runAt: 'http://:63001' in: (SstWebServicesInsuranceExample wsResourceQualifier  ).
        


	" Start a Web services container "
	 [ | aContainer |
        SstWSContainer clearAll.
        aContainer := SstWSContainer createContainerNamed:  SciSocketManager default getHostName 
              using: (SstWSContainerConfiguration defaultConfiguration).
              aContainer startUp.
        aContainer inspect ] fork

	
	" Deploy the hosted service(s) described by the SstWSInsurancePolicyInterface.xml file "
	 [ | aContainer aServiceCollection|
    aContainer := SstWSContainer containerNamed: SciSocketManager default getHostName.
    aServiceCollection := aContainer deploy: 'http://vasthost:63001/SstWSInsurancePolicyInterface.xml'.
	aServiceCollection inspect ] fork

	
	" Local invocation of the 'about' operation in the SstWSInsurancePolicyInterface service "
	  [ | aContainer aService|
      aContainer := SstWSContainer containerNamed:  SciSocketManager default getHostName.
      aService := aContainer serviceNamed: 'SstWSInsurancePolicyInterface' 
       inNamespace: 'http://www.SstWSInsurancePolicyInterface.com/SstWSInsurancePolicyInterface'.
    aService about inspect ] fork 


	" Remote invocation simulation.  Deploy client to separate container and invoke the service.   "
	 [ | aContainer aServiceCollection aService|
       aContainer := SstWSContainer containerNamed:  'VastSampleClientContainer' ifNone: [ SstWSContainer createContainerNamed: 'VastSampleClientContainer' ].
       aServiceCollection := aContainer deploy:   'http://vasthost:63001/SstWSInsurancePolicyClientInterface.xml'.
       aService := aServiceCollection first.
       aService about inspect ] fork


"  ---------------------------   Advanced functions ----------------------------------------"


" Deploy using the sample container configuration file.  Using this technique, custom overrides specified in the provided
	container deployment descriptor are applied to the newly deployed container.  "
SstWSContainer clearAll.
[ SstWSContainer deploy: 'http://vasthost:63001/SstWSSampleContainer.xml'.
 System logError: 'Deployment completed' ] fork.



" Invoke the 'getAllPolicies' operation which returns a collection of SstWSInsurancePolicy objects "
[|aContainer serviceCollection args|
	 aContainer := SstWSContainer containerNamed:  'VastSampleClientContainer' ifNone: [ SstWSContainer createContainerNamed: 'VastSampleClientContainer' ].
  		serviceCollection := aContainer deploy: 'http://vasthost:63001/SstWSInsurancePolicyClientInterface.xml'.
		serviceCollection first getAllPolicies inspect ] fork.


" Invoke the 'getAllPoliciesUsingSoapArray' executes the 'getAllPolicies' operation, but results are returned as a SOAP:Array "
[|aContainer serviceCollection args|
	 aContainer := SstWSContainer containerNamed:  'VastSampleClientContainer' ifNone: [ SstWSContainer createContainerNamed: 'VastSampleClientContainer' ].
  		serviceCollection := aContainer deploy: 'http://vasthost:63001/SstWSInsurancePolicyClientInterface.xml'.
		serviceCollection first getAllPoliciesUsingSoapArrays inspect ] fork.


" Code sample below invokes multiple operations in same script.  Results are displayed via inspector.
   Code assumes that the 'VastSampleClientContainer' was created by previous steps.  "
[|aContainer service args newPerson policy updatedPolicy newRate|
	 aContainer := SstWSContainer containerNamed:  'VastSampleClientContainer'.
  		service := aContainer serviceNamed: 'SstWSInsurancePolicyInterface' inNamespace: 'http://www.SstWSInsurancePolicyInterface.com/SstWSInsurancePolicyInterface'.
		( policy := service getInfoForPolicy: '85496328' ) inspect.
		newPerson:= policy owner deepCopy.
		newPerson name: 'New Person'; tin: '694-17-0804'.
		updatedPolicy := policy deepCopy.
		updatedPolicy dependents add: newPerson.
		
		(newRate:= service ratePolicy: updatedPolicy ) inspect.
		updatedPolicy premium: newRate.
		(service updatePolicy: updatedPolicy )  inspect.
 	] fork.


	" This operation passes the second method argument as a SOAP:Header.  The WSDL for the operation contains header extension descriptions
	   to allow the VAST framework to encode the header automatically  "
	[|aContainer service args newPerson policy updatedPolicy newRate|
	 aContainer := SstWSContainer containerNamed:  'VastSampleClientContainer' ifNone: [ SstWSContainer createContainerNamed: 'VastSampleClientContainer' ].
  	"	service := aContainer serviceNamed: 'SstWSInsurancePolicyInterface' inNamespace: 'http://www.SstWSInsurancePolicyInterface.com/SstWSInsurancePolicyInterface'. "
	service := (aContainer deploy: 'http://vasthost:63001/SstWSInsurancePolicyClientInterface.xml') first.
	(policy:= service getInfoForPolicy: '85496328'  withVerification: 'Acme Insurance' ) inspect.
 	] fork.


	" This code passes an invalid business partner argument (2nd argument) and causes the server application logic to issue an exception.  
	  The exception is passed back to the client as a SOAP fault "
	[|aContainer service args newPerson policy updatedPolicy newRate|
	 aContainer := SstWSContainer containerNamed:  'VastSampleClientContainer' ifNone: [ SstWSContainer createContainerNamed: 'VastSampleClientContainer' ].
  	"	service := aContainer serviceNamed: 'SstWSInsurancePolicyInterface' inNamespace: 'http://www.SstWSInsurancePolicyInterface.com/SstWSInsurancePolicyInterface'. "
	service := (aContainer deploy: 'http://vasthost:63001/SstWSInsurancePolicyClientInterface.xml') first.
	(policy:= service getInfoForPolicy: '85496328'  withVerification: 'Big Boy Insurance' ) inspect.
 	] fork.


	" Modify the client input message constructor so that it appends global header information to all outgoing SOAP messages.
	Subsequent executions cause the server handler named SstWSSampleContainerHeaderInputHandler to be invoked,
	and write a message to the Transcript. "
	| chain |
	chain := ( SstWSContainer containerNamed:  'VastSampleClientContainer' ) handlerFactory
		handlerNamed: 'wsClientInputMessageConstructor'.
	chain addHandler: (SstWSSampleContainerHeaderOutputHandler new name: 'containerHeaderHandler' )
