Search in sources :

Example 1 with URLRewriteMediatorFactory

use of org.apache.synapse.config.xml.URLRewriteMediatorFactory in project wso2-synapse by wso2.

the class URLRewriteMediatorTest method testFullRewriteScenario1.

public void testFullRewriteScenario1() throws Exception {
    String xml = "<rewrite xmlns=\"http://ws.apache.org/ns/synapse\">\n" + "    <rewriterule>\n" + "        <condition>\n" + "            <and>\n" + "                <equal type=\"url\" source=\"protocol\" value=\"http\"/>\n" + "                <equal type=\"url\" source=\"host\" value=\"test.org\"/>\n" + "            </and>\n" + "        </condition>\n" + "        <action value=\"https\" fragment=\"protocol\"/>\n" + "        <action value=\"test.com\" fragment=\"host\"/>\n" + "        <action value=\"9443\" fragment=\"port\"/>\n" + "    </rewriterule>\n" + "    <rewriterule>\n" + "        <condition>\n" + "            <not>\n" + "                <match type=\"url\" source=\"path\" regex=\"/services/.*\"/>\n" + "            </not>\n" + "        </condition>\n" + "        <action value=\"/services\" type=\"prepend\" fragment=\"path\"/>\n" + "    </rewriterule>\n" + "    <rewriterule>\n" + "        <condition>\n" + "            <and>\n" + "               <match type=\"url\" source=\"path\" regex=\".*/MyService\"/>\n" + "               <equal type=\"property\" source=\"prop1\" value=\"value1\"/>\n" + "            </and>\n" + "        </condition>        \n" + "        <action fragment=\"path\" value=\"StockQuoteService\" regex=\"MyService\" type=\"replace\"/>\n" + "        <action fragment=\"ref\" value=\"id\"/>\n" + "    </rewriterule>\n" + "</rewrite>";
    OMElement element = AXIOMUtil.stringToOM(xml);
    URLRewriteMediator mediator = (URLRewriteMediator) new URLRewriteMediatorFactory().createMediator(element, new Properties());
    MessageContext msgCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>");
    msgCtx.setTo(new EndpointReference("http://test.org:9763/MyService"));
    msgCtx.setProperty("prop1", "value1");
    mediator.mediate(msgCtx);
    assertEquals("https://test.com:9443/services/StockQuoteService#id", msgCtx.getTo().getAddress());
}
Also used : OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.synapse.MessageContext) URLRewriteMediatorFactory(org.apache.synapse.config.xml.URLRewriteMediatorFactory) Properties(java.util.Properties) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Aggregations

Properties (java.util.Properties)1 OMElement (org.apache.axiom.om.OMElement)1 EndpointReference (org.apache.axis2.addressing.EndpointReference)1 MessageContext (org.apache.synapse.MessageContext)1 URLRewriteMediatorFactory (org.apache.synapse.config.xml.URLRewriteMediatorFactory)1