Commit 43669437 authored by Ivan Tyagov's avatar Ivan Tyagov

Use already existing generic web service tool.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27394 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent acced39d
...@@ -47,7 +47,6 @@ from urllib import quote, unquote ...@@ -47,7 +47,6 @@ from urllib import quote, unquote
from DateTime import DateTime from DateTime import DateTime
from Products.PluggableAuthService.interfaces.plugins import IAuthenticationPlugin from Products.PluggableAuthService.interfaces.plugins import IAuthenticationPlugin
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
from urlparse import urlparse
# global (RAM) cookie storage # global (RAM) cookie storage
cookiejar = cookielib.CookieJar() cookiejar = cookielib.CookieJar()
...@@ -379,11 +378,16 @@ class WizardTool(BaseTool): ...@@ -379,11 +378,16 @@ class WizardTool(BaseTool):
finally: finally:
f.close() f.close()
def _getRemoteWitchTool(self, server_url): def _getRemoteWitchTool(self, url, user_name=None, password=None):
""" Return remote generator tool interface. """ """
server = xmlrpclib.ServerProxy(server_url, allow_none=1) Return remote portal_witch tool interface.
witch_tool = server.portal_witch """
return witch_tool handle = self.getPortalObject().portal_web_services.connect(
url = url, \
user_name = user_name, \
password = password, \
transport = 'xml-rpc')
return handle.portal_witch
def callRemoteProxyMethod(self, distant_method, server_url=None, use_cache=1, **kw): def callRemoteProxyMethod(self, distant_method, server_url=None, use_cache=1, **kw):
""" Call proxy method on server. """ """ Call proxy method on server. """
...@@ -401,7 +405,8 @@ class WizardTool(BaseTool): ...@@ -401,7 +405,8 @@ class WizardTool(BaseTool):
def _callRemoteMethod(self, distant_method, server_url=None, use_proxy=0, **kw): def _callRemoteMethod(self, distant_method, server_url=None, use_proxy=0, **kw):
""" Call remote method on server and get result. """ """ Call remote method on server and get result. """
result_call = GeneratorCall() result_call = GeneratorCall()
friendly_server_url = server_url user_name = None
password = None
if server_url is None: if server_url is None:
# calculate it # calculate it
server_url = self.getServerUrl() + self.getServerRoot() server_url = self.getServerUrl() + self.getServerRoot()
...@@ -409,12 +414,8 @@ class WizardTool(BaseTool): ...@@ -409,12 +414,8 @@ class WizardTool(BaseTool):
user_and_password = self._getSubsribedUserAndPassword() user_and_password = self._getSubsribedUserAndPassword()
if (len(user_and_password)==2 and if (len(user_and_password)==2 and
user_and_password[0] and user_and_password[1]): user_and_password[0] and user_and_password[1]):
friendly_server_url = server_url user_name, password = user_and_password
schema = urlparse(server_url) witch_tool = self._getRemoteWitchTool(server_url, user_name, password)
server_url = '%s://%s@%s%s' %(schema[0],
'%s:%s' %(user_and_password[0], user_and_password[1]), \
schema[1], schema[2])
witch_tool = self._getRemoteWitchTool(server_url)
parameter_dict = self.REQUEST.form.copy() parameter_dict = self.REQUEST.form.copy()
if use_proxy: if use_proxy:
# add remote method arguments # add remote method arguments
...@@ -431,7 +432,7 @@ class WizardTool(BaseTool): ...@@ -431,7 +432,7 @@ class WizardTool(BaseTool):
html = method(parameter_dict) html = method(parameter_dict)
except socket.error, message: except socket.error, message:
html = _generateErrorXML("""Cannot contact the server: %s. html = _generateErrorXML("""Cannot contact the server: %s.
Please check your network settings.""" %friendly_server_url) Please check your network settings.""" %server_url)
zLOG.LOG('Wizard Tool socket error', zLOG.ERROR, message) zLOG.LOG('Wizard Tool socket error', zLOG.ERROR, message)
result_call.update({"command": "show", result_call.update({"command": "show",
"data": html, "data": html,
...@@ -439,14 +440,14 @@ class WizardTool(BaseTool): ...@@ -439,14 +440,14 @@ class WizardTool(BaseTool):
"previous": None}) "previous": None})
except xmlrpclib.ProtocolError, message: except xmlrpclib.ProtocolError, message:
html = _generateErrorXML("""The server %s refused to reply. html = _generateErrorXML("""The server %s refused to reply.
Please contact erp5-dev@erp5.org""" %friendly_server_url) Please contact erp5-dev@erp5.org""" %server_url)
zLOG.LOG('Wizard Tool xmlrpc protocol error', zLOG.ERROR, message) zLOG.LOG('Wizard Tool xmlrpc protocol error', zLOG.ERROR, message)
result_call.update({"command": "show", result_call.update({"command": "show",
"data": html, "data": html,
"next": None, "next": None,
"previous": None}) "previous": None})
except xmlrpclib.Fault, message: except xmlrpclib.Fault, message:
html = _generateErrorXML("Error/bug inside the server: %s." %friendly_server_url) html = _generateErrorXML("Error/bug inside the server: %s." %server_url)
zLOG.LOG('Wizard Tool xmlrpc fault', zLOG.ERROR, message) zLOG.LOG('Wizard Tool xmlrpc fault', zLOG.ERROR, message)
result_call.update({"command": "show", result_call.update({"command": "show",
"data": html, "data": html,
......
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