DynamicCurioutBoundEndpoint在Mule 3中运行时未拾取newUri
DynamicCurioutBoundEndpoint在Mule 3中运行时未拾取newUri。我在下面粘贴了我的流和java代码片段以供参考。最初,我将一个出站端点添加到定制路由器,然后通过java代码尝试使用DynamicURIOutboundEndpoint动态更新出站端点的uri。但DynamicCurioutBoundEndpoint在运行时未使用newUri进行更新。我也尝试过扩展AbstractOutboundRouter来代替FilteringOutboundRouter,但结果仍然一样。我在网上看到过一些例子,其中DynamicOutboundEndpoint可以工作,但它可以与Mule2一起工作。有人能帮我和骡子3解决这个问题吗。我想使用DynamicURIOutboundEndpoint动态设置uriDynamicCurioutBoundEndpoint在Mule 3中运行时未拾取newUri,mule,Mule,DynamicCurioutBoundEndpoint在Mule 3中运行时未拾取newUri。我在下面粘贴了我的流和java代码片段以供参考。最初,我将一个出站端点添加到定制路由器,然后通过java代码尝试使用DynamicURIOutboundEndpoint动态更新出站端点的uri。但DynamicCurioutBoundEndpoint在运行时未使用newUri进行更新。我也尝试过扩展AbstractOutboundRouter来代替FilteringOutboundRouter,但结果
<flow name="DemoVipFlow1" doc:name="DemoVipFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP" path="rapp"/>
<logger level="INFO" doc:name="Logger" message="Stage1"/>
<custom-router class="com.vip.DynamicCustomRouter">
<outbound-endpoint address="http://doesnotexist:9999"/>
</custom-router>
</flow>
package com.tivo.vip;
import org.mule.api.MuleEvent;
import org.mule.api.MuleException;
import org.mule.api.MuleMessage;
import org.mule.api.endpoint.EndpointURI;
import org.mule.api.endpoint.OutboundEndpoint;
import org.mule.api.processor.MessageProcessor;
import org.mule.api.routing.CouldNotRouteOutboundMessageException;
import org.mule.api.routing.RoutePathNotFoundException;
import org.mule.api.routing.RoutingException;
import org.mule.config.i18n.CoreMessages;
import org.mule.endpoint.DynamicURIOutboundEndpoint;
import org.mule.endpoint.MuleEndpointURI;
import org.mule.routing.outbound.FilteringOutboundRouter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DynamicCustomRouter extends FilteringOutboundRouter {
@Override
public MuleEvent route(MuleEvent event) throws RoutingException {
MuleMessage message = event.getMessage();
MuleEvent result;
if (routes == null || routes.size() == 0) {
throw new RoutePathNotFoundException(
CoreMessages.noEndpointsForRouter(), event, null);
}
try {
MessageProcessor ep = routes.get(0);
EndpointURI newUri;
if (ep instanceof OutboundEndpoint) {
newUri = new MuleEndpointURI(
"http://${ipAddress}:8899/jolokia/list", muleContext);
ep = new DynamicURIOutboundEndpoint((OutboundEndpoint) ep,
newUri);
}
result = sendRequest(event, message, ep, true);
} catch (MuleException e) {
throw new CouldNotRouteOutboundMessageException(event,
routes.get(0), e);
}
return result;
}
}
包com.tivo.vip;
导入org.mule.api.MuleEvent;
导入org.mule.api.muleeexception;
导入org.mule.api.MuleMessage;
导入org.mule.api.endpoint.EndpointURI;
导入org.mule.api.endpoint.OutboundEndpoint;
导入org.mule.api.processor.MessageProcessor;
导入org.mule.api.routing.CouldNotRouteOutboundMessageException;
导入org.mule.api.routing.RoutePathNotFoundException;
导入org.mule.api.routing.RoutingException;
导入org.mule.config.i18n.core消息;
导入org.mule.endpoint.DynamicURIOutboundEndpoint;
导入org.mule.endpoint.MuleEndpointURI;
导入org.mule.routing.outbound.FilteringOutboundRouter;
导入org.slf4j.Logger;
导入org.slf4j.LoggerFactory;
公共类DynamicCustomRouter扩展了FilteringOutboundRouter{
@凌驾
公共多事件路由(多事件事件)引发RoutingException{
MuleMessage message=event.getMessage();
多重结果;
if(routes==null | | routes.size()==0){
抛出新RoutePathNotFoundException(
CoreMessages.noEndPointsErrorOuter(),事件,null);
}
试一试{
MessageProcessor ep=routes.get(0);
endpointurinewuri;
if(外部边界端点的ep实例){
newUri=新的MuleEndpointURI(
“http://${ipAddress}:8899/jolokia/list”,muleContext);
ep=新的DynamicURIOutboundEndpoint((OutboundEndpoint)ep,
纽乌里);
}
结果=发送请求(事件、消息、ep、真);
}捕获(多个例外){
抛出新的CouldNotRouteOutboundMessageException(事件,
路线。获取(0),e);
}
返回结果;
}
}
如果您只想发送到一个动态URL,那么您的方法就太复杂了。假设ipAddress
是可解析的全局属性,则以下操作有效:
<scripting:component>
<scripting:script engine="groovy">
muleContext.client.send('http://${ipAddress}:8899/jolokia/list',
eventContext.message)
</scripting:script>
</scripting:component>
send('http://${ipAddress}:8899/jolokia/list',
eventContext.message)
并且可以用来替换您的
自定义路由器
你好,大卫,谢谢您的回复。我可以得到上面的代码,你已经给工作。但请您澄清我的疑问:在Mule3中使用DynamicURIOutboundEndpoint是否存在缺陷。当我在JavaComponent中使用DynamicCurioutBoundEndpoint时,我无法在运行时动态更新uri。DynamicCurioutBoundEndpoint始终将请求发送到其defaultOtuboundendpoint(最初是静态设置的)。你能给我一个在Mule3中使用DynamicURIOutboundEndpoint动态更新uri的工作代码吗?嗨,David,我在脚本组件之前有一个http inboundendpoint(设置为请求-响应模式)(你已经在上面给出了)。在这种情况下,httpinboundendpoint不会直接将从client.send(…)收到的响应显示回调用方浏览器,这是一条mule消息。在将响应发送到httpinboundendpoint之前,是否需要对从client.send(…)收到的响应进行一些处理。属性占位符在配置加载时解析,而不是在运行时解析。因此,DynamicURIOutboundEndpoint
不可能解析${ipAddress}
。入站HTTP端点是否使用请求-响应
交换模式?如果是,请指定“响应不直接显示给呼叫方浏览器”的含义。您可能需要做的一件事是将脚本之后收到的相关入站属性(HTTP头、状态)复制到出站范围(使用copy property XML元素),以便初始调用方获得有效的HTTP响应。如果没有这些,它可以工作,但是你会从Jolokia的回复中丢失一些信息(标题)。嗨,David,谢谢你的回复。让我重新表述一下关于DynamicURIOutboundEndpoint的查询。假设我有以下代码(从顶部的初始查询中提取):