DataWeave Tip #8: The write Function

Originally published February 26, 2019

Recently I have been working on a really simple case. When an HTTP server returned an error and a non-empty body, I needed to embed this body into an error structure. Although this is a simple case, I got a problem with implementing it in Mule 4. In the previous Mule edition, it was a little bit simpler. So let's see what it is all about.

Case

First, we have a look at the case that I have to implement. I have a mule application that is calling an external HTTP server via an HTTP request component. When the server responds with an error like 4xx, 5xx, and the returned body will is not empty, we would like to forward that response to the calling application.

HTTP Forwarded and X-Forwarded-* Header Support: Dev Build Update

HTTP Forwarded and X-Forwarded-* header support means that programmers and applications can obtain the original client endpoint information presented by a proxy or a load balancer using the Forwarded or X-Forwarded-* headers instead of the current TCP connected endpoint. This information can be retrieved using certain Servlet API calls or the NCSA Access Log.

You can use the Forwarded and X-Forwarded-* headers by configuring a new element in the server.xml. Optionally, you can provide a regular expression that declares the internal/trusted proxy servers. In addition, you can optionally configure a Boolean type attribute that, if the HTTP Channel has verified the specific remote client information, the NCSA Access Log reflects the Forwarded and X-Forwarded-* headers when recording the remote IP, host, and/or the request protocol.