#2486 Exception if custom protocol options are wrong. #2486
authordporopat <denis.poropat@smarteh.si>
Tue, 05 Jun 2018 15:29:58 +0200
branch#2486
changeset 2207 c27b820cb96b
parent 2206 1e397afc36a9
child 2211 46447d99e5f9
child 2561 cc7d88679483
#2486 Exception if custom protocol options are wrong.
runtime/WampClient.py
--- a/runtime/WampClient.py	Fri May 18 11:05:49 2018 +0200
+++ b/runtime/WampClient.py	Tue Jun 05 15:29:58 2018 +0200
@@ -27,7 +27,6 @@
 import time
 import json
 import os
-import inspect
 import re
 from autobahn.twisted import wamp
 from autobahn.twisted.websocket import WampWebSocketClientFactory, connectWS
@@ -137,14 +136,14 @@
         global _transportFactory
         WampWebSocketClientFactory.__init__(self, *args, **kwargs)
 
-        protocolOptions = config.extra.get('protocolOptions', None)
-        if protocolOptions:
-            arguments = inspect.getargspec(self.setProtocolOptions).args
-            validProtocolOptions = getValidOptins(protocolOptions, arguments)
-            if validProtocolOptions:
-                self.setProtocolOptions(**validProtocolOptions)
-                #print(_("Added custom protocol options"))
-        _transportFactory = self
+        try:
+            protocolOptions = config.extra.get('protocolOptions', None)
+            if protocolOptions:
+                self.setProtocolOptions(**protocolOptions)
+            _transportFactory = self
+        except Exception, e:
+            print(_("Custom protocol options failed :"), e)
+            _transportFactory = None
 
     def buildProtocol(self, addr):
         self.resetDelay()
@@ -199,6 +198,8 @@
             with open(os.path.realpath(_WampConf), 'w') as f:
                 json.dump(WSClientConf, f, sort_keys=True, indent=4)
             if 'active' in WSClientConf and WSClientConf['active']:
+                if _transportFactory and _WampSession:
+                    StopReconnectWampClient()
                 StartReconnectWampClient()
             else:
                 StopReconnectWampClient()
@@ -262,16 +263,20 @@
     session_factory.session = WampSession
 
     # create a WAMP-over-WebSocket transport client factory
-    transport_factory = ReconnectingWampWebSocketClientFactory(
+    ReconnectingWampWebSocketClientFactory(
         component_config,
         session_factory,
         url=WSClientConf["url"],
         serializers=[MsgPackSerializer()])
 
     # start the client from a Twisted endpoint
-    conn = connectWS(transport_factory)
-    print(_("WAMP client connecting to :"), WSClientConf["url"])
-    return True
+    if _transportFactory:
+        conn = connectWS(_transportFactory)
+        print(_("WAMP client connecting to :"), WSClientConf["url"])
+        return True
+    else:
+        print(_("WAMP client can not connect to :"), WSClientConf["url"])
+        return False
 
 
 def StopReconnectWampClient():