使用groovy表达式在骡子有限的IP [英] Use groovy expression for limited IP in mule
问题描述
我用骡子的cxf创建了一个代理服务。我的骡子版本是3.3.0 CE。现在,我想在我的wsdl中使用代理服务创建一个限制。
我的限制不应该允许每个IP,他们看到我的WSDL。
,我发现Groovy表达式和下面的代码:
< expression-filter
expression = #{groovy:'$ {allowed}'。contains(message.getInboundProperty('MULE_REMOTE_CLIENT_ADDRESS')。substring(message.getInboundProperty('MULE_REMOTE_CLIENT_ADDRESS')。indexOf('/')+ 1,message.getInboundProperty('MULE_REMOTE_CLIENT_ADDRESS' ).indexOf(':')))]
doc:name =Expression/>
我不知道好的代码还是不行?
,我不知道应该在哪里定义我的有效Ip?解决方案
这个方法是有效的。
只建议我会做的是提取IP解析到一个全球性的功能重用性和更好的可读性:
<< ;结构>
< expression-language>
< global-functions>
def parseIp(fullIp){
return fullIp.substring(fullIp.indexOf('/')+ 1,fullIp.indexOf(':'))
}
< /全局函数>
< / expression-language>
< / configuration>
然后你可以这样使用它:
< $ p $ b $> $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' name =Expression/>
I created a proxy service with cxf in mule. My version of mule is 3.3.0 CE. Now, I want to put a restriction in my wsdl that created with proxy service. My restriction shouldn't allow to per IP that they see my wsdl. for this, I find Groovy expression and bellow code:
<expression-filter
expression="#[groovy:'${allowed}'.contains(message.getInboundProperty('MULE_REMOTE_CLIENT_ADDRESS').substring(message.getInboundProperty('MULE_REMOTE_CLIENT_ADDRESS').indexOf('/')+1, message.getInboundProperty('MULE_REMOTE_CLIENT_ADDRESS').indexOf(':')))]"
doc:name="Expression" />
I don't know Is good code Or no? and I don't know where do I should define my valid Ip?
That approach is valid. Only suggest I would do is to extract the IP parsing to a global function for reusability and better readability:
<configuration>
<expression-language>
<global-functions>
def parseIp(fullIp) {
return fullIp.substring(fullIp.indexOf('/') + 1, fullIp.indexOf(':'))
}
</global-functions>
</expression-language>
</configuration>
Then you can use it as follows:
<expression-filter expression="#['${allowed}'.contains(parseIp(message.inboundProperties['MULE_REMOTE_CLIENT_ADDRESS']))]"
doc:name="Expression" />
这篇关于使用groovy表达式在骡子有限的IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!