def __init__(self, dsn): # IMEDCON/imedcon@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.20.2.204)(PORT=1522))(CONNECT_DATA=(SID=TATESA))) self.user, self.password, self.server = re.findall("([^/]+)/([^@]+)@(.*)", dsn)[0] try: self.cn = cx_Oracle10g.connect(self.user, self.password, self.server) self.cr = self.cn.cursor() except cx_Oracle10g.DatabaseError, exc: log("cx_Oracle10g. Sin Conexion Oracle"); log(exc);
def __init__(self, dsn): # IMEDCON/imedcon@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.20.2.204)(PORT=1522))(CONNECT_DATA=(SID=TATESA))) self.user, self.password, self.server = re.findall( "([^/]+)/([^@]+)@(.*)", dsn)[0] try: self.cn = cx_Oracle10g.connect(self.user, self.password, self.server) self.cr = self.cn.cursor() except cx_Oracle10g.DatabaseError, exc: log("cx_Oracle10g. Sin Conexion Oracle") log(exc)
def handle(self): global ORACLE req = StringIO() cr = False while 1: line = self.rfile.readline() if line == '\n': break if line == '\r\n': cr = True break req.write(line) req = req.getvalue() log("REQ ", repr(req)) if REINTENTOS == "1": reintentos=2 else: reintentos=3 for i in range(1,reintentos): #Llama al Oracle log("Intento Numero",i) resp = ORACLE.sp_execcall(req) #Si fallo el Oracle, intento reconectar, sino exit #log("Print Resp",resp) if resp == "REINTENTE" or "ora-msg" in resp: try: log("Intento ReConexion ORA") try: ORACLE.cn.close() except: log("No se logro cerrar la ORACLE.cn.close") pass log("Connect") ORACLE.cn = cx_Oracle10g.connect(ORACLE.user, ORACLE.password, ORACLE.server) #log("Cursor") ORACLE.cr = ORACLE.cn.cursor() log("Re-Conectado OK") except: #Termino la ejecucion log("Falla Reconexion, Contesto Error") #Solo cambio la respuesta si la respuesta de sp viene con REINTENTE if resp == "REINTENTE": resp=json.dumps({ 'ora-err': "0", 'ora-msg': "Falla Oracle", 'API_ERROR' : "2", 'API_CODRESPUESTA' : "2", 'API_TIPO' : "ORACLE", 'API_DESCRIPCION_ERROR' : "Conexion Oracle No Establecida", 'xx_final_xx' :"**fin**" } , sort_keys=True) break else: #Si la respuesta en correcta sigo ejecucion break resp = resp.rstrip("\n") + "\n\n" if cr: resp = resp.replace('\n', '\r\n') log("RESP ", repr(resp)) #Respondo Socket self.wfile.write(resp) self.wfile.flush()
def handle(self): global ORACLE req = StringIO() cr = False while 1: line = self.rfile.readline() if line == '\n': break if line == '\r\n': cr = True break req.write(line) req = req.getvalue() log("REQ ", repr(req)) if REINTENTOS == "1": reintentos = 2 else: reintentos = 3 for i in range(1, reintentos): #Llama al Oracle log("Intento Numero", i) resp = ORACLE.sp_execcall(req) #Si fallo el Oracle, intento reconectar, sino exit #log("Print Resp",resp) if resp == "REINTENTE" or "ora-msg" in resp: try: log("Intento ReConexion ORA") try: ORACLE.cn.close() except: log("No se logro cerrar la ORACLE.cn.close") pass log("Connect") ORACLE.cn = cx_Oracle10g.connect(ORACLE.user, ORACLE.password, ORACLE.server) #log("Cursor") ORACLE.cr = ORACLE.cn.cursor() log("Re-Conectado OK") except: #Termino la ejecucion log("Falla Reconexion, Contesto Error") #Solo cambio la respuesta si la respuesta de sp viene con REINTENTE if resp == "REINTENTE": resp = json.dumps( { 'ora-err': "0", 'ora-msg': "Falla Oracle", 'API_ERROR': "2", 'API_CODRESPUESTA': "2", 'API_TIPO': "ORACLE", 'API_DESCRIPCION_ERROR': "Conexion Oracle No Establecida", 'xx_final_xx': "**fin**" }, sort_keys=True) break else: #Si la respuesta en correcta sigo ejecucion break resp = resp.rstrip("\n") + "\n\n" if cr: resp = resp.replace('\n', '\r\n') log("RESP ", repr(resp)) #Respondo Socket self.wfile.write(resp) self.wfile.flush()