pull/3/head
tanghc 4 years ago
parent 65342b54ee
commit 9ea5626074
  1. 17
      sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/Example1001_BaseController.java
  2. 16
      sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.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")

@ -218,6 +218,22 @@ public class AllInOneTest extends TestBase {
client.execute(requestBuilder);
}
/**
* 传递header
*/
public void testHeader() {
Map<String, String> 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

Loading…
Cancel
Save