Merge branch 'IOTA-23' of https://github.com/shiv4nsh/incubator-iota
diff --git a/fey-core/src/main/resources/application.conf b/fey-core/src/main/resources/application.conf
index a80f13e..e732880 100644
--- a/fey-core/src/main/resources/application.conf
+++ b/fey-core/src/main/resources/application.conf
@@ -93,7 +93,8 @@
     enable = true,
     type = "COMPLETE"
   }
-
+  port = 16666
+  urlPath = "127.0.0.1"
 }
 
 // Fey akka configuration. Can not be overwritten by user
@@ -107,4 +108,9 @@
       mailbox-type = "akka.dispatch.UnboundedControlAwareMailbox"
     }
   }
-}
\ No newline at end of file
+}
+
+//Configuration for rest Api .
+
+play.crypto.secret = "apacheiota"
+play.crypto.secret = ${?APPLICATION_SECRET}
\ No newline at end of file
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/Application.scala b/fey-core/src/main/scala/org/apache/iota/fey/Application.scala
index d62c418..34bbc29 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/Application.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/Application.scala
@@ -18,13 +18,7 @@
 package org.apache.iota.fey
 
 import akka.actor.{ActorSystem, Props}
-import akka.io.IO
-import akka.pattern.ask
-import akka.util.Timeout
 import com.typesafe.config.ConfigFactory
-import spray.can.Http
-
-import scala.concurrent.duration._
 
 object Application extends App {
 
@@ -40,16 +34,11 @@
 
 object SYSTEM_ACTORS{
 
-  import FEY_SYSTEM._
-
   FEY_CORE_ACTOR
 
   FEY_CORE_ACTOR.actorRef ! FeyCore.START
 
-  val service = system.actorOf(Props[MyServiceActor], name = "FEY_REST_API")
-
-  implicit val timeout = Timeout(800.seconds)
-  IO(Http) ? Http.Bind(SYSTEM_ACTORS.service, interface = "0.0.0.0", port = 16666)
+  FeyUIService
 
 }
 
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/FeyUIService.scala b/fey-core/src/main/scala/org/apache/iota/fey/FeyUIService.scala
new file mode 100644
index 0000000..cb48192
--- /dev/null
+++ b/fey-core/src/main/scala/org/apache/iota/fey/FeyUIService.scala
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.iota.fey
+
+import org.apache.iota.fey.FeyCore.JSON_TREE
+import play.api.BuiltInComponents
+import play.api.http.DefaultHttpErrorHandler
+import play.api.libs.json.Json
+import play.api.mvc._
+import play.api.routing.Router
+import play.api.routing.sird._
+import play.core.server._
+import CONFIG._
+
+import scala.concurrent.Future
+
+object FeyUIService {
+
+
+  val components = new FeyUIService(URL_PATH, PORT)
+  val server = components.server
+}
+
+class FeyUIService(urlPath: String, port: Int) extends NettyServerComponents with BuiltInComponents {
+
+  lazy val router = Router.from {
+    case GET(p"/fey/activeactors") => Action {
+      FEY_CORE_ACTOR.actorRef ! JSON_TREE
+      Thread.sleep(2000)
+      val json = IdentifyFeyActors.generateTreeJson()
+      val jsonTree: String = IdentifyFeyActors.getHTMLTree(json)
+      Results.Ok(jsonTree).as("text/html")
+    }
+    case GET(p"/fey/actorslifecycle") => Action {
+      val jsonTree = Json.stringify(Monitor.events.printWithEvents)
+      Results.Ok(jsonTree).as("application/json")
+    }
+    case GET(p"/fey/monitoringevents") => Action {
+      val returnValue: String = try {
+        if (CONFIG.MONITORING_TYPE == "COMPLETE") {
+          Monitor.getHTMLevents
+        } else {
+          Monitor.getSimpleHTMLEvents
+        }
+      } catch {
+        case e: Exception => ""
+      }
+      Results.Ok(returnValue).as("text/html")
+    }
+  }
+
+  override lazy val serverConfig = ServerConfig(
+    port = Some(port),
+    address = urlPath
+  )
+  override lazy val httpErrorHandler = new DefaultHttpErrorHandler(environment,
+    configuration, sourceMapper, Some(router)) {
+
+    override protected def onNotFound(request: RequestHeader, message: String) = {
+      Future.successful(Results.NotFound("NO_DATA_FOUND"))
+    }
+  }
+}
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/MyService.scala b/fey-core/src/main/scala/org/apache/iota/fey/MyService.scala
deleted file mode 100644
index f686321..0000000
--- a/fey-core/src/main/scala/org/apache/iota/fey/MyService.scala
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.iota.fey
-
-import akka.actor.Actor
-import org.apache.iota.fey.FeyCore.JSON_TREE
-import play.api.libs.json.Json
-import spray.http.MediaTypes._
-import spray.routing._
-
-class MyServiceActor extends Actor with MyService {
-
-  // the HttpService trait defines only one abstract member, which
-  // connects the services environment to the enclosing actor or test
-  def actorRefFactory = context
-
-  // this actor only runs our route, but you could add
-  // other things here, like request stream processing
-  // or timeout handling
-  def receive = runRoute(myRoute)
-}
-
-sealed trait MyService extends HttpService {
-
-  val home = pathPrefix("fey")
-  val activeActors = path("activeactors")
-  val actorLifecycle = path("actorslifecycle")
-  val eventsTable = path("monitoringevents")
-  val test = path("test")
-
-  val myRoute =
-    home {
-      activeActors {
-        get{
-          respondWithMediaType(`text/html`) {
-            complete {
-              FEY_CORE_ACTOR.actorRef ! JSON_TREE
-              Thread.sleep(2000)
-              val json = IdentifyFeyActors.generateTreeJson()
-              IdentifyFeyActors.getHTMLTree(json)
-            }
-          }
-        }
-      } ~
-      actorLifecycle {
-        get{
-          respondWithMediaType(`application/json`) {
-            complete {
-              Json.stringify(Monitor.events.printWithEvents)
-            }
-          }
-        }
-      } ~
-        eventsTable {
-        get{
-          respondWithMediaType(`text/html`) {
-            complete {
-              try {
-                if(CONFIG.MONITORING_TYPE == "COMPLETE") {
-                  Monitor.getHTMLevents
-                }else{
-                  Monitor.getSimpleHTMLEvents
-                }
-              }catch {
-                case e: Exception => ""
-              }
-            }
-          }
-        }
-      }
-    }
-
-}
\ No newline at end of file
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala b/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala
index 14c2a0c..ff4e574 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala
@@ -224,12 +224,13 @@
   var CUSTOM_DISPATCHERS: ConfigValue = null
   var MONITORING_ENABLED: Boolean = true
   var MONITORING_TYPE: String = "COMPLETE"
+  var PORT = 8080
+  var URL_PATH = "localhost"
 
   def loadUserConfiguration(path: String) : Unit = {
-
     val app = {
       if(path != "" && Files.exists(Paths.get(path))) {
-          ConfigFactory.parseFile(new File(path)).withFallback(ConfigFactory.load())
+        ConfigFactory.parseFile(new File(path)).withFallback(ConfigFactory.load())
       }else {
           log.info("Using Fey Default Configuration")
           log.warn(s"No user configuration defined. Check if your configuration path $path is right.")
@@ -250,6 +251,8 @@
     CUSTOM_DISPATCHERS = app.getValue("custom-dispatchers")
     MONITORING_ENABLED = app.getBoolean("monitoring.enable")
     MONITORING_TYPE = app.getString("monitoring.type").toUpperCase()
+    PORT = app.getInt("port")
+    URL_PATH = app.getString("urlPath")
 
     setLogbackConfiguration()
   }
diff --git a/project/Build.scala b/project/Build.scala
index c648ce8..2036523 100644
--- a/project/Build.scala
+++ b/project/Build.scala
@@ -23,7 +23,7 @@
 
   import Dependencies._
   val FeyDependencies           = compile(akka_actor,typesafe_config,playJson,slf4j,log4jbind,sprayCan,
-                                            sprayRouting,jsonValidator,javaFilter,codec,apacheIO) ++ test(akka_testkit, scala_test)
+                                            sprayRouting,jsonValidator,javaFilter,codec,apacheIO,playNetty) ++ test(akka_testkit, scala_test)
   val StreamDependencies        = provided(akka_actor, fey)
   val ZMQDependencies           = provided(akka_actor,  fey) ++ compile(zmq)
   val VirtualSensorDependencies = provided(akka_actor,  fey) ++ compile(math3)
diff --git a/project/Dependencies.scala b/project/Dependencies.scala
index 49c9e3d..63cdce1 100644
--- a/project/Dependencies.scala
+++ b/project/Dependencies.scala
@@ -33,6 +33,7 @@
   val typesafe_config = "com.typesafe"        %  "config"                     % "1.3.0"
 
   val playJson        = "com.typesafe.play"   %% "play-json"                  % "2.5.3"
+  val playNetty = "com.typesafe.play" %% "play-netty-server" % "2.5.3"
   val jsonValidator   = "com.eclipsesource"   %% "play-json-schema-validator" % "0.7.0"
 
   //Logger