Merge branch 'master' into eureka

eureka
tanghc 3 years ago
commit 890e7c3cce
  1. 6
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ApiArgumentResolver.java
  2. 9
      sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/Example1001_BaseController.java
  3. 18
      sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java

@ -51,6 +51,7 @@ import java.util.concurrent.ConcurrentHashMap;
@Slf4j
public class ApiArgumentResolver implements SopHandlerMethodArgumentResolver {
private static final String HAS_INIT_OPEN_CONTEXT = "hasInitOpenContext";
private final Map<MethodParameter, HandlerMethodArgumentResolver> argumentResolverCache = new ConcurrentHashMap<>(256);
private static List<MethodParameter> NEED_INIT_OPEN_CONTEXT = new ArrayList<>(16);
@ -163,10 +164,15 @@ public class ApiArgumentResolver implements SopHandlerMethodArgumentResolver {
private OpenContextImpl initOpenContextImpl(NativeWebRequest nativeWebRequest) {
HttpServletRequest request = (HttpServletRequest) nativeWebRequest.getNativeRequest();
Object hasInit = request.getAttribute(HAS_INIT_OPEN_CONTEXT);
if (hasInit != null) {
return (OpenContextImpl) ServiceContext.getCurrentContext().getOpenContext();
}
ServiceContext currentContext = ServiceContext.getCurrentContext();
JSONObject requestParams = OpenUtil.getRequestParams(request);
OpenContextImpl openContext = new OpenContextImpl(requestParams);
currentContext.setOpenContext(openContext);
request.setAttribute(HAS_INIT_OPEN_CONTEXT, true);
return openContext;
}

@ -35,6 +35,7 @@ import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@ -136,6 +137,14 @@ public class Example1001_BaseController {
@Open("story.system.param.get4")
@RequestMapping("/get/system/param/v4")
public Object addGoods3(HttpServletRequest request, StoryParam param) {
param.setRemark(request.getRequestURI());
return param;
}
@Open("story.system.param.get5")
@RequestMapping("/get/system/param/v5")
public Object get5(HttpServletRequest request, HttpServletResponse response, StoryParam param) {
param.setRemark(request.getRequestURI() + ", getCharacterEncoding:" + response.getCharacterEncoding());
return param;
}

@ -422,6 +422,24 @@ public class AllInOneTest extends TestBase {
client.execute(requestBuilder);
}
public void testParamBind2() {
Client.RequestBuilder requestBuilder = new Client.RequestBuilder()
.method("story.system.param.get5")
.version("1.0")
.bizContent(new BizContent().add("id", "1").add("name", "葫芦娃"))
.postJson(true)
.httpMethod(HttpTool.HTTPMethod.POST)
.callback((requestInfo, responseData) -> {
System.out.println(responseData);
String node = requestInfo.getDataNode();
JSONObject jsonObject = JSON.parseObject(responseData).getJSONObject(node);
Assert.assertEquals(1L, jsonObject.getLongValue("id"));
Assert.assertEquals("葫芦娃", jsonObject.getString("name"));
});
client.execute(requestBuilder);
}
/**
* 未知异常
*/

Loading…
Cancel
Save