我是 Mule 的新手,我想验证来自 URI 的时间戳和 nonce 参数以防止重放攻击。我使用choice-when路由器,当时间戳和nonce有效(验证过程复杂)时,将请求转发到后端rest服务,否则返回错误代码和消息。我发现很多 MEL 用法用于选择时,但是我可以使用 java 定义自定义表达式吗?有一个例子吗?URI 示例:
http://muledemo.org/ci2/ni/del?id=0xe413×tamp=1376022133&nonce=a03ed9c
代码片段:
<choice doc:name="Choice">
<when expression="???how to call a java validator???">
</when>
<otherwise>
<processor-chain doc:name="Processor Chain">
<echo-component doc:name="Echo" />
<http:outbound-endpoint exchange-pattern="request-response" method="POST"
address="http://localhost:8081#[message.inboundProperties['http.request']]" doc:name="HTTP" />
</processor-chain>
</otherwise>
</choice>
编辑:
XML配置:
<spring:beans>
<spring:bean id="replayAttackCheck" class="org.jamee.demo.mule.ReplayAttackCheck"/>
</spring:beans>
... ...
<when expression="#[replayAttackCheck.validate(payload)]">
<expression-component doc:name="Check Required Params"><![CDATA[payload="{\"code\":\"PA002\", \"message\":\"timestamp or nonce is illegal\"}"]]>
</expression-component>
</when>
错误日志:
ERROR 2013-08-09 14:32:39,090 [[demo.router].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Execution of the expression "replayAttackCheck.validate(payload)" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: HashMap
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. [Error: unresolvable property or identifier: replayAttackCheck]
[Near : {... replayAttackCheck.validate(pay ....}]