From 9ea56260745a09b4b8845bc822ab9cc6ec84490c Mon Sep 17 00:00:00 2001 From: tanghc Date: Thu, 15 Oct 2020 20:16:24 +0800 Subject: [PATCH] 4.0.3 --- .../controller/Example1001_BaseController.java | 17 ++++++++++++++++- .../java/com/gitee/sop/test/AllInOneTest.java | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/Example1001_BaseController.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/Example1001_BaseController.java index 42747c1e..7e70af33 100644 --- a/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/Example1001_BaseController.java +++ b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/Example1001_BaseController.java @@ -22,9 +22,11 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import javax.servlet.http.HttpServletRequest; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; @@ -135,6 +137,19 @@ public class Example1001_BaseController { return testResult; } + // 获取header + @Open(value = "test.head",version = "1.0") + @GetMapping("/get/header/v1") + public StoryResult header(@RequestBody StoryParam story, HttpServletRequest request) { + HttpServletRequest servletRequest = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + StoryResult storyResult = new StoryResult(); + storyResult.setId(1L); + storyResult.setName(story.getName() + + ", token1:" + request.getHeader("token") + + ", token2:" + servletRequest.getHeader("token")); + return storyResult; + } + // 返回数组结果 @ApiOperation(value = "返回数组结果(第二)", notes = "返回数组结果", position = -99) @Open("story.list") diff --git a/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java b/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java index 266ee47e..78e9a3d3 100644 --- a/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java +++ b/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java @@ -218,6 +218,22 @@ public class AllInOneTest extends TestBase { client.execute(requestBuilder); } + /** + * 传递header + */ + public void testHeader() { + Map header = new HashMap<>(8); + header.put("token", "aaaabbbb"); + Client.RequestBuilder requestBuilder = new Client.RequestBuilder() + .method("test.head") + .version("1.0") + .header(header) + .bizContent(new BizContent().add("id", "1").add("name", "葫芦娃")) + .httpMethod(HttpTool.HTTPMethod.GET); + + client.execute(requestBuilder); + } + /** * 测试post提交大文本内容 * @throws IOException