Mercurial > libervia-pubsub
comparison idavoll/gateway.py @ 191:48245777acea
Return proper HTTP status codes on failed un-/subscription.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Sat, 17 May 2008 18:31:31 +0000 |
parents | 69cdd8c6a431 |
children | e404775b12df |
comparison
equal
deleted
inserted
replaced
190:6e6c89eca9db | 191:48245777acea |
---|---|
489 the JID of the pubsub service, the node identifier | 489 the JID of the pubsub service, the node identifier |
490 and the callback URI as received in the HTTP POST | 490 and the callback URI as received in the HTTP POST |
491 request to this resource. | 491 request to this resource. |
492 """ | 492 """ |
493 serviceMethod = None | 493 serviceMethod = None |
494 errorMap = { | |
495 error.NodeNotFound: | |
496 (responsecode.FORBIDDEN, "Node not found"), | |
497 error.NotSubscribed: | |
498 (responsecode.FORBIDDEN, "No such subscription found"), | |
499 } | |
494 | 500 |
495 def __init__(self, service): | 501 def __init__(self, service): |
496 self.service = service | 502 self.service = service |
497 self.params = None | 503 self.params = None |
498 | 504 |
500 http_GET = None | 506 http_GET = None |
501 | 507 |
502 | 508 |
503 def http_POST(self, request): | 509 def http_POST(self, request): |
504 def trapNotFound(failure): | 510 def trapNotFound(failure): |
505 failure.trap(error.NodeNotFound) | 511 err = failure.trap(*self.errorMap.keys()) |
506 return http.StatusResponse(responsecode.NOT_FOUND, | 512 code, msg = self.errorMap[err] |
507 "Node not found") | 513 return http.StatusResponse(code, msg) |
508 | 514 |
509 def respond(result): | 515 def respond(result): |
510 return http.Response(responsecode.NO_CONTENT) | 516 return http.Response(responsecode.NO_CONTENT) |
511 | 517 |
512 def gotRequest(result): | 518 def gotRequest(result): |
732 headers={'Content-Type': MIME_JSON}, | 738 headers={'Content-Type': MIME_JSON}, |
733 agent=self.agent) | 739 agent=self.agent) |
734 return f.deferred | 740 return f.deferred |
735 | 741 |
736 | 742 |
743 def unsubscribe(self, xmppURI): | |
744 params = {'uri': xmppURI, | |
745 'callback': 'http://%s:%s/callback' % (self.callbackHost, | |
746 self.callbackPort)} | |
747 f = getPageWithFactory(self._makeURI('unsubscribe'), | |
748 method='POST', | |
749 postdata=simplejson.dumps(params), | |
750 headers={'Content-Type': MIME_JSON}, | |
751 agent=self.agent) | |
752 return f.deferred | |
753 | |
754 | |
737 def items(self, xmppURI, maxItems=None): | 755 def items(self, xmppURI, maxItems=None): |
738 query = {'uri': xmppURI} | 756 query = {'uri': xmppURI} |
739 if maxItems: | 757 if maxItems: |
740 query['max_items'] = int(maxItems) | 758 query['max_items'] = int(maxItems) |
741 f = getPageWithFactory(self._makeURI('items', query), | 759 f = getPageWithFactory(self._makeURI('items', query), |