Conversation
src/main/java/org/openrewrite/java/spring/mvc/JaxrsToSpringmvcAnnotations.java
Outdated
Show resolved
Hide resolved
timtebeek
left a comment
There was a problem hiding this comment.
Thanks for getting this started @yasaswigadde ; let us know if you need any help.
Thanks @timtebeek, appreciate the support! |
src/main/java/org/openrewrite/java/spring/mvc/JaxrsToSpringmvcAnnotations.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/spring/mvc/JaxrsToSpringmvcAnnotations.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/spring/mvc/JaxrsToSpringmvcAnnotations.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/spring/mvc/JaxrsToSpringmvcMediaType.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/spring/mvc/JaxrsToSpringmvcResponseEntity.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/spring/mvc/MigrateJaxrsToSpringmvcTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/spring/mvc/MigrateJaxrsToSpringmvcTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/spring/mvc/MigrateJaxrsToSpringmvcTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/spring/mvc/MigrateJaxrsToSpringmvcTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/spring/mvc/MigrateJaxrsToSpringmvcTest.java
Outdated
Show resolved
Hide resolved
|
Hi @timtebeek I am trying to the tests in local, but I'm getting - And also, I am getting this during build -
Can you let me know if I'm missing anything? |
|
Sorry to hear about your troubles; for the CSV issue it should print a suggestion to run For the type tables there's only an entry in the test type tables: If you need that in Hope that helps you on your way there! |
|
Thanks! I am able to run the test cases after changing them to parserClasspath. |
| @Override | ||
| public String getDisplayName() { | ||
| return "Migrate jax-rs annotations to spring MVC annotations"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDescription() { | ||
| return "Replaces all jax-rs annotations with Spring MVC annotations."; | ||
| } | ||
|
|
||
| @Override | ||
| public Set<String> getTags() { |
There was a problem hiding this comment.
| @Override | |
| public String getDisplayName() { | |
| return "Migrate jax-rs annotations to spring MVC annotations"; | |
| } | |
| @Override | |
| public String getDescription() { | |
| return "Replaces all jax-rs annotations with Spring MVC annotations."; | |
| } | |
| @Override | |
| public Set<String> getTags() { | |
| String displayName = "Migrate jax-rs annotations to spring MVC annotations"; | |
| String description = "Replaces all jax-rs annotations with Spring MVC annotations."; | |
| Set<String> tags = new HashSet<>(Arrays.asList("Java", "Spring")); |
| import java.util.Set; | ||
|
|
||
| @Value | ||
| @EqualsAndHashCode(callSuper = false) | ||
| public class JaxrsToSpringmvcMediaType extends Recipe { | ||
|
|
||
| @Override | ||
| public String getDisplayName() { | ||
| return "Migrate jax-rs MediaType to spring MVC MediaType"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDescription() { |
There was a problem hiding this comment.
| import java.util.Set; | |
| @Value | |
| @EqualsAndHashCode(callSuper = false) | |
| public class JaxrsToSpringmvcMediaType extends Recipe { | |
| @Override | |
| public String getDisplayName() { | |
| return "Migrate jax-rs MediaType to spring MVC MediaType"; | |
| } | |
| @Override | |
| public String getDescription() { | |
| String displayName = "Migrate jax-rs MediaType to spring MVC MediaType"; | |
| String description = "Replaces all jax-rs MediaType with Spring MVC MediaType."; | |
| Set<String> tags = new HashSet<>(Arrays.asList("Java", "Spring")); |
| import org.openrewrite.java.tree.Expression; | ||
| import org.openrewrite.java.tree.J; | ||
|
|
||
| import java.util.*; |
There was a problem hiding this comment.
| import java.util.*; | |
| import java.util.ArrayList; | |
| import java.util.Arrays; | |
| import java.util.HashSet; | |
| import java.util.List; |
| @Override | ||
| public String getDisplayName() { | ||
| return "Migrate jax-rs Response to spring MVC ResponseEntity"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDescription() { | ||
| return "Replaces all jax-rs Response with Spring MVC ResponseEntity."; | ||
| } | ||
|
|
||
| @Override | ||
| public Set<String> getTags() { |
There was a problem hiding this comment.
| @Override | |
| public String getDisplayName() { | |
| return "Migrate jax-rs Response to spring MVC ResponseEntity"; | |
| } | |
| @Override | |
| public String getDescription() { | |
| return "Replaces all jax-rs Response with Spring MVC ResponseEntity."; | |
| } | |
| @Override | |
| public Set<String> getTags() { | |
| String displayName = "Migrate jax-rs Response to spring MVC ResponseEntity"; | |
| String description = "Replaces all jax-rs Response with Spring MVC ResponseEntity."; | |
| Set<String> tags = new HashSet<>(Arrays.asList("Java", "Spring")); |
| void jaxrsToSpringmvcAnnotationsTest1() { | ||
| rewriteRun( | ||
| java( | ||
| """ |
There was a problem hiding this comment.
| """ | |
| """ |
| .build() | ||
| .activateRecipes("org.openrewrite.java.spring.mvc.MigrateJaxRsToSpringMvc")) | ||
| .parser(JavaParser.fromJavaVersion() | ||
| .classpathFromResources(new InMemoryExecutionContext(), "jakarta.ws.rs-api-4", "javax.ws.rs-api-2"));; |
There was a problem hiding this comment.
| .classpathFromResources(new InMemoryExecutionContext(), "jakarta.ws.rs-api-4", "javax.ws.rs-api-2"));; | |
| .classpathFromResources(new InMemoryExecutionContext(), "jakarta.ws.rs-api-4", "javax.ws.rs-api-2")); |
| void jaxrsToSpringmvcJavaxTest() { | ||
| rewriteRun( | ||
| java( | ||
| """ |
There was a problem hiding this comment.
| """ | |
| """ |
| } | ||
| } | ||
| """, | ||
| """ |
There was a problem hiding this comment.
| """ | |
| """ |
| void jaxrsToSpringmvcJakartaTest() { | ||
| rewriteRun( | ||
| java( | ||
| """ |
There was a problem hiding this comment.
| """ | |
| """ |
| } | ||
| } | ||
| """, | ||
| """ |
There was a problem hiding this comment.
| """ | |
| """ |
What's changed?
Added a Recipe for Jax-RS to Spring MVC Migration
What's your motivation?
Needed to migrate a project from Jax-rs to Spring MVC. Tried finding the recipe on Moderne but couldn't. Noticed that it is a wanted recipe - #69. Hence decided to create one as it can also be used by others.
Have you considered any alternatives or workarounds?
Tried creating declarative recipe first, but couldn't achieve the required functionality.
Any additional context
Custom Recipes
Three Imperative Recipes are created to facilitate JAX-RS to Spring MVC migration:
1. JAX-RS Annotation Transformation Recipe
Converts JAX-RS REST annotation to Spring MVC equivalents
valueparameter within annotations @GetMapping or @PostMapping etc.consumesandproducesparameters within the annotations @RequestMapping or @GetMapping etc.defaultValueparameter within annotation @RequestParam. Else therequiredparameter is set tofalsewithin annotation @RequestParam, since QueryParam and FormParam are optional in JAX-RS and RequestParam is required by default and will throw error if not provided.defaultValueparameter within annotation @RequestHeader. Else therequiredparameter is set tofalsewithin annotation @RequestParam, since HeaderParam is optional in JAX-RS and RequestHeader is required by default and will throw error if not provided.multipartin it.multipartconsumer.2. MediaType Transformation Recipe
Converts JAX-RS MediaType to Spring's MediaType
3. Response Object Conversion Recipe
Converts JAX-RS Response to Spring's ResponseEntity
Change Type Recipes Used
org.openrewrite.java.ChangeType Recipe is used in Declarative Recipe to migrate few JAX-RS components to respective Spring components:
Known Limitations
required = falsefor these parameters when there is no default value. Parameter should be reviewed and updated if they should be mandatory.valueornamemanually based on the usage.Checklist
LICENSE
THIS SOFTWARE IS CONTRIBUTED SUBJECT TO THE TERMS OF THE MODERNE SOURCE AVAILABLE LICENSE. YOU MAY OBTAIN A COPY OF THE LICENSE AT https://github.com/openrewrite/rewrite-spring/blob/main/LICENSE/moderne-source-available-license.md.
THIS SOFTWARE IS LICENSED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY WARRANTY OF NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THIS SOFTWARE MAY BE REDISTRIBUTED TO OTHERS ONLY BY EFFECTIVELY USING THIS OR ANOTHER EQUIVALENT DISCLAIMER IN ADDITION TO ANY OTHER REQUIRED LICENSE TERMS.