支持的,我写了一个测试例,你可以参考下:
public class TestRequest extends AbstractRopRequest { @Valid private Map<String, String> params; public Map<String, String> getParams() { return params; } public void setParams(Map<String, String> params) { this.params = params; } }
public class TestService { public static final String APP_KEY = "c339f406cc4fcd247ebebd8c2ef04961"; public static final String APP_SECRET = "e087854ec655c113a8046cd4a208f3f7"; public static final String SERVER_URL = "http://127.0.0.1:8080/router"; /** * testSearch(测试用例) * @Exception 异常对象 */ @org.junit.Test public void testSearch() throws Exception { RestTemplate restTemplate = new RestTemplate(); MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>(); form.add("method", "dfire.test.search"); form.add("appKey", APP_KEY); form.add("v", "1.0"); form.add("locale", "zh_CN"); form.add("timestamp", String.valueOf(System.currentTimeMillis())); TestRequest test = new TestRequest(); Map<String,String> params = new HashMap<>(); params.put("name","maodou"); test.setParams(params); form.add("test", JsonUtil.beanToJson(test)); //对请求参数列表进行签名 String sign = RopUtils.sign(form.toSingleValueMap(), APP_SECRET); form.add("sign", sign); String response = restTemplate.postForObject(SERVER_URL, form, String.class); System.out.println("response:\n" + response); } }
/** * @author maodou * @version 1.0 */ @ServiceMethodBean public interface TestService { /** * testSearch 测试用例 * @param request 参数描述 * @return Boolean 返回值描述 * @Exception 异常对象 */ @ServiceMethod(method = "dfire.test.search", needInSession = NeedInSessionType.NO, version = "1.0", httpAction = HttpAction.POST) Result<Boolean> testSearch(TestRequest request); }
/** * @author "maodou" * @version 1.0 */ @ServiceMethodBean(version = "1.0") public class TestServiceImpl implements TestService { @Override public Result<Boolean> testSearch(TestRequest request) { Result<Boolean> result = new ResultSupport<>(); try { RopRequestContext requestContext = request.getRopRequestContext(); String json = requestContext.getParamValue("test"); System.out.println(json); } catch (BizException e) { return new ResultSupport(e.getCode(), e.getMessage()); } return result; } }
返回参数:{"ropRequestContext":null,"params":{"name":"maodou"}}