HOWTO
c. Add Service Instance to Twisted Container
Add your WSDL entry under appropriate section in "pyGridWare/config.txt".
[WSDL]
CounterService
= share/schema/core/samples/counter/counter_service.wsdl
Regenerate all bindings and install.
%python
setup.py --regenerate install
Generates
several modules for each WSDL (eg. Òcounter_service.wsdlÓ)
1) Types
module:
pyGridWare/generated/types/counterservice.py
2) Client module:
pyGridWare/generated/stubs/counterservice.py
3) Service stub module:
pyGridWare/generated/services/stubs/counterservice.py
4) Service WSRF modules:
pyGridWare/generated/services/counterservice/CounterService.py
pyGridWare/generated/properties/counterservice/CounterService/CounterPortTypePort.py
pyGridWare/generated/resource/counterservice/CounterService.py
Create a resource
import
pyGridWare.generated.stubs.Counter_services as COUNTER
locator
= COUNTER.CounterServiceLocator()
port
= locator.getCounterPortType(portAddress=url, **kw)
request
= COUNTER.CreateCounterRequest()
msg
= port.createCounter(request)
Counter Port using EPR
epr = msg._EndpointReference
port
= locator.getCounterPortType(portAddress=url, \
endPointReference=epr, **kw)
First you need to create a notification consumer, and from it you can retrieve the notification context. Second, provide the notificationConsumer's EPR in the Subscribe message, and also provide the resource property QName we want to be notified about.
from
pyGridWare.notification.NotificationConsumer import \
NotificationConsumer
notificationConsumer
= NotificationConsumer()
notificationConsumer.start()
WARNING -- The topic expression expects to
receive a QName in text content.
This is a little screwy since we need to manually specify the prefix
mapping, to do this we need to specify a typecode attribute for the text
content.
Class
Qname(tuple):
typecode = ZSI.TC.Qname()
ctx
= notificationConsumer.getNotificationContext()
request
= COUNTER.SubscribeRequest()
request._ConsumerReference
= ctx.getConsumerReference()
request._TopicExpression
= TopicExpression()
request._TopicExpression._text
= Qname(Òhttp://counter.comÓ, ÒValueÓ)
request._UseNotify
= True
msg
= port.Subscribe(request)
First youÕll need to create a resource context, and resource home. The context will hold state and information specific to the resource. Secondly youÕll need to implement the service by sub-classing the generated server module.
Eg. 'pyGridWare.services.CounterService'.
First subclass the generated server interface, and overide any "wsa_" methods you need to and call the base class method to set up the request instance (available as "self.request") and initialize the response (return by base class "wsa_" call).
All the logic of each operation will reside within the service's "wsa_" methods. Standard WSRF methods will already be implemented in the generated code.
Types of Operations:
First need to create a context, set the URL of the service, and register it to the resource home. Then need to retrieve the End Point Reference (EPR) from the context instance, and set this in the response message that is returned to the calling party.
Automatically generated.
Automatically generated.
Automatically generated.
Retrieve the resource context from the ResourceHome, then grab the resource properties from the resource context. Then grab the "Value" resource property. Add "self.request" to "Value", and set the "Value" resource property to their sum.
Subscribe to a resource property to receive notifications when that resource property's state changes. Retrieve the resource context from the ResourceHome, then get the SubscriptionManager singleton. Use the Subscription Manager to subscribe to the resource property using the request, it will return an EPR representing the subscription that must be returned in the response message.
Eg. "pyGridWare.generated.services.Counter_services_server.py"
Inherit from class GssSecureResourceMixIn.
from pyGridWare.services.CounterService import Counter
from pyGridWare.security.gss.GssService import GssSecureResourceMixIn
class SecureCounter(GssSecureResourceService, Counter):
def __init__(self, post='/wsrf/services/SecureCounterService', **kw):
GssSecureResourceService.__init__(self, post)
Basically you need to identify or create the resource node in the siteÕs resource tree where the service instance will reside, and also pass in the POST value when creating the service instance.
Run the twisted service container:
%./start-container.sh