Skip to content

Commit

Permalink
Merge pull request #57 from http4s/servlet-5
Browse files Browse the repository at this point in the history
Servlet 5 support
  • Loading branch information
rossabaker authored Jun 19, 2022
2 parents 24e8c46 + f034a53 commit 6f7e79f
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 55 deletions.
10 changes: 5 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// https://typelevel.org/sbt-typelevel/faq.html#what-is-a-base-version-anyway
ThisBuild / tlBaseVersion := "0.24" // your current series x.y
ThisBuild / tlBaseVersion := "0.25" // your current series x.y

ThisBuild / licenses := Seq(License.Apache2)
ThisBuild / developers := List(
Expand All @@ -21,10 +21,10 @@ ThisBuild / tlJdkRelease := Some(8)
lazy val root = tlCrossRootProject.aggregate(servlet, examples)

val asyncHttpClientVersion = "2.12.3"
val jettyVersion = "10.0.9"
val jettyVersion = "11.0.9"
val http4sVersion = "0.23.12"
val munitCatsEffectVersion = "1.0.7"
val servletApiVersion = "4.0.1"
val servletApiVersion = "5.0.0"

lazy val servlet = project
.in(file("servlet"))
Expand All @@ -33,7 +33,7 @@ lazy val servlet = project
description := "Portable servlet implementation for http4s servers",
startYear := Some(2013),
libraryDependencies ++= Seq(
"javax.servlet" % "javax.servlet-api" % servletApiVersion % Provided,
"jakarta.servlet" % "jakarta.servlet-api" % servletApiVersion % Provided,
"org.eclipse.jetty" % "jetty-client" % jettyVersion % Test,
"org.eclipse.jetty" % "jetty-server" % jettyVersion % Test,
"org.eclipse.jetty" % "jetty-servlet" % jettyVersion % Test,
Expand All @@ -54,7 +54,7 @@ lazy val examples = project
fork := true,
Jetty / containerLibs := List("org.eclipse.jetty" % "jetty-runner" % jettyVersion),
libraryDependencies ++= Seq(
"javax.servlet" % "javax.servlet-api" % servletApiVersion % Provided
"jakarta.servlet" % "jakarta.servlet-api" % servletApiVersion % Provided
),
)
.dependsOn(servlet)
Expand Down
7 changes: 3 additions & 4 deletions examples/src/main/scala/com/example/Bootstrap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ package com.example
import cats.effect.IO
import cats.effect.std.Dispatcher
import cats.effect.unsafe.implicits.global
import jakarta.servlet.ServletContextEvent
import jakarta.servlet.ServletContextListener
import jakarta.servlet.annotation.WebListener
import org.http4s._
import org.http4s.servlet.syntax._

import javax.servlet.ServletContextEvent
import javax.servlet.ServletContextListener
import javax.servlet.annotation.WebListener

@WebListener
/** 1. To start from sbt: `examples/Jetty/start`
* 2. Browse to http://localhost:8080/http4s/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package org.http4s.servlet

import javax.servlet.AsyncEvent
import javax.servlet.AsyncListener
import jakarta.servlet.AsyncEvent
import jakarta.servlet.AsyncListener

protected[servlet] abstract class AbstractAsyncListener extends AsyncListener {
override def onComplete(event: AsyncEvent): Unit = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import cats.effect.kernel.Async
import cats.effect.kernel.Deferred
import cats.effect.std.Dispatcher
import cats.syntax.all._
import jakarta.servlet._
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import org.http4s.server._

import javax.servlet._
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import scala.concurrent.duration.Duration

class AsyncHttp4sServlet[F[_]](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ package servlet
import cats.effect.kernel.Sync
import cats.effect.std.Dispatcher
import cats.syntax.all._
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import org.http4s.server._

import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

class BlockingHttp4sServlet[F[_]] private (
service: HttpApp[F],
servletIo: ServletIo[F],
Expand Down
20 changes: 11 additions & 9 deletions servlet/src/main/scala/org/http4s/servlet/Http4sServlet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import cats.syntax.all._
import com.comcast.ip4s.IpAddress
import com.comcast.ip4s.Port
import com.comcast.ip4s.SocketAddress
import jakarta.servlet.ServletConfig
import jakarta.servlet.http.HttpServlet
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import jakarta.servlet.http.HttpSession
import org.http4s._
import org.http4s.internal.CollectionCompat.CollectionConverters._
import org.http4s.server.SecureSession
Expand All @@ -32,11 +37,6 @@ import org.typelevel.ci._
import org.typelevel.vault._

import java.security.cert.X509Certificate
import javax.servlet.ServletConfig
import javax.servlet.http.HttpServlet
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import javax.servlet.http.HttpSession

abstract class Http4sServlet[F[_]](
service: HttpApp[F],
Expand Down Expand Up @@ -135,12 +135,14 @@ abstract class Http4sServlet[F[_]](
.insert(
ServerRequestKeys.SecureSession,
(
Option(req.getAttribute("javax.servlet.request.ssl_session_id").asInstanceOf[String]),
Option(req.getAttribute("javax.servlet.request.cipher_suite").asInstanceOf[String]),
Option(req.getAttribute("javax.servlet.request.key_size").asInstanceOf[Int]),
Option(
req.getAttribute("jakarta.servlet.request.ssl_session_id").asInstanceOf[String]
),
Option(req.getAttribute("jakarta.servlet.request.cipher_suite").asInstanceOf[String]),
Option(req.getAttribute("jakarta.servlet.request.key_size").asInstanceOf[Int]),
Option(
req
.getAttribute("javax.servlet.request.X509Certificate")
.getAttribute("jakarta.servlet.request.X509Certificate")
.asInstanceOf[Array[X509Certificate]]
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package org.http4s.servlet

import javax.servlet.ServletContext
import jakarta.servlet.ServletContext

import scala.math.Ordered.orderingToOrdered

final case class ServletApiVersion(major: Int, minor: Int) extends Ordered[ServletApiVersion] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package org.http4s
package servlet

import cats.effect._
import jakarta.servlet.DispatcherType
import jakarta.servlet.http.HttpFilter
import jakarta.servlet.http.HttpServlet
import org.http4s.server.ServerBuilder

import java.util
import javax.servlet.DispatcherType
import javax.servlet.http.HttpFilter
import javax.servlet.http.HttpServlet

abstract class ServletContainer[F[_]] extends ServerBuilder[F] {
type Self <: ServletContainer[F]
Expand Down
8 changes: 4 additions & 4 deletions servlet/src/main/scala/org/http4s/servlet/ServletIo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import cats.effect.std.Dispatcher
import cats.effect.std.Queue
import cats.syntax.all._
import fs2._
import jakarta.servlet.ReadListener
import jakarta.servlet.WriteListener
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import org.log4s.getLogger

import java.util.Arrays
import javax.servlet.ReadListener
import javax.servlet.WriteListener
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

/** Determines the mode of I/O used for reading request bodies and writing response bodies.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ package syntax

import cats.effect._
import cats.effect.std.Dispatcher
import jakarta.servlet.ServletContext
import jakarta.servlet.ServletRegistration
import org.http4s.server.DefaultServiceErrorHandler
import org.http4s.server.defaults
import org.http4s.syntax.all._

import javax.servlet.ServletContext
import javax.servlet.ServletRegistration
import scala.concurrent.duration.Duration

trait ServletContextSyntax {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@

package org.http4s.servlet

import javax.servlet.ServletInputStream
import javax.servlet.http.HttpServletRequest
import jakarta.servlet.ServletInputStream
import jakarta.servlet.http.HttpServletRequest

final case class HttpServletRequestStub(
inputStream: ServletInputStream
) extends HttpServletRequest {
def getInputStream(): ServletInputStream = inputStream

def authenticate(x$1: javax.servlet.http.HttpServletResponse): Boolean = ???
def authenticate(x$1: jakarta.servlet.http.HttpServletResponse): Boolean = ???
def changeSessionId(): String = ???
def getAuthType(): String = ???
def getContextPath(): String = ???
def getCookies(): Array[javax.servlet.http.Cookie] = ???
def getCookies(): Array[jakarta.servlet.http.Cookie] = ???
def getDateHeader(x$1: String): Long = ???
def getHeader(x$1: String): String = ???
def getHeaderNames(): java.util.Enumeration[String] = ???
def getHeaders(x$1: String): java.util.Enumeration[String] = ???
def getIntHeader(x$1: String): Int = ???
def getMethod(): String = ???
def getPart(x$1: String): javax.servlet.http.Part = ???
def getParts(): java.util.Collection[javax.servlet.http.Part] = ???
def getPart(x$1: String): jakarta.servlet.http.Part = ???
def getParts(): java.util.Collection[jakarta.servlet.http.Part] = ???
def getPathInfo(): String = ???
def getPathTranslated(): String = ???
def getQueryString(): String = ???
Expand All @@ -45,8 +45,8 @@ final case class HttpServletRequestStub(
def getRequestURL(): StringBuffer = ???
def getRequestedSessionId(): String = ???
def getServletPath(): String = ???
def getSession(): javax.servlet.http.HttpSession = ???
def getSession(x$1: Boolean): javax.servlet.http.HttpSession = ???
def getSession(): jakarta.servlet.http.HttpSession = ???
def getSession(x$1: Boolean): jakarta.servlet.http.HttpSession = ???
def getUserPrincipal(): java.security.Principal = ???
def isRequestedSessionIdFromCookie(): Boolean = ???
def isRequestedSessionIdFromURL(): Boolean = ???
Expand All @@ -55,15 +55,15 @@ final case class HttpServletRequestStub(
def isUserInRole(x$1: String): Boolean = ???
def login(x$1: String, x$2: String): Unit = ???
def logout(): Unit = ???
def upgrade[T <: javax.servlet.http.HttpUpgradeHandler](x$1: Class[T]): T = ???
def getAsyncContext(): javax.servlet.AsyncContext = ???
def upgrade[T <: jakarta.servlet.http.HttpUpgradeHandler](x$1: Class[T]): T = ???
def getAsyncContext(): jakarta.servlet.AsyncContext = ???
def getAttribute(x$1: String): Object = ???
def getAttributeNames(): java.util.Enumeration[String] = ???
def getCharacterEncoding(): String = ???
def getContentLength(): Int = ???
def getContentLengthLong(): Long = ???
def getContentType(): String = ???
def getDispatcherType(): javax.servlet.DispatcherType = ???
def getDispatcherType(): jakarta.servlet.DispatcherType = ???
def getLocalAddr(): String = ???
def getLocalName(): String = ???
def getLocalPort(): Int = ???
Expand All @@ -79,20 +79,20 @@ final case class HttpServletRequestStub(
def getRemoteAddr(): String = ???
def getRemoteHost(): String = ???
def getRemotePort(): Int = ???
def getRequestDispatcher(x$1: String): javax.servlet.RequestDispatcher = ???
def getRequestDispatcher(x$1: String): jakarta.servlet.RequestDispatcher = ???
def getScheme(): String = ???
def getServerName(): String = ???
def getServerPort(): Int = ???
def getServletContext(): javax.servlet.ServletContext = ???
def getServletContext(): jakarta.servlet.ServletContext = ???
def isAsyncStarted(): Boolean = ???
def isAsyncSupported(): Boolean = ???
def isSecure(): Boolean = ???
def removeAttribute(x$1: String): Unit = ???
def setAttribute(x$1: String, x$2: Object): Unit = ???
def setCharacterEncoding(x$1: String): Unit = ???
def startAsync(
x$1: javax.servlet.ServletRequest,
x$2: javax.servlet.ServletResponse,
): javax.servlet.AsyncContext = ???
def startAsync(): javax.servlet.AsyncContext = ???
x$1: jakarta.servlet.ServletRequest,
x$2: jakarta.servlet.ServletResponse,
): jakarta.servlet.AsyncContext = ???
def startAsync(): jakarta.servlet.AsyncContext = ???
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ package org.http4s.servlet

import cats.effect.IO
import cats.effect.Resource
import jakarta.servlet.Servlet
import org.eclipse.jetty.server.HttpConfiguration
import org.eclipse.jetty.server.HttpConnectionFactory
import org.eclipse.jetty.server.ServerConnector
import org.eclipse.jetty.server.{Server => EclipseServer}
import org.eclipse.jetty.servlet.ServletContextHandler
import org.eclipse.jetty.servlet.ServletHolder

import javax.servlet.Servlet

object TestEclipseServer {

def apply(
Expand Down

0 comments on commit 6f7e79f

Please sign in to comment.