Skip to main content

#Vars.outboundHeaders Default {}0 discussing

I would like to create an endpoint for uploading files with different Media/Content-Types (csv,jpg,xlsx... etc).

 

preferably using 1 flow.

How do I change a header value in the attributs 

In my main flow I would like to store the original Content-Type Header value and then replace it with "application/*" so the APIkit will route it to the postfile flow.main flowBut I can't get it to work.

 

This is what I have so far:

 

<flow name="test-main">

<http:listener config-ref="test-httpListenerConfig" path="/*">

<http:response statusCode="#vars.httpStatus default 200">

<http:headers><![CDATA[#vars.outboundHeaders default {}]]></http:headers>

</http:response>

<http:error-response statusCode="#vars.httpStatus default 500">

<http:body><![CDATA[#payload]]></http:body>

<http:headers><![CDATA[#vars.outboundHeaders default {}]]></http:headers>

</http:error-response>

</http:listener>

<set-variable value='#attributes.headers."content-type"' doc:name="Save Content-Type" variableName="headerContentType"/>

<ee:transform doc:name="Override Content-Type" >

<ee:message >

<ee:set-attributes ><![CDATA[%dw 2.0

import * from dw::util::Values

---

if (lower(attributes.method) == "post"

and

lower(attributes.headers."content-type") != "application/json"

)

// A file is POSTed, force the content-type to the correct API Kit Route

attributes update ["headers", field("content-type")] with "application/*"

//as Object {

// class: "org.mule.extension.http.api.HttpRequestAttributes"

//}

else

attributes

]]></ee:set-attributes>

</ee:message>

</ee:transform>

<apikit:router config-ref="test-config" />

</flow>

 

This is my test application

 

In Mule 3 I did this with a custom-transformer and a Java class, but that doesn't work anymore in Mule 4.

 

I hope someone here can help me with this problem.

2 answers
  1. Jul 21, 2021, 3:10 PM

    I found a solution by building the whole attributes object from scratch

     

    <ee:transform doc:name="Override Content-Type">

    <ee:message >

    <ee:set-attributes ><![CDATA[%dw 2.0

    output application/java

    fun updAttr(headers) =

    headers update {

    case ."content-type" -> "application/*"

    }

    ---

    if (lower(attributes.method) == "post"

    and

    lower(attributes.headers."content-type") != "application/json"

    )

    {

    listenerPath: attributes.listenerPath,

    rawRequestPath: attributes.rawRequestPath,

    relativePath: attributes.relativePath,

    version: attributes.version,

    scheme: attributes.scheme,

    method: attributes.method,

    requestUri: attributes.requestUri,

    rawRequestUri: attributes.rawRequestUri,

    queryString: attributes.queryString,

    localAddress: attributes.localAddress,

    remoteAddress: attributes.remoteAddress,

    queryParams: attributes.queryParams,

    uriParams: attributes.uriParams,

    requestPath: attributes.requestPath,

    headers: updAttr(attributes.headers)

    }

    as Object {

    class: "org.mule.extension.http.api.HttpRequestAttributes"

    }

    else 

    attributes]]></ee:set-attributes>

    </ee:message>

    <ee:variables >

    </ee:variables>

    </ee:transform>

     

    I left out items:

    • maskedRequestPath (resulted in "Invalid property name: `maskedRequestPath` on class `org.mule.extension.http.api.HttpRequestAttributesBuilder`")
    • clientCertificate (resulted in "Errors while creating org.mule.runtime.api.util.SerializableLazyValue by reflection, even when class in on classpath")
0/9000

I tried to use <on-error ref="test-error-handler"/> to reference the error handling strategy in the Mule Application. I created new test application using Anypoint Studio v7.17 and I encountered that this element causes compilation errors. Has anyone also encountered such a problem and know how to resolve this?

 

<app.runtime>4.6.2</app.runtime>

<mule.maven.plugin.version>4.2.0</mule.maven.plugin.version>

 

Error Message:

[ERROR] Failed to execute goal org.mule.tools.maven:mule-maven-plugin:4.2.0:process-classes (default-process-classes) on project common-extend-test: Fail to compile: Cannot invoke "org.mule.runtime.ast.api.ComponentParameterAst.getRawValue()" because the return value of "org.mule.runtime.config.internal.validation.AbstractErrorValidation.getErrorTypeParam(org.mule.runtime.ast.api.ComponentAst)" is null -> [Help 1]

 

Configuration XML:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit="http://www.mulesoft.org/schema/mule/mule-apikit" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/mule-apikit http://www.mulesoft.org/schema/mule/mule-apikit/current/mule-apikit.xsd http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd ">

<flow name="test-raml-main">

<http:listener config-ref="test-raml-httpListenerConfig" path="/api/*">

<http:response statusCode="#vars.httpStatus default 200">

<http:headers>#vars.outboundHeaders default {}</http:headers>

</http:response>

<http:error-response statusCode="#vars.httpStatus default 500">

<http:body>#[payload]</http:body>

<http:headers>#vars.outboundHeaders default {}</http:headers>

</http:error-response>

</http:listener>

<apikit:router config-ref="test-raml-config" />

<error-handler >

<on-error ref="test-error-handler"/>

<on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" doc:id="4a2c18e6-d4a4-4659-afb3-0108f1074b3c" >

<logger level="INFO" doc:name="Logger" doc:id="318a7585-7926-4dc6-b76a-5ffe72f392b2" />

</on-error-continue>

</error-handler>

</flow>

<error-handler name="test-error-handler" doc:id="c849264d-d1d4-4a06-b3a0-3b4e3cbf1e35">

<on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" doc:id="19e4b41a-b088-4d78-b40a-b6370718e943" type="EXPRESSION">

<logger level="INFO" doc:name="Logger" doc:id="f8acc841-b047-44ac-88fc-cfbc0b33e40f" />

</on-error-continue>

</error-handler>

<flow name="get:\test:test-raml-config">

<logger level="INFO" message="get:\test:test-raml-config" />

</flow>

</mule>

5 answers
  1. Jun 11, 2024, 1:50 PM

    Hi ,

    It looks like there is a reference to a common error handler and another 'on error continue' statement present, which is causing the error. Please remove it.

     

    current inside main flow test-raml-main

    <on-error ref="test-error-handler"/>

    <on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" doc:id="4a2c18e6-d4a4-4659-afb3-0108f1074b3c" >

    <logger level="INFO" doc:name="Logger" doc:id="318a7585-7926-4dc6-b76a-5ffe72f392b2" />

     

    </on-error-continue>

    </error-handler>

     

    instead only have this

    <error-handler ref="test-error-handler" />

     

    Hi ,It looks like there is a reference to a common error handler and another 'on error continue' statement present, which is causing the error. Please remove it. 

0/9000

I'm having a problem with an integration once deployed, but it works locally. The structure of the integration looks like this

 

Database SAPI <-> PAPI <-> SFTP SAPI

 

The PAPI calls the Database SAPI and the Database SAPI calls a stored procedure and compresses the result. Then, the PAPI sends data to the SFTP SAPI, which writes the data to an SFTP file location.

 

Once I deploy, I'm getting this error in response from the SFTP SAPI midway through execution of the integration. Can anyone help me narrow my issue down?

 

HTTP response sending task failed with error: java.util.concurrent.TimeoutException

********************************************************************************

Message               : java.util.concurrent.TimeoutException

Element               : sftp-sapi-main/source @ sftp-sapi:interface.xml:4

Element DSL           : <http:listener config-ref="sftp-sapi-httpListenerConfig" path="/api/*">

<http:response statusCode="#vars.httpStatus default 200">

<http:headers><![CDATA[

#vars.outboundHeaders default {}

]]></http:headers>

</http:response>

<http:error-response statusCode="#vars.httpStatus default 500">

<http:body><![CDATA[

#payload

]]></http:body>

<http:headers><![CDATA[

#vars.outboundHeaders default {}

]]></http:headers>

</http:error-response>

</http:listener>

Error type            : MULE:SOURCE_RESPONSE_SEND

FlowStack             :

Payload Type          : org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider

--------------------------------------------------------------------------------

6 answers
  1. Jan 10, 2023, 4:37 PM

    Hi Shyram,

     

    I've seen that article before, but the HTTP request connector I'm using doesn't have that as an option. I've included a screenshot of the general and the advance tab. The advance tab leads me to believe there's already a streaming strategy in place. Do you have any advice for configuring the streaming strategy?Hi Shyram, I've seen that article before, but the HTTP request connector I'm using doesn't have that as an option. I've included a screenshot of the general and the advance tab.Capture2

0/9000

I have deployed application on cloud hub after deployment it has generated App url = flightdetails.us-e2.cloudhub.io. I have modified the URL per my implementation i.e. http://flightdetails.us-e2.cloudhub.io/api/flights, but its giving error 502 Bad Gateway. Can someone please suggest what could be the root cause. Please note that I can see in the logs that application has started successfully.

There are no errors in implementation, I have tested locally. In main process its just sending the dummy response back.

And I am directly using the app url and not via gateway

5 answers
  1. Sep 26, 2022, 3:42 PM

    I had the same issue. My browser was forcing me to use https and when I changed it to HTTP it worked perfectly

0/9000

Hi Team,

 

I am trying to use parallel for-each to publish the data into Anypoint MQ. I am able to publish the data successfully but in logs i can see some error.

 

Can any one help me on this.

 

Error

ERROR 2021-06-23 18:53:51,795 [[MuleRuntime].uber.04: [eapi-customer-rocky-oem].patch:\consents:application\json:eapi-customer-rocky-oem-config.BLOCKING @5f1f8d95] [processor: ; event: 3ed40460-d426-11eb-8f90-14f6d87d8107] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler: 

********************************************************************************

Message        : Could not serialize object

Element        : eapi-customer-rocky-oem-main/source @ eapi-customer-rocky-oem:eapi-customer-rocky-oem.xml:9

Element DSL      : <http:listener config-ref="eapi-customer-rocky-oem-httpListenerConfig" path="/v1/*">

<http:response statusCode="#vars.httpStatus default 200">

<http:headers>#vars.outboundHeaders default {}</http:headers>

</http:response>

<http:error-response statusCode="#vars.httpStatus default 500">

<http:body>#payload</http:body>

<http:headers>#vars.outboundHeaders default {}</http:headers>

</http:error-response>

</http:listener>

Error type      : MULE:SOURCE_RESPONSE_SEND

FlowStack       : 

 

 (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

1 answer
  1. Jun 23, 2021, 1:54 PM

    MULE:SOURCE_RESPONSE_SEND means that an error occurred in the source of the flow processing a successful response.

     

    Did you check if you are responding to the HTTP Request with a valid response?

0/9000

<?xml version="1.0" encoding="UTF-8"?>

 

<mule xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:http="http://www.mulesoft.org/schema/mule/http"

xmlns="http://www.mulesoft.org/schema/mule/core"

xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd

http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd

http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd">

<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="3e081917-1381-4106-a2fa-a9c4d8180881" >

<http:listener-connection host="0.0.0.0" port="8081" />

</http:listener-config>

<db:config name="Database_Config" doc:name="Database Config" doc:id="4be42af6-7e1c-4b97-b5ed-6718d5aaf398" >

<db:my-sql-connection host="mudb.learn.mulesoft.com" port="3306" user="mule" password="mule" database="training"/>

</db:config>

<flow name="training4-american-wsFlow" doc:id="0fe44c96-8928-4eed-83ae-937a742fc24e" >

<http:listener doc:name="Listener" doc:id="43e1d8fb-4de1-4173-8ec9-5666c480529b" config-ref="HTTP_Listener_config" path="/flights"/>

<db:select doc:name="Select" doc:id="74c0406a-9130-445f-95f5-5a4ff5b01fee" config-ref="Database_Config">

<db:sql >SELECT *

FROM american</db:sql>

</db:select>

</flow>

</mule>

12 answers
  1. Jan 16, 2021, 9:07 AM

    Hello @Srinivas Pachari​ ,

     

    your welcome, just for other developers I am describing the fix of your issue.

     

    1. recreated the HTTP configurations
    2. added new HTTP listener with some more configurations for response
    3. in transform message just after db connector used output application/json

     

    Thanks,

    Anurag Sharma

0/9000

Am building an API using RAML (APIKit Router) and i want to send the response with a header field "Content-Disposition"

 

I don't see any place in Mule 4 to set HTTP Response headers rather than directly mentioning on HTTP Listener. I don't want to do that on HTTP Listener as it impacts other resources/paths.

 

and i see that mulesoft documentation mentions about accessing attributes and http headers. but stupid thing doesnt give details about how to set header attributes.

 

am really pissed off with this. anybody can help me on this ?

3 answers
  1. Dec 11, 2019, 7:56 AM

    <flow name="testhttpFlow" doc:id="beb4b2ce-9a41-44ad-bf8a-37bf4a5613d0" >

          <http:listener doc:name="Listener" doc:id="4f8d7d19-9c3c-433d-afcd-ddd12241d92e" config-ref="HTTP_Listener_config" path="/">

             <http:response statusCode="#vars.httpStatus default 200">

           <http:headers>#vars.outboundHeaders default {}</http:headers>

       </http:response>

     

          </http:listener>

          <logger level="INFO" doc:name="Logger" doc:id="6e1fac7b-d610-4406-81ec-5193a63a5145" message="test req :::: #payload"/>

          <ee:transform doc:name="Transform Message" doc:id="ef8e8e24-21c4-4aa3-bcad-8ce57e05d207" >

             <ee:message >

             </ee:message>

             <ee:variables >

                <ee:set-variable variableName="outboundHeaders" ><![CDATA[%dw 2.0

    output application/json

    ---

    {

       "correlation": correlationId

     

    }]]></ee:set-variable>

             </ee:variables>

          </ee:transform>

          <!-- <scripting:execute doc:name="Execute" doc:id="a35ff2e4-1f6c-49d0-9fc0-f445f897f898" engine="groovy">

             <scripting:code >vars.outboundHeaders.put('Content-Disposition', 'form-data');

    vars.outboundHeaders.put('ddd', 'dd');</scripting:code>

          </scripting:execute> -->

          <set-payload value="#'hi'" doc:name="Set Payload" doc:id="d74cb14a-b32d-4ccf-bdba-4ef001c7b378" />

       </flow>

     

    please try to run this flow.. commented groovy if you want without dw , we can use this also

0/9000

Hi guys,

 I'm currently working on Http listener with multiple flows defined, where each message flow has a requirement of different set of Response headers, but I cannot be able to add the #vars.outboundHeaders default {} at Http Response coloumn.Even adding in the Configuration xml is being removed automatically. My current mule runtime version is 4.1.4, but I can see this working in 4.2.2 fine. Are there any modifications required

1 answer
0/9000

Hi There

 

I am trying to proxy a Restful endpoint deployed on Cloud Hub and I believe I followed all the appropriate steps - however when trying to access the API via the proxy I am getting a gateway timed out error

 

504 Gateway Time-out on Cloud Hub

 

Any ideas what could be the issue.

Any help is appreciated

 

Thank you

4 answers
  1. Dec 29, 2019, 9:38 PM

    i too have same sort of issue and could not able to get out from this Black hole.Before creating proxy the database retrieval is working,but post creating proxy im getting 504 bad gate way error by default.

    Any help on this would be great,

     

    1.Xml from Anypoin studio- implementation

    <http:listener-config name="HTTP_Listener_configCustom" doc:name="HTTP Listener config" doc:id="a808ff86-bb72-4111-ba6d-1aa6704cd7af" >

    <http:listener-connection host="0.0.0.0" port="8081" />

    </http:listener-config>

    2.Interface - (API Kit Router)

     <http:listener config-ref="HTTP_Listener_configCustom" path="/api/*">

          <http:response statusCode="#vars.httpStatus default 200">

            <http:headers>#vars.outboundHeaders default {}</http:headers>

          </http:response>

0/9000