Home > Blockchain >  Redirect link in Mule 4
Redirect link in Mule 4

Time:12-08

I have to create an endpoint and when it is called, it redirects me to a specific web page, how can I do this?

I investigated about the HTTP Response Builder, but it tells me that it is "Deprecated" and when I add it in the XML, Mule does not recognize it.

CodePudding user response:

Just instruct the HTTP Listener to return a 302 status and a header Location with the new URL. That's how an HTTP redirection works.

Example:

<http:listener doc:name="Listener"config-ref="HTTP_Listener_config" path="/redirectme">
    <http:response statusCode="302">
        <http:headers ><![CDATA[
            output application/java
            ---
            {
                "Location" : "http://somehost.com/some/other/url"
            }
            ]]>
        </http:headers>
    </http:response>
</http:listener>

If you need to make it dynamic just replace by variables in the expressions and set the variables inside of the flow.

Example:

    <http:response statusCode="#[vars.httpStatus default 200]">
...
            {
                "Location" : vars.someURL
            }

  • Related