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):
"""
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
# Get informations from the body
if xml_client is not None: # We have received a message
......@@ -90,7 +74,6 @@ class PublicationSynchronization(XMLSyncUtils):
#if alert is not None:
if 1:
# 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
xml = ""
xml += '<SyncML>\n'
......@@ -110,7 +93,9 @@ class PublicationSynchronization(XMLSyncUtils):
xml += '</SyncML>\n'
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):
......@@ -123,6 +108,7 @@ class PublicationSynchronization(XMLSyncUtils):
if xml_client is None:
xml_client = self.readResponse(from_url='file://tmp/sync_server')
LOG('PubSync',0,'Starting... msg: %s' % str(xml_client))
result = None
if xml_client is not None:
if type(xml_client) in (type('a'),type(u'a')):
......@@ -143,38 +129,33 @@ class PublicationSynchronization(XMLSyncUtils):
if subnode.nodeType == subnode.ELEMENT_NODE and subnode.nodeName == "Source":
subscription_url = str(subnode.childNodes[0].data)
# 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)
LOG('PubSync.getPublication: ',0,self.getPublication(id))
#LOG('PubSync.getSubscriber: ',0,self.getPublication(id))
#file.close()
if subscriber == None:
subscriber = Subscriber(subscription_url)
# FIXME: Why can't we use the method addSubscriber ??
self.getPublication(id).addSubscriber(subscriber)
# 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):
self.PubSyncInit(publication=self.getPublication(id),
result = self.PubSyncInit(publication=self.getPublication(id),
xml_client=xml_client, subscriber=subscriber,sync_type=alert_code)
else:
self.PubSyncModif(self.getPublication(id), xml_client)
result = self.PubSyncModif(self.getPublication(id), xml_client)
elif subscriber is not None:
# This looks like we are starting a synchronization after
# 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)
has_response = 1 #pubsync always replies to messages
if RESPONSE is not None:
RESPONSE.redirect('managePublications')
else:
return 1
elif result is not None:
return result
def PubSyncModif(self, publication, xml_client):
"""
The modidification message for the publication
"""
self.SyncModif(publication,xml_client)
return self.SyncModif(publication,xml_client)
......@@ -74,7 +74,9 @@ class SubscriptionSynchronization(XMLSyncUtils):
xml += '</SyncML>\n'
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):
"""
......@@ -83,26 +85,24 @@ class SubscriptionSynchronization(XMLSyncUtils):
LOG('SubSync',0,'starting... id: %s' % str(id))
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)
if msg==None:
msg = self.readResponse(sync_id=id,from_url=subscription.getSubscriptionUrl())
if msg==None:
self.SubSyncInit(self.getSubscription(id))
has_response = 1
response = self.SubSyncInit(self.getSubscription(id))
else:
xml_client = msg
if type(xml_client) in (type('a'),type(u'a')):
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:
RESPONSE.redirect('manageSubscriptions')
else:
LOG('SubSync',0,'has_response: %s' % str(has_response))
return has_response
return response
def SubSyncModif(self, subscription, xml_client):
"""
......
......@@ -229,7 +229,6 @@ class SynchronizationTool( UniqueObject, SimpleItem,
def manage_resetSubscription(self, id, RESPONSE=None):
"""
reset a subscription
XXX R -> r
"""
self.list_subscriptions[id].resetAllSignatures()
self.list_subscriptions[id].resetAnchors()
......@@ -460,12 +459,6 @@ class SynchronizationTool( UniqueObject, SimpleItem,
Do whatever needed in order to store the local value on
the remote server
Suggestion:
manage_applyPublisherValue XXX
Suggestion:
add global apply (not conflict per conflict) XXX
Suggestion (API)
add method to view document with applied xupdate
of a given subscriber XX (ex. viewSubscriberDocument?path=ddd&subscriber_id=dddd)
......@@ -522,7 +515,7 @@ class SynchronizationTool( UniqueObject, SimpleItem,
return context.getPhysicalPath()
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
response, or just copy to a file.
......@@ -536,7 +529,7 @@ class SynchronizationTool( UniqueObject, SimpleItem,
# we will send an http response
self.activate(activity='RAMQueue').sendHttpResponse(sync_id=sync_id,
to_url=to_url,
xml=xml)
xml=xml, domain=domain)
return None
elif to_url.find('file://')==0:
filename = to_url[len('file:/'):]
......@@ -552,12 +545,24 @@ class SynchronizationTool( UniqueObject, SimpleItem,
self.sendMail(from_address,to_address,sync_id,xml)
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))
encoded = urllib.urlencode(to_encode)
to_url = to_url + '/portal_synchronizations/readResponse'
to_url
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')
def readResponse(self, text=None, sync_id=None, to_url=None, from_url=None):
......@@ -586,13 +591,13 @@ class SynchronizationTool( UniqueObject, SimpleItem,
url = subnode2.childNodes[0].data
for publication in self.getPublicationList():
if publication.getPublicationUrl()==url:
self.PubSync(sync_id,xml)
return None
result = self.PubSync(sync_id,xml)
return result['xml']
for subscription in self.getSubscriptionList():
if subscription.getSubscriptionUrl()==url:
self.SubSync(sync_id,xml)
return None
result = self.SubSync(sync_id,xml)
if result is not None:
self.SubSync(sync_id,result)
# we use from only if we have a file
elif type(from_url) is type('a'):
......
......@@ -963,13 +963,13 @@ class XMLSyncUtils(XMLSyncUtilsMixin):
xml += '</SyncML>\n'
if domain.domain_type == self.PUB: # We always reply
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
elif domain.domain_type == self.SUB:
if self.checkAlert(remote_xml) or \
(xml_confirmation,syncml_data)!=('','') or \
has_status_list:
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
return has_response
return {'has_response':has_response,'xml':xml}
......@@ -304,11 +304,11 @@ class TestERP5SyncML(ERP5TypeTestCase):
file.write('')
file.close()
nb_message = 1
has_response = portal_sync.SubSync(subscription.getId())
while has_response==1:
result = portal_sync.SubSync(subscription.getId())
while result['has_response']==1:
portal_sync.PubSync(publication.getId())
has_response = portal_sync.SubSync(subscription.getId())
nb_message += 1 + has_response
result = portal_sync.SubSync(subscription.getId())
nb_message += 1 + result['has_response']
return nb_message
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