I created a custom router with one endpoint. The user router views the destination of the endpoint based on the URL parameters of the incoming URL. I have an example of this and it works, and I am testing it in a browser. I am trying to solve one last thing with this. When I make a call in the browser using http: // localhost: 8787 / my-site , the call redirects and the browser URL changes to http://server2.xyz.com:8080/my-site . I do not want the user to ever see http://server2.xyz.com:8080/my-site . I want the user to always see http: // localhost: 8787 / my-site . How can i achieve this? I am using the community version of Mule 2.2.1 with Java 1.6.
Here is my Mule configuration file:
<?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;
}
private String lookupServiceUri(String id) {
if(id.equalsIgnoreCase("12345")) {
return "http://server.xyz.com:8080/";
} else {
return "http://server2.xyz.com:8080/";
}
}
}