Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Parker Gordon pgordon9

🎯
Focusing
View GitHub Profile
@pgordon9
pgordon9 / JettyExample.scala
Last active Mar 4, 2017
Complete JettyExample | parkergordon.io
View JettyExample.scala
import org.eclipse.jetty.servlet.ServletHandler
import org.eclipse.jetty.server.{NetworkConnector, Server}
import javax.servlet.http.{HttpServlet, HttpServletRequest, HttpServletResponse}
object JettyExample {
import CounterServlets._
val incrementRoute = "/increment"
val resetRoute = "/reset"
val server = createServer()
@pgordon9
pgordon9 / JettyExample.scala
Created Sep 26, 2016
Start Server. JettyExample | parkergordon.io
View JettyExample.scala
{...}
object JettyExample {
{...}
val server = createServer()
def main(args: Array[String]) = {
{...}
server.start()
println(s"Server started on ${port()} with routes: '$incrementRoute'")
server.join()
@pgordon9
pgordon9 / JettyExample.scala
Last active Sep 26, 2016
Binding servlet handler. JettyExample | parkergordon.io
View JettyExample.scala
import org.eclipse.jetty.servlet.ServletHandler
object JettyExample {
{...}
import CounterServlets._
val incrementRoute = "/increment"
val resetRoute = "/reset"
val handler = new ServletHandler()
@pgordon9
pgordon9 / JettyExample.scala
Last active Mar 4, 2017
ResetServlet. JettyExample | parkergordon.io
View JettyExample.scala
{...}
object JettyExample{
{...}
object CounterServlets{
{...}
class ResetServlet extends HttpServlet {
override protected def doGet(request: HttpServletRequest, response: HttpServletResponse):Unit = {
requestCount.getAndIncrement()
response.setContentType("text/html")
@pgordon9
pgordon9 / JettyExample.scala
Last active Mar 4, 2017
IncrementServlet. JettyExample | parkergordon.io
View JettyExample.scala
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()
@pgordon9
pgordon9 / JettyExample.scala
Last active Mar 4, 2017
CounterServlets base. JettyExample | parkergordon.io
View JettyExample.scala
object JettyExample{
{...}
object CounterServlets{
private var requestCount: Int = AtomicInteger(0) // encapsulate the state in a Thread safe way
// TODO: Servlet Classes to go here
}
}
@pgordon9
pgordon9 / JettyExample.scala
Created Sep 26, 2016
Get port the server is running on. JettyExample | parkergordon.io
View JettyExample.scala
import org.eclipse.jetty.server.{NetworkConnector, Server}
object JettyExample{
{...}
def port() = {
val conn = server.getConnectors()(0).asInstanceOf[NetworkConnector]
conn.getLocalPort()
}
}
@pgordon9
pgordon9 / JettyExample.scala
Created Sep 26, 2016
Added createServer function JettyExample | parkergordon.io
View JettyExample.scala
import org.eclipse.jetty.server.Server
object JettyExample {
val server = createServer()
{...}
def createServer() = new Server(0) // 0 for random port
}
@pgordon9
pgordon9 / JettyExample.scala
Last active Sep 26, 2016
Base JettyExample object with config variables | parkergordon.io
View JettyExample.scala
object JettyExample {
val incrementRoute = "/increment"
val resetRoute = "/reset"
def main(args: Array[String]) = {
}
}
@pgordon9
pgordon9 / pom.xml
Created Sep 26, 2016
Embedded Jetty Server - Maven | parkergordon.io
View pom.xml
<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>
You can’t perform that action at this time.