Skip to content

Instantly share code, notes, and snippets.

View pgordon9's full-sized avatar
🎯
Focusing

Parker Gordon pgordon9

🎯
Focusing
View GitHub Profile
@pgordon9
pgordon9 / JettyExample.scala
Last active March 4, 2017 16:11
Complete JettyExample | parkergordon.io
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 September 26, 2016 05:05
Start Server. JettyExample | parkergordon.io
{...}
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 September 26, 2016 05:22
Binding servlet handler. JettyExample | parkergordon.io
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 March 4, 2017 16:06
ResetServlet. JettyExample | parkergordon.io
{...}
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 March 4, 2017 16:04
IncrementServlet. JettyExample | parkergordon.io
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 March 4, 2017 16:00
CounterServlets base. JettyExample | parkergordon.io
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 September 26, 2016 04:13
Get port the server is running on. JettyExample | parkergordon.io
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 September 26, 2016 03:56
Added createServer function JettyExample | parkergordon.io
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 September 26, 2016 05:31
Base JettyExample object with config variables | parkergordon.io
object JettyExample {
val incrementRoute = "/increment"
val resetRoute = "/reset"
def main(args: Array[String]) = {
}
}
@pgordon9
pgordon9 / pom.xml
Created September 26, 2016 02:44
Embedded Jetty Server - Maven | parkergordon.io
<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>