You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by pe...@apache.org on 2022/02/24 10:37:09 UTC

[incubator-linkis-website] branch dev updated: add springmvc-replaces-jersey.md

This is an automated email from the ASF dual-hosted git repository.

peacewong pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-linkis-website.git


The following commit(s) were added to refs/heads/dev by this push:
     new 90b8632  add springmvc-replaces-jersey.md
     new 635e205  Merge pull request #173 from casionone/dev
90b8632 is described below

commit 90b8632400a09a904693af72fa2dda33a9f9e5ce
Author: casionone <ca...@gmail.com>
AuthorDate: Thu Feb 24 17:31:24 2022 +0800

    add springmvc-replaces-jersey.md
---
 .../development/springmvc-replaces-jersey.md       | 63 ++++++++++++++++++++++
 .../development/springmvc-replaces-jersey.md       | 62 +++++++++++++++++++++
 2 files changed, 125 insertions(+)

diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-1.0.3/development/springmvc-replaces-jersey.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-1.0.3/development/springmvc-replaces-jersey.md
new file mode 100644
index 0000000..f308a3e
--- /dev/null
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-1.0.3/development/springmvc-replaces-jersey.md
@@ -0,0 +1,63 @@
+---
+title: SpringMVC 替换 Jersey分享
+sidebar_position: 5
+---
+> 本文主要介绍 linkis-1.0.3 版本,如何使用Spring REST对jersey REST模式的替换,在1.0.3版本之前。linkis提供的REST Web服务是使用的jersey架构,考虑到Linkis本身是基于Spring开发的项目,能更轻松的集成Spring REST模式,同时也更符合linkis社区开发者使用的主流技术。
+
+
+## Servlet 的调整
+
+linkis在1.0.3之前,DataWorkCloudApplication启动类在创建JettyServletWebServerFactory的Web容器时,使用的是jersey的ServletContainer。
+在1.0.3替换为了Spring的DispatcherServlet。如果有基于linkis二次开发的其他组件,有依赖了DataWorkCloudApplication启动类,那么原来jersey模式的http服务无法直接使用。
+
+## 请求返回的结构体调整
+- Jersey :http请求返回实体:javax.ws.rs.core.Response为jersey模式http返回实体,jersey内部有做单独的处理,封装为了Response
+
+- Spingmvc模式需要修改,直接返回Message
+
+```java
+  return Message.messageToResponse(Message.ok().data("test", data));
+=>
+  return Message.ok().data("test", data)
+```
+
+
+## jackson升级替换 
+
+- org.codehaus.jackson 从v2版本时已经从 codehaus 移交到github 并重命名为com.fasterxml.jackson
+- jersey老版本使用的是org.codehaus.jackson,springmvc使用的是新版本的com.fasterxml.jackson,替换为springmvc风格时,需要升级jackson
+
+
+## 注解对比
+
+
+|  jersey注解| springmvc注解 | 备注 |
+| --- | --- | --- |
+|  @GET |   @RequestMapping(method = RequestMethod.GET)|  |
+|  @POST| @RequestMapping(method = RequestMethod.POST) |  |
+|  @DELETE| @RequestMapping(method = RequestMethod.DELETE) |  |
+|  @PUT| @RequestMapping(method = RequestMethod.PUT) |  |
+| @Path("/dss") | @RequestMapping(path = "/dss) |  |
+|  @FormDataParam("system") String system | @RequestParam(value ="system",required = false)|request为false|
+ |  @QueryParam("system") String system |@RequestParam(value ="system",required = false)|request为false|
+|  @PathParam("id") Long id|@PathVariable("id") Long id |  |
+| FormDataMultiPart form  |@RequestParam("file") List\<MultipartFile\> files  | 默认参数名为file,用法需要修改 |
+|@Context  |  直接删除|  |
+|  @DefaultValue("1000") @QueryParam("pageSize") int pageSize, |   @RequestParam(value = "pageSize",defaultValue = "1000")|  |
+|@Consumes(MediaType.APPLICATION_JSON)| @RequestMapping(consumes = {"application/json"})||
+|@Produces(MediaType.APPLICATION_JSON)|@RequestMapping(produces = {"application/json"})| |
+|参数 org.codehaus.jackson.JsonNode|@RequestBody com.fasterxml.jackson.databind.JsonNode jsonNode|jersey老版本使用的是老版本的jackson,springmvc使用的是新版本的JsonNode/
+
+
+## Jackson升级主要替换点
+
+```shell script
+
+jackson-1.X 方法: getBooleanValue()、getFields()、getElements()、getIntValue()
+jackson-2.X 方法: booleanValue()、fields()、elements() 和 intValue()
+
+```
+
+详细可参考:
+- https://stackoverflow.com/questions/55896802/upgrade-of-jackson-from-org-codehaus-jackson-to-com-fasterxml-jackson-version-1
+- http://www.cowtowncoder.com/blog/archives/2012/04/entry_469.html
\ No newline at end of file
diff --git a/versioned_docs/version-1.0.3/development/springmvc-replaces-jersey.md b/versioned_docs/version-1.0.3/development/springmvc-replaces-jersey.md
new file mode 100644
index 0000000..73d5f64
--- /dev/null
+++ b/versioned_docs/version-1.0.3/development/springmvc-replaces-jersey.md
@@ -0,0 +1,62 @@
+---
+title: SpringMVC Replaces Jersey 
+sidebar_position: 5
+---
+> This article mainly introduces linkis-1.0.3 version, how to use Spring REST to replace jersey REST mode, before version 1.0.3. The REST Web service provided by linkis uses the Jersey Architecture. Considering that Linkis itself is a project developed based on Spring, it can integrate the Spring REST mode more easily, and it is also more in line with the mainstream technologies used by developers in the linkis community.
+
+
+## Servlet Adjustment
+
+linkis Before 1.0.3, the DataWorkCloudApplication startup class used jersey's ServletContainer when creating the web container of JettyServletWebServerFactory.
+Replaced by Spring's DispatcherServlet in 1.0.3. If there are other components based on the secondary development of linkis, and some rely on the DataWorkCloudApplication startup class, then the http service in the original jersey mode cannot be used directly.
+
+## Request Returned Structure Adjustment
+- Jersey: http request returns entity: javax.ws.rs.core.Response is the jersey mode http return entity, which is processed separately in jersey and encapsulated as Response
+
+- The Spingmvc mode needs to be modified and returns directly to Message
+
+````java
+  return Message.messageToResponse(Message.ok().data("test", data));
+=>
+  return Message.ok().data("test", data)
+````
+
+
+## Jackson Upgrade Replacement
+
+- org.codehaus.jackson has been moved from codehaus to github since v2 and renamed to com.fasterxml.jackson
+- The old version of jersey uses org.codehaus.jackson, and springmvc uses the new version of com.fasterxml.jackson. When replacing with springmvc style, you need to upgrade jackson
+
+
+## Annotation Comparison
+
+
+| jersey annotations | springmvc annotations | remarks |
+| --- | --- | --- |
+| @GET | @RequestMapping(method = RequestMethod.GET) | |
+| @POST| @RequestMapping(method = RequestMethod.POST) | |
+| @DELETE| @RequestMapping(method = RequestMethod.DELETE) | |
+| @PUT| @RequestMapping(method = RequestMethod.PUT) | |
+| @Path("/dss") | @RequestMapping(path = "/dss) | |
+| @FormDataParam("system") String system | @RequestParam(value = "system",required = false)|request is false|
+| @QueryParam("system") String system |@RequestParam(value = "system",required = false)|request is false|
+| @PathParam("id") Long id|@PathVariable("id") Long id | |
+| FormDataMultiPart form |@RequestParam("file") List\<MultipartFile\> files | The default parameter name is file, the usage needs to be modified |
+|@Context | Delete directly | |
+| @DefaultValue("1000") @QueryParam("pageSize") int pageSize, | @RequestParam(value = "pageSize",defaultValue = "1000")| |
+|@Consumes(MediaType.APPLICATION_JSON)| @RequestMapping(consumes = {"application/json"})||
+|@Produces(MediaType.APPLICATION_JSON)|@RequestMapping(produces = {"application/json"})| |
+|Parameter org.codehaus.jackson.JsonNode|@RequestBody com.fasterxml.jackson.databind.JsonNode jsonNode|The old version of jersey uses the old version of jackson, and springmvc uses the new version of JsonNode
+
+
+## Jackson Main Replacement Point
+
+```
+jackson-1.X methods: getBooleanValue(), getFields(), getElements(), getIntValue()
+jackson-2.X methods: booleanValue(), fields(), elements() and intValue()
+
+```
+
+For details, please refer to
+- https://stackoverflow.com/questions/55896802/upgrade-of-jackson-from-org-codehaus-jackson-to-com-fasterxml-jackson-version-1
+- http://www.cowtowncoder.com/blog/archives/2012/04/entry_469.html

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org