我创建的自定义路由器与一个端点。定制路由器查找基于入站网址的URL参数端点的目的地。我有这样的启动和运行的一个例子,我在浏览器中进行测试它。我试图解决最后一件事与此有关。 //本地主机:当我使用 HTTP使在浏览器中调用8787 /我的站点中,调用使重定向并在浏览器更改 http://server2.xyz.com的网址: 8080 /我的站点。我不希望用户看到过 http://server2.xyz.com:8080/我的现场。我希望用户随时查看的http://本地主机:8787 /我的站点。我怎样才能做到这一点?我使用的骡子2.2.1社区版与Java 1.6。

下面是我Mule配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:spring="http://www.springframework.org/schema/beans"
    xmlns:http="http://www.mulesource.org/schema/mule/http/2.2"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
        http://www.mulesource.org/schema/mule/http/2.2 http://www.mulesource.org/schema/mule/http/2.2/mule-http.xsd">

    <model name="ProxyService">
        <service name="HttpProxyService">
            <inbound>
                <http:inbound-endpoint address="http://localhost:8787" synchronous="true"/>
            </inbound>
            <outbound>
                <custom-outbound-router class="com.abc.xyz.routing.LookupOutboundRouter">
                    <outbound-endpoint name="custom" address="http://nonexistant.server.com:8080" synchronous="true"/>
                </custom-outbound-router>
            </outbound>
        </service>
    </model>
</mule>

下面是我的自定义路由器:

public class LookupOutboundRouter extends AbstractOutboundRouter {
 Logger logger = Logger.getLogger(LookupOutboundRouter.class);

 @Override
 public boolean isMatch(MuleMessage message) throws MessagingException {
  return true;
 }

 @Override
 public MuleMessage route(MuleMessage message, MuleSession session) throws MessagingException {
  String[] urlValues = StringUtils.split(message.getProperty("http.request").toString(), "/");

  String newUri = lookupServiceUri(urlValues[0]) + urlValues[1];
  logger.info("newUri=" + newUri);

  DynamicURIOutboundEndpoint ep;

  try {
   ep = new DynamicURIOutboundEndpoint((OutboundEndpoint) getEndpoints().get(0), new MuleEndpointURI(newUri));

   MuleMessage message2 = send(session, message, ep);

   return message2;
  } catch (EndpointException e1) {
   e1.printStackTrace();
  } catch (MuleException e) {
   e.printStackTrace();
  }

  return null;
 }

 /**
  * This will call the service registry.
  * @param id
  * @return
  */
 private String lookupServiceUri(String id) {
  if(id.equalsIgnoreCase("12345")) {
   return "http://server.xyz.com:8080/";
  } else {
   return "http://server2.xyz.com:8080/";
  }
 }
}
有帮助吗?

解决方案

我能够由HTTP连接器上followRedirects设置为true在浏览器中实现这一点。与此唯一的问题是现在,它并没有为POST重定向工作。我正在从一个了SoapUI SOAP调用,而不是现在使用的浏览器。

Entity enclosing requests cannot be redirected without user intervention

Message               : Failed to route event via endpoint: org.mule.endpoint.DynamicURIOutboundEndpoint@fd285ee0. Message payload is of type: PostMethod
Type                  : org.mule.api.transport.DispatchException
Code                  : MULE_ERROR-42999
Payload               : org.apache.commons.httpclient.methods.PostMethod@9fa8f
JavaDoc               : http://www.mulesource.org/docs/site/current2/apidocs/org/mule/api/transport/DispatchException.html
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top