Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PXS-82308] Update liftweb 2.6.3 to be Jakarta EE compatible #2

Open
wants to merge 2 commits into
base: v2.6.3_scala2.13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Dependencies._

organization in ThisBuild := "net.liftweb"

version in ThisBuild := "2.6.3-px-1"
version in ThisBuild := "2.6.3-px-jakarta-2"

homepage in ThisBuild := Some(url("http://www.liftweb.net"))

Expand Down
9 changes: 5 additions & 4 deletions core/util/src/main/scala/net/liftweb/util/Mailer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
package net.liftweb
package util

import javax.mail._
import javax.mail.internet._
import jakarta.activation.{DataHandler, DataSource}
import jakarta.mail._
import jakarta.mail.internet._
import javax.naming.{Context, InitialContext}
import java.util.Properties
import common._
Expand Down Expand Up @@ -278,7 +279,7 @@ trait Mailer extends SimpleInjector {
}

/**
* Given a MailBodyType, convert it to a javax.mail.BodyPart. You can override this method if you
* Given a MailBodyType, convert it to a jakarta.mail.BodyPart. You can override this method if you
* add custom MailBodyTypes
*/
protected def buildMailBody(tab: MailBodyType): BodyPart = {
Expand Down Expand Up @@ -336,7 +337,7 @@ trait Mailer extends SimpleInjector {
part.setFileName(holder.name)
part.setContentID(holder.name)
part.setDisposition(if (holder.attachment) Part.ATTACHMENT else Part.INLINE)
part.setDataHandler(new javax.activation.DataHandler(new javax.activation.DataSource {
part.setDataHandler(new DataHandler(new DataSource {
def getContentType = holder.mimeType
def getInputStream = new java.io.ByteArrayInputStream(holder.bytes)
def getName = holder.name
Expand Down
2 changes: 1 addition & 1 deletion core/util/src/test/scala/net/liftweb/util/MailerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package net.liftweb
package util

import javax.mail.internet.{MimeMessage, MimeMultipart}
import jakarta.mail.internet.{MimeMessage, MimeMultipart}

import org.specs2.mutable.Specification

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package net.liftweb
package jpa

import javax.persistence.EntityManager
import jakarta.persistence.EntityManager

import net.liftweb.http.TransientRequestVar

Expand Down
2 changes: 1 addition & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ object BuildDef extends Build {
.settings(description := "Utilities Library",
parallelExecution in Test := false,
libraryDependencies <++= scalaVersion {sv => Seq(joda_time,
joda_convert, commons_codec, javamail, log4j, htmlparser, xerces)}
joda_convert, commons_codec, jakartamail, log4j, htmlparser, xerces)}
)

// Web Projects
Expand Down
15 changes: 8 additions & 7 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ object Dependencies {
// Compile scope:
// Scope available in all classpath, transitive by default.
lazy val commons_codec = "commons-codec" % "commons-codec" % "1.6"
lazy val commons_fileupload = "commons-fileupload" % "commons-fileupload" % "1.3.1"
lazy val commons_fileupload = "org.apache.commons" % "commons-fileupload2-jakarta-servlet6" % "2.0.0-M2"
lazy val commons_httpclient = "commons-httpclient" % "commons-httpclient" % "3.1"
lazy val javamail = "javax.mail" % "mail" % "1.4.4"
lazy val jakartamail = "jakarta.mail" % "jakarta.mail-api" % "2.1.3"

lazy val joda_time = "joda-time" % "joda-time" % "2.1"
lazy val joda_convert = "org.joda" % "joda-convert" % "1.2"
lazy val htmlparser = "nu.validator.htmlparser" % "htmlparser" % "1.4"
Expand All @@ -64,11 +65,11 @@ object Dependencies {

// Provided scope:
// Scope provided by container, available only in compile and test classpath, non-transitive by default.
lazy val logback = "ch.qos.logback" % "logback-classic" % "1.0.9" % "provided"
lazy val log4j = "log4j" % "log4j" % "1.2.16" % "provided"
lazy val slf4j_log4j12 = "org.slf4j" % "slf4j-log4j12" % slf4jVersion % "provided"
lazy val persistence_api = "javax.persistence" % "persistence-api" % "1.0" % "provided"
lazy val servlet_api = "javax.servlet" % "servlet-api" % "2.5" % "provided"
lazy val logback = "ch.qos.logback" % "logback-classic" % "1.0.9" % "provided"
lazy val log4j = "log4j" % "log4j" % "1.2.16" % "provided"
lazy val slf4j_log4j12 = "org.slf4j" % "slf4j-log4j12" % slf4jVersion % "provided"
lazy val persistence_api = "javax.persistence" % "persistence-api" % "1.0" % "provided"
lazy val servlet_api = "jakarta.servlet" % "jakarta.servlet-api" % "6.0.0" % "provided"


// Runtime scope:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import java.util.Date
import java.util.Locale
import java.util.{Enumeration => JEnum}
import java.util.{HashMap => JHash}
import javax.servlet._
import javax.servlet.http._
import jakarta.servlet._
import jakarta.servlet.http._

import scala.collection.JavaConversions._
import scala.collection.mutable.ListBuffer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import java.util.Arrays
import java.util.Date
import java.util.Locale
import java.util.Vector
import javax.servlet._
import javax.servlet.http._
import jakarta.servlet._
import jakarta.servlet.http._

/**
* A Mock HttpServletResponse. Take a peek at it's writer or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import java.util.Arrays
import java.util.Date
import java.util.Locale
import java.util.Vector
import javax.servlet._
import javax.servlet.http._
import jakarta.servlet._
import jakarta.servlet.http._

/**
* An example of how to use these mock classes in your unit tests:
Expand Down
3 changes: 1 addition & 2 deletions web/webkit/src/main/scala/net/liftweb/http/LiftRules.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2053,8 +2053,7 @@ object StrictXHTML1_0Validator extends GenericValidator {

abstract class GenericValidator extends XHtmlValidator with Loggable {
import javax.xml.validation._
import javax.xml._
import XMLConstants._
import javax.xml.XMLConstants._
import java.net.URL
import javax.xml.transform.dom._
import javax.xml.transform.stream._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ package http
package provider
package servlet

import java.io.{InputStream}
import java.util.{Locale}
import javax.servlet.http.{HttpServletRequest}
import org.apache.commons.fileupload.servlet._
import org.apache.commons.fileupload.ProgressListener
import java.io.InputStream
import java.util.Locale
import jakarta.servlet.http.{HttpServletRequest}
import org.apache.commons.fileupload2.jakarta.servlet6.JakartaServletFileUpload
import org.apache.commons.fileupload2.core.ProgressListener
import net.liftweb.common._
import net.liftweb.util._
import Helpers._

import scala.language.postfixOps

class HTTPRequestServlet(val req: HttpServletRequest, val provider: HTTPProvider) extends HTTPRequest {
class HTTPRequestServlet(@transient val req: HttpServletRequest, @transient val provider: HTTPProvider) extends HTTPRequest {
private lazy val ctx = {
new HTTPServletContext(req.getSession.getServletContext)
}
Expand Down Expand Up @@ -69,7 +69,7 @@ class HTTPRequestServlet(val req: HttpServletRequest, val provider: HTTPProvider

// don't cache... allow multiple sessions for the request
// necessary for session destruction on login
def session = new HTTPServletSession(req getSession)
def session = new HTTPServletSession(req.getSession)

def uri = req.getRequestURI

Expand All @@ -95,19 +95,19 @@ class HTTPRequestServlet(val req: HttpServletRequest, val provider: HTTPProvider

def remoteHost: String = req.getRemoteHost

def serverName = req getServerName
def serverName = req.getServerName

def scheme: String = req getScheme
def scheme: String = req.getScheme

def serverPort = req getServerPort
def serverPort = req.getServerPort

def method: String = req.getMethod

def locale: Box[Locale] = Box !! req.getLocale

def inputStream: InputStream = req.getInputStream

def multipartContent_? = ServletFileUpload.isMultipartContent(req)
def multipartContent_? = JakartaServletFileUpload.isMultipartContent(req)

/**
* Destroy the underlying servlet session
Expand All @@ -129,11 +129,11 @@ class HTTPRequestServlet(val req: HttpServletRequest, val provider: HTTPProvider
} yield id

def extractFiles: List[ParamHolder] = (new Iterator[ParamHolder] {
val mimeUpload = (new ServletFileUpload)
val mimeUpload = new JakartaServletFileUpload
mimeUpload.setProgressListener(new ProgressListener {
lazy val progList: (Long, Long, Int) => Unit = S.session.flatMap(_.progressListener) openOr LiftRules.progressListener

def update(a: Long, b: Long, c: Int) {progList(a, b, c)}
def update(a: Long, b: Long, c: Int): Unit = {progList(a, b, c)}
})

mimeUpload.setSizeMax(LiftRules.maxMimeSize)
Expand All @@ -142,16 +142,16 @@ class HTTPRequestServlet(val req: HttpServletRequest, val provider: HTTPProvider

def hasNext = what.hasNext

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

def next = what.next match {
case f if (f.isFormField) => NormalParamHolder(f.getFieldName, new String(readWholeStream(f.openStream), "UTF-8"))
case f if (f.isFormField) => NormalParamHolder(f.getFieldName, new String(readWholeStream(f.getInputStream), "UTF-8"))
case f => {
val headers = f.getHeaders()
val names: List[String] = if (headers eq null) Nil else headers.getHeaderNames().asInstanceOf[java.util.Iterator[String]].asScala.toList
val map: Map[String, List[String]] = Map(names.map(n => n -> headers.getHeaders(n).asInstanceOf[java.util.Iterator[String]].asScala.toList) :_*)
LiftRules.withMimeHeaders(map) {
LiftRules.handleMimeFile(f.getFieldName, f.getContentType, f.getName, f.openStream)
LiftRules.handleMimeFile(f.getFieldName, f.getContentType, f.getName, f.getInputStream)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package servlet

import scala.collection.mutable.{ListBuffer}
import java.io.{OutputStream}
import javax.servlet.http.{HttpServletResponse, Cookie}
import jakarta.servlet.http.{HttpServletResponse, Cookie}
import net.liftweb.common._
import net.liftweb.util._
import Helpers._
Expand All @@ -33,7 +33,7 @@ class HTTPResponseServlet(resp: HttpServletResponse) extends HTTPResponse {

def addCookies(cookies: List[HTTPCookie]) = cookies.foreach {
case c =>
val cookie = new javax.servlet.http.Cookie(c.name, c.value openOr null)
val cookie = new Cookie(c.name, c.value openOr null)
c.domain map (cookie.setDomain(_))
c.path map (cookie.setPath(_))
c.maxAge map (cookie.setMaxAge(_))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package http
package provider
package servlet

import javax.servlet.{ServletContext}
import jakarta.servlet.{ServletContext}
import java.net.URL
import java.io.InputStream

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package http
package provider
package servlet

import javax.servlet.http._
import jakarta.servlet.http._
import net.liftweb.common._
import net.liftweb.util._

Expand Down Expand Up @@ -53,23 +53,23 @@ class HTTPServletSession(session: HttpSession) extends HTTPSession {
* Represents the "bridge" between HttpSession and LiftSession
*/
case class SessionToServletBridge(uniqueId: String) extends HttpSessionBindingListener with HttpSessionActivationListener {
def sessionDidActivate(se: HttpSessionEvent) = {
override def sessionDidActivate(se: HttpSessionEvent) = {
SessionMaster.getSession(uniqueId, Empty).foreach(ls =>
LiftSession.onSessionActivate.foreach(_(ls)))
}

def sessionWillPassivate(se: HttpSessionEvent) = {
override def sessionWillPassivate(se: HttpSessionEvent) = {
SessionMaster.getSession(uniqueId, Empty).foreach(ls =>
LiftSession.onSessionPassivate.foreach(_(ls)))
}

def valueBound(event: HttpSessionBindingEvent) {
override def valueBound(event: HttpSessionBindingEvent) {
}

/**
* When the session is unbound the the HTTP session, stop us
*/
def valueUnbound(event: HttpSessionBindingEvent) {
override def valueUnbound(event: HttpSessionBindingEvent) {
SessionMaster.sendMsg(RemoveSession(uniqueId))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package http
package provider
package servlet

import javax.servlet._
import javax.servlet.http._
import jakarta.servlet._
import jakarta.servlet.http._

import net.liftweb.common._
import net.liftweb.util._
Expand All @@ -32,7 +32,7 @@ trait ServletFilterProvider extends Filter with HTTPProvider {
var ctx: HTTPContext = _

//We need to capture the ServletContext on init
def init(config: FilterConfig) {
override def init(config: FilterConfig) {
ctx = new HTTPServletContext(config.getServletContext)

LiftRules.setContext(ctx)
Expand All @@ -42,7 +42,7 @@ trait ServletFilterProvider extends Filter with HTTPProvider {
}

//And throw it away on destruction
def destroy {
override def destroy {
ctx = null
terminate
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package provider
package servlet
package containers

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

import net.liftweb.common._
import net.liftweb.http._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ package provider
package servlet
package containers

import javax.servlet.http.HttpServletRequest
import jakarta.servlet.ServletRequest
import jakarta.servlet.http.HttpServletRequest

import net.liftweb.common._
import net.liftweb.http._
Expand All @@ -43,7 +44,7 @@ object Jetty7AsyncProvider extends AsyncProviderMeta {
isResumed) = {
try {
val cc = Class.forName("org.eclipse.jetty.continuation.ContinuationSupport")
val meth = cc.getMethod("getContinuation", classOf[javax.servlet.ServletRequest])
val meth = cc.getMethod("getContinuation", classOf[ServletRequest])
val cci = Class.forName("org.eclipse.jetty.continuation.Continuation")
val getAttribute = cci.getMethod("getAttribute", classOf[String])
val setAttribute = cci.getMethod("setAttribute", classOf[String], classOf[AnyRef])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ package provider
package servlet
package containers

import javax.servlet.http.HttpServletRequest
import javax.servlet._
import jakarta.servlet.http.{HttpServletRequest, HttpServletResponse}
//import jakarta.servlet._

import net.liftweb.common._
import net.liftweb.http._
Expand All @@ -40,8 +40,8 @@ object Servlet30AsyncProvider extends AsyncProviderMeta {
complete,
isSupported) = {
try {
val cc = Class.forName("javax.servlet.ServletRequest")
val asyncClass = Class.forName("javax.servlet.AsyncContext")
val cc = Class.forName("jakarta.servlet.ServletRequest")
val asyncClass = Class.forName("jakarta.servlet.AsyncContext")
val startAsync = cc.getMethod("startAsync")
val getResponse = asyncClass.getMethod("getResponse")
val complete = asyncClass.getMethod("complete")
Expand Down Expand Up @@ -107,7 +107,7 @@ class Servlet30AsyncProvider(req: HTTPRequest) extends ServletAsyncProvider with

def resume(what: (Req, LiftResponse)): Boolean = {
logger.trace("Servlet 3.0 begin resume")
val httpRes = getResponse.invoke(asyncCtx).asInstanceOf[javax.servlet.http.HttpServletResponse]
val httpRes = getResponse.invoke(asyncCtx).asInstanceOf[HttpServletResponse]
val httpResponse = new HTTPResponseServlet(httpRes)
val liftServlet = req.provider.liftServlet
try {
Expand Down