comparison sat_pubsub/tap_http.py @ 273:6ba0d6def7f5

Use twisted.web instead of web2, initial tests.
author Ralph Meijer <ralphm@ik.nu>
date Sun, 20 Jan 2013 13:38:41 +0100
parents d55620ceafed
children 002c59dbc23f
comparison
equal deleted inserted replaced
272:558a43366c9f 273:6ba0d6def7f5
50 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 50 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
51 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 51 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52 52
53 """ 53 """
54 54
55 from twisted.application import internet, service, strports 55 from twisted.application import internet, strports
56 from twisted.conch import manhole, manhole_ssh 56 from twisted.conch import manhole, manhole_ssh
57 from twisted.cred import portal, checkers 57 from twisted.cred import portal, checkers
58 from twisted.web2 import channel, log, resource, server 58 from twisted.web import resource, server
59 from twisted.web2.tap import Web2Service
60 59
61 from sat_pubsub import gateway, tap 60 from sat_pubsub import gateway, tap
62 from sat_pubsub.gateway import RemoteSubscriptionService 61 from sat_pubsub.gateway import RemoteSubscriptionService
63 62
64 class Options(tap.Options): 63 class Options(tap.Options):
104 # Set up web service 103 # Set up web service
105 104
106 root = resource.Resource() 105 root = resource.Resource()
107 106
108 # Set up resources that exposes the backend 107 # Set up resources that exposes the backend
109 root.child_create = gateway.CreateResource(bs, config['jid'], 108 root.putChild('create', gateway.CreateResource(bs, config['jid'],
110 config['jid']) 109 config['jid']))
111 root.child_delete = gateway.DeleteResource(bs, config['jid'], 110 root.putChild('delete', gateway.DeleteResource(bs, config['jid'],
112 config['jid']) 111 config['jid']))
113 root.child_publish = gateway.PublishResource(bs, config['jid'], 112 root.putChild('publish', gateway.PublishResource(bs, config['jid'],
114 config['jid']) 113 config['jid']))
115 root.child_list = gateway.ListResource(bs) 114 root.putChild('list', gateway.ListResource(bs))
116 115
117 # Set up resources for accessing remote pubsub nodes. 116 # Set up resources for accessing remote pubsub nodes.
118 root.child_subscribe = gateway.RemoteSubscribeResource(ss) 117 root.putChild('subscribe', gateway.RemoteSubscribeResource(ss))
119 root.child_unsubscribe = gateway.RemoteUnsubscribeResource(ss) 118 root.putChild('unsubscribe', gateway.RemoteUnsubscribeResource(ss))
120 root.child_items = gateway.RemoteItemsResource(ss) 119 root.putChild('items', gateway.RemoteItemsResource(ss))
121
122 if config["verbose"]:
123 root = log.LogWrapperResource(root)
124 120
125 site = server.Site(root) 121 site = server.Site(root)
126 w = internet.TCPServer(int(config['webport']), channel.HTTPFactory(site)) 122 w = internet.TCPServer(int(config['webport']), site)
127
128 if config["verbose"]:
129 logObserver = log.DefaultCommonAccessLoggingObserver()
130 w2s = Web2Service(logObserver)
131 w.setServiceParent(w2s)
132 w = w2s
133
134 w.setServiceParent(s) 123 w.setServiceParent(s)
135 124
136 # Set up a manhole 125 # Set up a manhole
137 126
138 namespace = {'service': s, 127 namespace = {'service': s,