Replace deprecated Jakarta Servlet methods and classes

org.openrewrite.java.migrate.jakarta.RemovalsServletJakarta10

This recipe replaces the classes and methods deprecated in Jakarta Servlet 6.0

Recipe source

GitHub, Issue Tracker, Maven Central

  • groupId: org.openrewrite.recipe

  • artifactId: rewrite-migrate-java

  • version: 2.12.0

This recipe is composed of more than one recipe. If you want to customize the set of recipes this is composed of, you can find and copy the GitHub source for the recipe from the link above.

Usage

This recipe has no required configuration options. It can be activated by adding a dependency on org.openrewrite.recipe:rewrite-migrate-java:2.12.0 in your build file or by running a shell command (in which case no build changes are needed):

  1. Add the following to your build.gradle file:

build.gradle
plugins {
    id("org.openrewrite.rewrite") version("6.12.0")
}

rewrite {
    activeRecipe("org.openrewrite.java.migrate.jakarta.RemovalsServletJakarta10")
}

repositories {
    mavenCentral()
}

dependencies {
    rewrite("org.openrewrite.recipe:rewrite-migrate-java:2.12.0")
}
  1. Run gradle rewriteRun to run the recipe.

Definition

  • Change type

    • oldFullyQualifiedTypeName: javax.servlet.http.HttpServletRequest

    • newFullyQualifiedTypeName: jakarta.servlet.http.HttpServletRequest

  • Change type

    • oldFullyQualifiedTypeName: javax.servlet.http.HttpServletRequestWrapper

    • newFullyQualifiedTypeName: jakarta.servlet.http.HttpServletRequestWrapper

  • Change type

    • oldFullyQualifiedTypeName: javax.servlet.http.HttpServletResponse

    • newFullyQualifiedTypeName: jakarta.servlet.http.HttpServletResponse

  • Change type

    • oldFullyQualifiedTypeName: javax.servlet.http.HttpServletResponseWrapper

    • newFullyQualifiedTypeName: jakarta.servlet.http.HttpServletResponseWrapper

  • Change type

    • oldFullyQualifiedTypeName: javax.servlet.http.HttpSession

    • newFullyQualifiedTypeName: jakarta.servlet.http.HttpSession

  • Change type

    • oldFullyQualifiedTypeName: javax.servlet.ServletContext

    • newFullyQualifiedTypeName: jakarta.servlet.ServletContext

  • Change type

    • oldFullyQualifiedTypeName: javax.servlet.UnavailableException

    • newFullyQualifiedTypeName: jakarta.servlet.UnavailableException

  • Change method name

    • methodPattern: jakarta.servlet.http.HttpServletRequest isRequestedSessionIdFromUrl()

    • newMethodName: isRequestedSessionIdFromURL

  • Change method name

    • methodPattern: jakarta.servlet.http.HttpServletRequestWrapper isRequestedSessionIdFromUrl()

    • newMethodName: isRequestedSessionIdFromURL

  • Change method name

    • methodPattern: jakarta.servlet.http.HttpServletResponse encodeUrl(String)

    • newMethodName: encodeURL

  • Change method name

    • methodPattern: jakarta.servlet.http.HttpServletResponseWrapper encodeUrl(String)

    • newMethodName: encodeURL

  • Change method name

    • methodPattern: jakarta.servlet.http.HttpServletResponse encodeRedirectUrl(String)

    • newMethodName: encodeRedirectURL

  • Change method name

    • methodPattern: jakarta.servlet.http.HttpServletResponseWrapper encodeRedirectUrl(String)"

    • newMethodName: encodeRedirectURL

  • Change method name

    • methodPattern: jakarta.servlet.http.HttpSession getValue(String)

    • newMethodName: getAttribute

  • Change method name

    • methodPattern: jakarta.servlet.http.HttpSession getValueNames()

    • newMethodName: getAttributeNames

  • Change method name

    • methodPattern: jakarta.servlet.http.HttpSession putValue(String, Object)

    • newMethodName: setAttribute

  • Change method name

    • methodPattern: jakarta.servlet.http.HttpSession removeValue(String)

    • newMethodName: removeAttribute

  • Delete method argument

    • methodPattern: jakarta.servlet.http.HttpServletResponse setStatus(int, String)

    • argumentIndex: 1

  • Delete method argument

    • methodPattern: jakarta.servlet.http.HttpServletResponseWrapper setStatus(int, String)

    • argumentIndex: 1

  • Reorder method arguments

    • methodPattern: jakarta.servlet.ServletContext log(Exception, String)

    • newParameterNames: [ex, str]

    • oldParameterNames: [str, ex]

    • matchOverrides: true

  • Delete method argument

    • methodPattern: jakarta.servlet.UnavailableException <constructor>(jakarta.servlet.Servlet, String)

    • argumentIndex: 0

  • Delete method argument

    • methodPattern: jakarta.servlet.UnavailableException <constructor>(int, jakarta.servlet.Servlet, String)

    • argumentIndex: 1

  • Reorder method arguments

    • methodPattern: jakarta.servlet.UnavailableException <constructor>(int, String)

    • newParameterNames: [str, in]

    • oldParameterNames: [in, str]

    • matchOverrides: true

See how this recipe works across multiple open-source repositories

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.

Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.

Contributors

Anu Ramamoorthy, Tim te Beek

Last updated