This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.eclipse.jetty</groupId> | |
<artifactId>jetty-server</artifactId> | |
<version>9.3.12.v20160915</version> | |
</dependency> | |
<dependency> | |
<groupId>org.eclipse.jetty</groupId> | |
<artifactId>jetty-servlet</artifactId> | |
<version>9.3.12.v20160915</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
libraryDependencies ++= Seq( | |
"org.eclipse.jetty" % "jetty-servlet" % "9.3.12.v20160915", | |
"org.eclipse.jetty" % "jetty-server" % "9.3.12.v20160915" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.eclipse.jetty.server.Server | |
object JettyExample { | |
val server = createServer() | |
{...} | |
def createServer() = new Server(0) // 0 for random port | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.eclipse.jetty.server.{NetworkConnector, Server} | |
object JettyExample{ | |
{...} | |
def port() = { | |
val conn = server.getConnectors()(0).asInstanceOf[NetworkConnector] | |
conn.getLocalPort() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{...} | |
object JettyExample { | |
{...} | |
val server = createServer() | |
def main(args: Array[String]) = { | |
{...} | |
server.start() | |
println(s"Server started on ${port()} with routes: '$incrementRoute'") | |
server.join() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.eclipse.jetty.servlet.ServletHandler | |
object JettyExample { | |
{...} | |
import CounterServlets._ | |
val incrementRoute = "/increment" | |
val resetRoute = "/reset" | |
val handler = new ServletHandler() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object JettyExample { | |
val incrementRoute = "/increment" | |
val resetRoute = "/reset" | |
def main(args: Array[String]) = { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object JettyExample{ | |
{...} | |
object CounterServlets{ | |
private var requestCount: Int = AtomicInteger(0) // encapsulate the state in a Thread safe way | |
// TODO: Servlet Classes to go here | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.servlet.http.{HttpServlet, HttpServletRequest, HttpServletResponse} | |
object JettyExample{ | |
{...} | |
object CounterServlets{ | |
private var requestCount: Int = AtomicInteger(0) | |
class IncrementServlet extends HttpServlet { | |
override protected def doGet(request: HttpServletRequest, response: HttpServletResponse):Unit = { | |
requestCount.getAndIncrement() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{...} | |
object JettyExample{ | |
{...} | |
object CounterServlets{ | |
{...} | |
class ResetServlet extends HttpServlet { | |
override protected def doGet(request: HttpServletRequest, response: HttpServletResponse):Unit = { | |
requestCount.getAndIncrement() | |
response.setContentType("text/html") |
OlderNewer