Commits

Hector Miuler Malpica Gallegos committed 3b747d5

capturando las exceptiones y agregando el log

Comments (0)

Files changed (5)

     "junit" % "junit" % "4.10" % "test",
     "org.specs2" %% "specs2" % "1.12.1" % "test",
     "net.liftweb" %% "lift-json" % "2.5-M1",
-    "io.netty" % "netty" % "4.0.0.Alpha5"
+    "io.netty" % "netty" % "4.0.0.Alpha5",
+    "ch.qos.logback" % "logback-classic" % "1.0.7",
+    "org.slf4j" % "slf4j-api" % "1.6.6"
 )
 
 resolvers ++= Seq("snapshots" at "http://oss.sonatype.org/content/repositories/snapshots",

src/main/scala/com/miuler/mocksmtp/Main.scala

 
   def main(argv : Array[String]) {
     val mainGUI = new MainGUI()
-    mainGUI.run()
   }
 
 }

src/main/scala/com/miuler/mocksmtp/core/MockSMTP.scala

 package com.miuler.mocksmtp.core
 
 import io.netty.bootstrap.ServerBootstrap
+import org.slf4j.LoggerFactory
 
 /**
  * Created with IntelliJ IDEA.
  */
 class MockSMTP {
 
-  var server: ServerBootstrap = _
+  private val log = LoggerFactory.getLogger(classOf[MockSMTP])
 
-  //    println("initSMTP - inicio")
-  //    server = new ServerBootstrap()
-  //    server.localAddress(8080)
-  //    println("initSMTP - fin")
+  log.debug("initSMTP - inicio")
+  val server = new ServerBootstrap()
+  server.localAddress(8080)
+  log.debug("initSMTP - fin")
 
-  private def start = server.bind().sync()
 
-  private def stop = server.shutdown()
+  def start = server.bind().sync()
+
+  def stop = server.shutdown()
 
 }

src/main/scala/com/miuler/mocksmtp/gui/MainGUI.scala

 package com.miuler.mocksmtp.gui
 
 import com.trolltech.qt.gui._
+import com.miuler.mocksmtp.core.MockSMTP
+import org.slf4j.LoggerFactory
+import com.miuler.mocksmtp.utils.Utils.{stack2String, showMessageE}
 
 
 /**
  */
 class MainGUI(id: String = null, serverId: String = null) {
 
+  private val log = LoggerFactory.getLogger(classOf[MainGUI])
+
   var btnInitSMTP: QPushButton = _
   var btnStopSMTP: QPushButton = _
+  val mockSMTP = new MockSMTP()
 
-  def run() {
-    println("Hola Mundo")
-    QApplication.initialize(Array())
-    initGUI
-    QApplication.exec()
-  }
+  log.debug("MainGUI: Begin constructor")
+  QApplication.initialize(Array())
+  initGUI
+  QApplication.exec()
+  log.debug("MainGUI: End constructor")
 
-  def initGUI {
+
+  private def initGUI {
     btnInitSMTP = new QPushButton()
     btnInitSMTP.setCheckable(true)
     btnInitSMTP.setText("Iniciar servidor SMTP")
     layout.addWidget(btnStopSMTP)
 
     val window = new QWidget()
+    window.setWindowTitle("MOCK SMTP")
     window.setLayout(layout)
     window.show()
   }
 
   def startSMTP() {
-    println("\ninitSMTP ==============")
+    log.debug("\ninitSMTP ==============")
     if (btnInitSMTP.isChecked()) {
       btnInitSMTP.setDisabled(true)
       btnStopSMTP.toggle()
       btnStopSMTP.setDisabled(false)
     }
+
+    try {
+      mockSMTP start
+    } catch {
+      case e: Exception => {
+        log error stack2String(e)
+        showMessageE(e)
+      }
+    }
   }
 
   def stopSMTP() {
-    println("\nstopSMTP ==============")
-    println("btnInitSMTP.isChecked: " + btnInitSMTP.isChecked())
-    println("btnStopSMTP.isChecked: " + btnStopSMTP.isChecked())
+    log.debug("\nstopSMTP ==============")
+    log.debug("btnInitSMTP.isChecked: " + btnInitSMTP.isChecked())
+    log.debug("btnStopSMTP.isChecked: " + btnStopSMTP.isChecked())
     if (btnStopSMTP.isChecked()) {
       btnInitSMTP.setDisabled(false)
       btnInitSMTP.toggle()

src/main/scala/com/miuler/mocksmtp/utils/Utils.scala

+package com.miuler.mocksmtp.utils
+
+import java.io.{StringWriter, PrintWriter}
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: miuler
+ * Date: 01/10/12
+ * Time: 06:08 PM
+ * To change this template use File | Settings | File Templates.
+ */
+object Utils {
+
+  def stack2String (e: Exception) = {
+    val stringWriter = new StringWriter()
+    e printStackTrace (new PrintWriter(stringWriter))
+    stringWriter toString
+  }
+
+  def showMessageE(e: Exception) {
+    val stack = stack2String(e)
+
+    val msgBox = new QMessageBox
+    msgBox setText "Error in Server SMTP:"
+    msgBox setInformativeText e.getMessage
+    msgBox setDetailedText stack
+    msgBox show
+  }
+
+}