Guest User

Untitled

a guest
Apr 22nd, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.18 KB | None | 0 0
  1. class MyScalatraServlet extends ScalatraServlet with SQLServerTrait {
  2.     var jdbcUrl = "";
  3.  
  4.     override def init(config: ServletConfig) {
  5.       super.init(config)
  6.       jdbcUrl = "jdbc:jtds:sqlserver://" +
  7.             servletContext.getInitParameter("SQL_SERVER_ADDRESS") + ":" +
  8.             servletContext.getInitParameter("SQL_SERVER_PORT") +"/" +
  9.             servletContext.getInitParameter("SQL_SERVER_DB") + ";user=" +
  10.             servletContext.getInitParameter("SQL_SERVER_USER") + ";password=" +
  11.             servletContext.getInitParameter("SQL_SERVER_PASSWORD"))
  12.     }
  13.  
  14.     before("/*") {
  15.         contentType="application/json"
  16.         println(jdbcUrl)
  17.         connect(jdbcUrl)
  18.          
  19.     }
  20.  
  21.     after("/*") {
  22.         disconnect()
  23.     }
  24.  
  25.     notFound {
  26.         halt(status = 404, reason = "Not Found")
  27.     }
  28.  
  29.     options("/") {
  30.         halt(status = 200,
  31.           reason = "OK",
  32.           headers = Map("Allow" -> "GET"))
  33.     }
  34.  
  35.     get("/") {
  36.         //Code for sending data fetched from SQL Server back to the client
  37.         //...
  38.     }
  39.  
  40. }
  41.  
  42. // test
  43.  
  44. val servlet = new MyScalatraServlet
  45. servlet.jdbcUrl = testJdbcUrl
  46. addServlet(servlet, "/*")
Add Comment
Please, Sign In to add comment