venusdrogon / feilong-platform

:gem:all feilong projects's parent
http://feitianbenyue.iteye.com/
Apache License 2.0
94 stars 58 forks source link

支持将请求参数放在路径中的配置 #233

Closed ijiangtao closed 6 years ago

ijiangtao commented 6 years ago

例如:

接口 PUT v1/transactions/28173035/43399596-0a70817e-943e-11e8-98f1-378370ca0da4/compelte, 作用是将指定订单的状态改为完成。 配置为: method=PUT uri= v1/transactions/{transactionId}/compelte

接口 GET v1/transactions/28173035/43399596-0a70817e-943e-11e8-98f1-378370ca0da4, 作用是获取指定的订单信息。 配置为: method=GET uri= v1/transactions/{transactionId}

image

ijiangtao commented 6 years ago

v1/transactions/{transactionId}/compelte ,可以参考tiles配置文件的实现方式:

通过“{数字}”的方式动态获取。

venusdrogon commented 6 years ago

配置


<property name="httpTypeBeanProperty">
        <bean class="com.feilong.context.beanproperty.SimpleHttpTypeBeanProperty" 
p:uri="http://hubforeign-test.mapemall.com/toms/inter/tryCaculateForOrder/${routingRequest.routingConstants.routingSecret}"    
p:method="post" />
</property>

结果 :


17:24:10 DEBUG (DefaultHttpRequestBuilder.java:132) buildHttpRequestUri() - parse uri:[http://hubforeign-test.mapemall.com/toms/inter/tryCaculateForOrder/${routingRequest.routingConstants.routingSecret}],use map:[{"routingRequest": "com.**.store.order.RoutingRequest@2c177f9e"}],result:[http://hubforeign-test.mapemall.com/toms/inter/tryCaculateForOrder/xhf6Z6I3JePpm8pgYa5m6w==]

url 参数 变量规则:

使用的是 对应request 类型, 首字母小写, 然后 . 取里面的属性

底层目前使用velocity 模板来解析, 将来可能会支持 OGNL/MVEL

image

ijiangtao commented 6 years ago

如果路径中包含非ASCII字符,不会转义,从而造成请求出错。

例如: https://test.example.com/a 中文 c

建议增加自动转义功能。

例如:

/**
 * <p>
 * 将Hppt请求的URI的 Path内容部分(不包含protocol和host以及/) 转码为 ASCII String
 * </p>
 * <br>
 * <p>
 * exampe:<br>
 * URIUtils.pathContentToASCIIString("g h 【 中文 】");
 * <br>
 * 返回:<br>
 * g%20h%20%E3%80%90%20%E4%B8%AD%E6%96%87%20%E3%80%91<br>
 * </p>
 * 
 * @param path
 * @return
 * @throws URISyntaxException
 */
public static String pathContentToASCIIString(String uriPath) throws URISyntaxException{

    String scheme = "https";
    String host = "vadvdavddfmadlovbnsdaye.adfmadddcsefgrfcvg.ppamsasaaaff";
    String path = "/" + uriPath;

    URI uri = new URI(scheme, host, path, null);

    String regex = scheme + "://" + host + "/";

    return uri.toASCIIString().replaceFirst(regex, "");
}

[a 中文 c] 转义为 [a%20%E4%B8%AD%E6%96%87%20c]

venusdrogon commented 6 years ago

新增一个 issue

see 增加自动转义-请求参数放在路径中的配置 #257