Commit 27f346a6 authored by Sebastien Robin's avatar Sebastien Robin

Make the http synchronization working with only one way


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@597 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0849e7ca
...@@ -45,22 +45,6 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -45,22 +45,6 @@ class PublicationSynchronization(XMLSyncUtils):
""" """
LOG('PubSyncInit',0,'Starting... publication: %s' % str(publication)) LOG('PubSyncInit',0,'Starting... publication: %s' % str(publication))
#first_node = xml_client.childNodes[1]
#if first_node.nodeName != "SyncML":
# LOG('PubSyncInit',0,'This is not a SyncML Message')
# Get informations from the header
#client_header = first_node.childNodes[1]
#if client_header.nodeName != "SyncHdr":
# LOG('PubSyncInit',0,'This is not a SyncML Header')
#for subnode in client_header.childNodes:
# if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName == "Source":
# subscription_url = str(subnode.childNodes[0].data)
#subscriber = publication.getSubscriber(subscription_url) # Get the subscriber or create it if not already in the list
alert = None alert = None
# Get informations from the body # Get informations from the body
if xml_client is not None: # We have received a message if xml_client is not None: # We have received a message
...@@ -90,7 +74,6 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -90,7 +74,6 @@ class PublicationSynchronization(XMLSyncUtils):
#if alert is not None: #if alert is not None:
if 1: if 1:
# Prepare the xml message for the Sync initialization package # Prepare the xml message for the Sync initialization package
#file = open('/tmp/sync_init_server','w')
cmd_id = 1 # specifies a SyncML message-unique command identifier cmd_id = 1 # specifies a SyncML message-unique command identifier
xml = "" xml = ""
xml += '<SyncML>\n' xml += '<SyncML>\n'
...@@ -110,7 +93,9 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -110,7 +93,9 @@ class PublicationSynchronization(XMLSyncUtils):
xml += '</SyncML>\n' xml += '</SyncML>\n'
self.sendResponse(from_url=publication.getPublicationUrl(), self.sendResponse(from_url=publication.getPublicationUrl(),
to_url=subscriber.getSubscriptionUrl(),sync_id=publication.id,xml=xml) to_url=subscriber.getSubscriptionUrl(),sync_id=publication.id,xml=xml,
domain=publication)
return {'has_response':1,'xml':xml}
def PubSync(self, id, msg=None, RESPONSE=None, subscriber=None): def PubSync(self, id, msg=None, RESPONSE=None, subscriber=None):
...@@ -123,6 +108,7 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -123,6 +108,7 @@ class PublicationSynchronization(XMLSyncUtils):
if xml_client is None: if xml_client is None:
xml_client = self.readResponse(from_url='file://tmp/sync_server') xml_client = self.readResponse(from_url='file://tmp/sync_server')
LOG('PubSync',0,'Starting... msg: %s' % str(xml_client)) LOG('PubSync',0,'Starting... msg: %s' % str(xml_client))
result = None
if xml_client is not None: if xml_client is not None:
if type(xml_client) in (type('a'),type(u'a')): if type(xml_client) in (type('a'),type(u'a')):
...@@ -143,38 +129,33 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -143,38 +129,33 @@ class PublicationSynchronization(XMLSyncUtils):
if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName == "Source": if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName == "Source":
subscription_url = str(subnode.childNodes[0].data) subscription_url = str(subnode.childNodes[0].data)
# Get the subscriber or create it if not already in the list # Get the subscriber or create it if not already in the list
#subscriber = self.list_publications[id].getSubscriber(subscription_url)
subscriber = self.getPublication(id).getSubscriber(subscription_url) subscriber = self.getPublication(id).getSubscriber(subscription_url)
LOG('PubSync.getPublication: ',0,self.getPublication(id))
#LOG('PubSync.getSubscriber: ',0,self.getPublication(id))
#file.close()
if subscriber == None: if subscriber == None:
subscriber = Subscriber(subscription_url) subscriber = Subscriber(subscription_url)
# FIXME: Why can't we use the method addSubscriber ??
self.getPublication(id).addSubscriber(subscriber) self.getPublication(id).addSubscriber(subscriber)
# first synchronization # first synchronization
self.PubSyncInit(self.getPublication(id),xml_client,subscriber=subscriber,sync_type=self.SLOW_SYNC) result = self.PubSyncInit(self.getPublication(id),xml_client,subscriber=subscriber,sync_type=self.SLOW_SYNC)
elif self.checkAlert(xml_client) and alert_code in (self.TWO_WAY,self.SLOW_SYNC): elif self.checkAlert(xml_client) and alert_code in (self.TWO_WAY,self.SLOW_SYNC):
self.PubSyncInit(publication=self.getPublication(id), result = self.PubSyncInit(publication=self.getPublication(id),
xml_client=xml_client, subscriber=subscriber,sync_type=alert_code) xml_client=xml_client, subscriber=subscriber,sync_type=alert_code)
else: else:
self.PubSyncModif(self.getPublication(id), xml_client) result = self.PubSyncModif(self.getPublication(id), xml_client)
elif subscriber is not None: elif subscriber is not None:
# This looks like we are starting a synchronization after # This looks like we are starting a synchronization after
# a conflict resolution by the user # a conflict resolution by the user
self.PubSyncInit(publication=self.getPublication(id), result = self.PubSyncInit(publication=self.getPublication(id),
xml_client=None, subscriber=subscriber,sync_type=self.TWO_WAY) xml_client=None, subscriber=subscriber,sync_type=self.TWO_WAY)
has_response = 1 #pubsync always replies to messages has_response = 1 #pubsync always replies to messages
if RESPONSE is not None: if RESPONSE is not None:
RESPONSE.redirect('managePublications') RESPONSE.redirect('managePublications')
else: elif result is not None:
return 1 return result
def PubSyncModif(self, publication, xml_client): def PubSyncModif(self, publication, xml_client):
""" """
The modidification message for the publication The modidification message for the publication
""" """
self.SyncModif(publication,xml_client) return self.SyncModif(publication,xml_client)
...@@ -74,7 +74,9 @@ class SubscriptionSynchronization(XMLSyncUtils): ...@@ -74,7 +74,9 @@ class SubscriptionSynchronization(XMLSyncUtils):
xml += '</SyncML>\n' xml += '</SyncML>\n'
self.sendResponse(from_url=subscription.subscription_url, to_url=subscription.publication_url, self.sendResponse(from_url=subscription.subscription_url, to_url=subscription.publication_url,
sync_id=subscription.id, xml=xml) sync_id=subscription.id, xml=xml,domain=subscription)
return {'has_response':1,'xml':xml}
def SubSync(self, id, msg=None, RESPONSE=None): def SubSync(self, id, msg=None, RESPONSE=None):
""" """
...@@ -83,26 +85,24 @@ class SubscriptionSynchronization(XMLSyncUtils): ...@@ -83,26 +85,24 @@ class SubscriptionSynchronization(XMLSyncUtils):
LOG('SubSync',0,'starting... id: %s' % str(id)) LOG('SubSync',0,'starting... id: %s' % str(id))
LOG('SubSync',0,'starting... msg: %s' % str(msg)) LOG('SubSync',0,'starting... msg: %s' % str(msg))
has_response = 0 #check if subsync replies to this messages response = None #check if subsync replies to this messages
subscription = self.getSubscription(id) subscription = self.getSubscription(id)
if msg==None: if msg==None:
msg = self.readResponse(sync_id=id,from_url=subscription.getSubscriptionUrl()) msg = self.readResponse(sync_id=id,from_url=subscription.getSubscriptionUrl())
if msg==None: if msg==None:
self.SubSyncInit(self.getSubscription(id)) response = self.SubSyncInit(self.getSubscription(id))
has_response = 1
else: else:
xml_client = msg xml_client = msg
if type(xml_client) in (type('a'),type(u'a')): if type(xml_client) in (type('a'),type(u'a')):
xml_client = FromXml(xml_client) xml_client = FromXml(xml_client)
has_response = self.SubSyncModif(self.getSubscription(id),xml_client) response = self.SubSyncModif(self.getSubscription(id),xml_client)
if RESPONSE is not None: if RESPONSE is not None:
RESPONSE.redirect('manageSubscriptions') RESPONSE.redirect('manageSubscriptions')
else: else:
LOG('SubSync',0,'has_response: %s' % str(has_response)) return response
return has_response
def SubSyncModif(self, subscription, xml_client): def SubSyncModif(self, subscription, xml_client):
""" """
......
...@@ -229,7 +229,6 @@ class SynchronizationTool( UniqueObject, SimpleItem, ...@@ -229,7 +229,6 @@ class SynchronizationTool( UniqueObject, SimpleItem,
def manage_resetSubscription(self, id, RESPONSE=None): def manage_resetSubscription(self, id, RESPONSE=None):
""" """
reset a subscription reset a subscription
XXX R -> r
""" """
self.list_subscriptions[id].resetAllSignatures() self.list_subscriptions[id].resetAllSignatures()
self.list_subscriptions[id].resetAnchors() self.list_subscriptions[id].resetAnchors()
...@@ -460,12 +459,6 @@ class SynchronizationTool( UniqueObject, SimpleItem, ...@@ -460,12 +459,6 @@ class SynchronizationTool( UniqueObject, SimpleItem,
Do whatever needed in order to store the local value on Do whatever needed in order to store the local value on
the remote server the remote server
Suggestion:
manage_applyPublisherValue XXX
Suggestion:
add global apply (not conflict per conflict) XXX
Suggestion (API) Suggestion (API)
add method to view document with applied xupdate add method to view document with applied xupdate
of a given subscriber XX (ex. viewSubscriberDocument?path=ddd&subscriber_id=dddd) of a given subscriber XX (ex. viewSubscriberDocument?path=ddd&subscriber_id=dddd)
...@@ -522,7 +515,7 @@ class SynchronizationTool( UniqueObject, SimpleItem, ...@@ -522,7 +515,7 @@ class SynchronizationTool( UniqueObject, SimpleItem,
return context.getPhysicalPath() return context.getPhysicalPath()
security.declarePublic('sendResponse') security.declarePublic('sendResponse')
def sendResponse(self, to_url=None, from_url=None, sync_id=None,xml=None): def sendResponse(self, to_url=None, from_url=None, sync_id=None,xml=None, domain=None):
""" """
We will look at the url and we will see if we need to send mail, http We will look at the url and we will see if we need to send mail, http
response, or just copy to a file. response, or just copy to a file.
...@@ -536,7 +529,7 @@ class SynchronizationTool( UniqueObject, SimpleItem, ...@@ -536,7 +529,7 @@ class SynchronizationTool( UniqueObject, SimpleItem,
# we will send an http response # we will send an http response
self.activate(activity='RAMQueue').sendHttpResponse(sync_id=sync_id, self.activate(activity='RAMQueue').sendHttpResponse(sync_id=sync_id,
to_url=to_url, to_url=to_url,
xml=xml) xml=xml, domain=domain)
return None return None
elif to_url.find('file://')==0: elif to_url.find('file://')==0:
filename = to_url[len('file:/'):] filename = to_url[len('file:/'):]
...@@ -552,12 +545,24 @@ class SynchronizationTool( UniqueObject, SimpleItem, ...@@ -552,12 +545,24 @@ class SynchronizationTool( UniqueObject, SimpleItem,
self.sendMail(from_address,to_address,sync_id,xml) self.sendMail(from_address,to_address,sync_id,xml)
security.declarePrivate('sendHttpResponse') security.declarePrivate('sendHttpResponse')
def sendHttpResponse(self, to_url=None, sync_id=None, xml=None): def sendHttpResponse(self, to_url=None, sync_id=None, xml=None, domain=None ):
LOG('sendHttpResponse, starting with domain:',0,domain)
if domain is not None:
if domain.domain_type == self.PUB:
return xml
to_encode = (('text',xml),('sync_id',sync_id)) to_encode = (('text',xml),('sync_id',sync_id))
encoded = urllib.urlencode(to_encode) encoded = urllib.urlencode(to_encode)
to_url = to_url + '/portal_synchronizations/readResponse' to_url = to_url + '/portal_synchronizations/readResponse'
to_url
result = urllib.urlopen(to_url, encoded).read() result = urllib.urlopen(to_url, encoded).read()
LOG('sendHttpResponse, before result, domain:',0,domain)
LOG('sendHttpResponse, result:',0,result)
if domain is not None:
if domain.domain_type == self.SUB:
if result not in (None,''):
uf = self.acl_users
user = UnrestrictedUser('syncml','syncml',['Manager','Member'],'')
newSecurityManager(None, user)
self.activate(activity='RAMQueue').SubSync(sync_id,result)
security.declarePublic('readResponse') security.declarePublic('readResponse')
def readResponse(self, text=None, sync_id=None, to_url=None, from_url=None): def readResponse(self, text=None, sync_id=None, to_url=None, from_url=None):
...@@ -586,13 +591,13 @@ class SynchronizationTool( UniqueObject, SimpleItem, ...@@ -586,13 +591,13 @@ class SynchronizationTool( UniqueObject, SimpleItem,
url = subnode2.childNodes[0].data url = subnode2.childNodes[0].data
for publication in self.getPublicationList(): for publication in self.getPublicationList():
if publication.getPublicationUrl()==url: if publication.getPublicationUrl()==url:
self.PubSync(sync_id,xml) result = self.PubSync(sync_id,xml)
return None return result['xml']
for subscription in self.getSubscriptionList(): for subscription in self.getSubscriptionList():
if subscription.getSubscriptionUrl()==url: if subscription.getSubscriptionUrl()==url:
self.SubSync(sync_id,xml) result = self.SubSync(sync_id,xml)
return None if result is not None:
self.SubSync(sync_id,result)
# we use from only if we have a file # we use from only if we have a file
elif type(from_url) is type('a'): elif type(from_url) is type('a'):
......
...@@ -963,13 +963,13 @@ class XMLSyncUtils(XMLSyncUtilsMixin): ...@@ -963,13 +963,13 @@ class XMLSyncUtils(XMLSyncUtilsMixin):
xml += '</SyncML>\n' xml += '</SyncML>\n'
if domain.domain_type == self.PUB: # We always reply if domain.domain_type == self.PUB: # We always reply
self.sendResponse(from_url=domain.publication_url, to_url=subscriber.subscription_url, self.sendResponse(from_url=domain.publication_url, to_url=subscriber.subscription_url,
sync_id=domain.id, xml=xml) sync_id=domain.id, xml=xml,domain=domain)
has_response = 1 has_response = 1
elif domain.domain_type == self.SUB: elif domain.domain_type == self.SUB:
if self.checkAlert(remote_xml) or \ if self.checkAlert(remote_xml) or \
(xml_confirmation,syncml_data)!=('','') or \ (xml_confirmation,syncml_data)!=('','') or \
has_status_list: has_status_list:
self.sendResponse(from_url=domain.subscription_url, to_url=domain.publication_url, self.sendResponse(from_url=domain.subscription_url, to_url=domain.publication_url,
sync_id=domain.id, xml=xml) sync_id=domain.id, xml=xml,domain=domain)
has_response = 1 has_response = 1
return has_response return {'has_response':has_response,'xml':xml}
...@@ -304,11 +304,11 @@ class TestERP5SyncML(ERP5TypeTestCase): ...@@ -304,11 +304,11 @@ class TestERP5SyncML(ERP5TypeTestCase):
file.write('') file.write('')
file.close() file.close()
nb_message = 1 nb_message = 1
has_response = portal_sync.SubSync(subscription.getId()) result = portal_sync.SubSync(subscription.getId())
while has_response==1: while result['has_response']==1:
portal_sync.PubSync(publication.getId()) portal_sync.PubSync(publication.getId())
has_response = portal_sync.SubSync(subscription.getId()) result = portal_sync.SubSync(subscription.getId())
nb_message += 1 + has_response nb_message += 1 + result['has_response']
return nb_message return nb_message
def testFirstSynchronization(self, quiet=0, run=run_all_test): def testFirstSynchronization(self, quiet=0, run=run_all_test):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment