Difference between revisions of "Adding State"

From GCube System
Jump to: navigation, search
(Delving into the implementation)
(Adding State)
Line 1: Line 1:
 
= Adding State =
 
= Adding State =
 
In the first part of this tutorial we have created a stateless service for simplicity. However, the most common patterns used when developing gCube services are the ones that allow to create stateful service.
 
In the first part of this tutorial we have created a stateless service for simplicity. However, the most common patterns used when developing gCube services are the ones that allow to create stateful service.
In this part of the tutorial we see how to add a state to the SampleService.  
+
In this part of the tutorial we will learn how to add a state to the SampleService.  
 +
 
 
== Towards a multi port-type service ==
 
== Towards a multi port-type service ==
 
To add a state we need firstly to add two new port-types to the SampleService:
 
To add a state we need firstly to add two new port-types to the SampleService:
Line 13: Line 14:
  
 
plus other specific steps that allow to manage stateful services.
 
plus other specific steps that allow to manage stateful services.
 
  
 
== Profiling for the infrastructure ==
 
== Profiling for the infrastructure ==
Line 175: Line 175:
 
== Delving into the implementation ==
 
== Delving into the implementation ==
 
The implementation of the stateful part of the SampleService is a bit more complex than the stateless one. The new classes  will be placed in the new ''org.acme.sample.stateful''.  
 
The implementation of the stateful part of the SampleService is a bit more complex than the stateless one. The new classes  will be placed in the new ''org.acme.sample.stateful''.  
Then, the implementation has
+
 
  
 
Stateful Context
 
Stateful Context
 +
----
  
 
Resource
 
Resource
 +
----
  
 
ResourceHome
 
ResourceHome
 +
----
  
 
Service instance port-type
 
Service instance port-type
 +
----
  
 
Factory port-type
 
Factory port-type
 +
----
  
 
== Configuring JNDIs & Descriptors ==
 
== Configuring JNDIs & Descriptors ==

Revision as of 18:38, 26 March 2008

Adding State

In the first part of this tutorial we have created a stateless service for simplicity. However, the most common patterns used when developing gCube services are the ones that allow to create stateful service. In this part of the tutorial we will learn how to add a state to the SampleService.

Towards a multi port-type service

To add a state we need firstly to add two new port-types to the SampleService:

  • one is dedicated to create a new stateful resource, the so-called Factory service port-type
  • the other one is dedicated to access and manage the state, the so-called Service instance port-type

For both, we need to perform the same steps done for the Stateless port-type:

  • add the port-types to the profile file
  • define the WSDL interface for each port-type
  • provide the Java implementation of the two port-types

plus other specific steps that allow to manage stateful services.

Profiling for the infrastructure

The following is the new SERVICE/etc/profile.xml that declares the new two port-types.

<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<ID></ID>
	<Type>Service</Type>
	<Profile>
		<Description>A very simple gCube Service</Description>
		<Class>Samples</Class>
		<Name>SampleService</Name>
		<Packages>
			<Main>
				<Description>Describes port-types</Description>
				<Name>Main</Name>
				<Dependencies>
					<Dependency>
						<Service>
							<Class>Samples</Class>
							<Name>SampleService</Name>
						</Service>
						<Package>Stubs</Package>
						<Version>1.0</Version>
						<Scope level="GHN"/>
						<Optional>false</Optional>
					</Dependency>
				</Dependencies>
				<GARArchive>org.acme.sample.gar</GARArchive>
				<PortType>
					<Name>acme/sample/stateless</Name>
					<WSDL/>
				</PortType>
				<PortType>
					<Name>acme/sample/stateful</Name>
					<WSDL/>
				</PortType>
				<PortType>
					<Name>acme/sample/factory</Name>
					<WSDL/>
				</PortType>
			</Main>
			<Software>
				<Description>Describes port-type stubs</Description>
				<Name>Stubs</Name>
				<Files><File>org.acme.sample.stubs.jar</File></Files>
			</Software>
		</Packages>
	</Profile>
</Resource>

Defining the port-type interfaces

WSDL interface for the factory service

Create a new WSDL file, name it Factory.wsdl and place the file in the SERVICE/etc folder.

<definitions name="Factory"
    targetNamespace="http://acme.org/sample"
    xmlns:tns="http://acme.org/sample"
  	xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:corefaults="http://gcube-system.org/namespaces/common/core/faults"
    xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing" >
    
    <import namespace="http://gcube-system.org/namespaces/common/core/faults" location="../gcube/common/core/faults/GCUBEFaults.wsdl"/>
   
 	<types>
	<xsd:schema targetNamespace="http://acme.org/sample">
		
		 <xsd:import namespace="http://schemas.xmlsoap.org/ws/2004/03/addressing" 
schemaLocation="../ws/addressing/WS-Addressing.xsd" />
	
  		<xsd:element name="logon" type="xsd:string" />		
		<xsd:element name="logonResponse" type="wsa:EndpointReferenceType"/>
	</xsd:schema>
	</types>

	<message name="logonInputMessage">
		<part name="request" element="tns:logon"/>
	</message>
	<message name="logonOutputMessage">
		<part name="response" element="tns:logonResponse"/>
	</message>

	<portType name="FactoryPortType">
	
		<operation name="logon">
			<input message="tns:logonInputMessage"/>
			<output message="tns:logonOutputMessage"/>
			<fault name="fault" message="corefaults:GCUBEFaultMessage"></fault>
			<fault name="fault" message="corefaults:GCUBEUnrecoverableFaultMessage"></fault>
			<fault name="fault" message="corefaults:GCUBERetrySameFaultMessage"></fault>
			<fault name="fault" message="corefaults:GCUBERetryEquivalentFaultMessage"></fault>
		</operation>
	
	</portType>

</definitions>

Notes:

  • the interface imports the WS-Addressing.xsd to make use of the WS-Adressing types' definitions
  • the interface exposes one single operation allowing to create a new stateful resource, the logon operation
  • the operation takes a string as input parameter
  • the operation returns an EndpointReferenceType that points to the stateful resource

WSDL interface for the service instance

Create a new WSDL file, name it Stateful.wsdl and place the file in the SERVICE/etc folder.

<definitions name="Stateful"
    targetNamespace="http://acme.org/sample"
    xmlns:tns="http://acme.org/sample"
  	xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:coretypes="http://gcube-system.org/namespaces/common/core/types"
    xmlns:corefaults="http://gcube-system.org/namespaces/common/core/faults">
    
    <import namespace="http://gcube-system.org/namespaces/common/core/faults" 
location="../gcube/common/core/faults/GCUBEFaults.wsdl"/>
    
 	<types>
	<xsd:schema targetNamespace="http://acme.org/sample">    	
	    <xsd:import namespace="http://gcube-system.org/namespaces/common/core/types" 
schemaLocation="../gcube/common/core/types/GCUBETypes.xsd"/>
	    	
  		<xsd:element name="aboutSF" type="coretypes:VOID" />
		<xsd:element name="aboutSFResponse" type="xsd:string" />				        
                    
	</xsd:schema>
	</types>

	<message name="aboutSFInputMessage">
		<part name="request" element="tns:aboutSF"/>
	</message>
	<message name="aboutSFOutputMessage">
		<part name="response" element="tns:aboutSFResponse"/>
	</message>

	<portType name="StatefulPortType">        
	
		<operation name="aboutSF">
			<input message="tns:aboutSFInputMessage"/>
			<output message="tns:aboutSFOutputMessage"/>
			<fault name="fault" message="corefaults:GCUBEFaultMessage"></fault>
		</operation>	
	
	</portType>

</definitions>

Notes:

  • the port-type exposes a single operation, the aboutSF operation
  • the operation does not take any input, in these cases it must be passed an element coretypes:VOID to avoid SOAP issues
  • the operation returns a string

Delving into the implementation

The implementation of the stateful part of the SampleService is a bit more complex than the stateless one. The new classes will be placed in the new org.acme.sample.stateful.


Stateful Context


Resource


ResourceHome


Service instance port-type


Factory port-type


Configuring JNDIs & Descriptors

Building & Deploying

A Test Client

--Manuele.simi 03:21, 26 March 2008 (EET)