1

I have requirement to set cookies into mules HTTP Request component. I verified different possibilities but no success. I am using Mule 3.9 CE. Any suggestion?

I tried below (Use Cookies is enabled)

  1. Enabled User Cookies option for HTTP Request component
  2. Tried to add cookies into the Header (Add cookies as header in component configuration)
  3. Set cookies using set property and used it as outbondproperties.
  4. Tried to add cookies using message transformer – same as 2 but different approach
  5. Tried to set HTTP Request metadata for cookies as String type
  6. Tried to retrieved cookies with org.mule.transport.http.CookieHelper.parseCookiesAsAClient and then set as a property before 2nd call

About flow: 1. Sends request with credential in it – just to get cookies (This part works in current mule process) 2. Send same request without credentials (this request uses cookies) and it returns the actual response.

Please find below xml (subflow)

<sub-flow name="test">
    <invoke name="AcksRequest" object-ref="acksRequest" method="getAcksRequestWithCred" methodArguments="#[flowVars.txFile], ${user}, ${password}" doc:name="Invoke AcksRequest"/>
    <set-variable variableName="acksRequest" value="#[payload]" doc:name="Set Acks Request"/>
    //This request sends request just for cookie
    <http:request config-ref="HTTP_Request_Configuration" path="/test.asmx" method="POST" doc:name="HTTPS POST" metadata:id="ec75b200-28d1-49fc-bdcd-6883d6ba27c8">
        <http:request-builder>
            <http:header headerName="Content-Type" value="text/xml"/>
        </http:request-builder>
    </http:request>

    //Get cookies and set it as property
    <logger message="Cookies----&gt;  #[message.inboundProperties['set-cookie']]" level="INFO" doc:name="Logger"/>
    <set-property propertyName="Cookies" value="#[message.inboundProperties['set-cookie']]" doc:name="Property"/>
    <logger message="Outbond Property ----&gt; #[message.outboundProperties.Cookies]" level="INFO" doc:name="Logger"/>

    //Another call with cookie
    <invoke name="AcksRequest1" object-ref="acksRequest" method="getAcksRequestWithoutCred" methodArguments="#[flowVars.txFile]" doc:name="Invoke AcksRequest"/>
    <http:request config-ref="HTTP_Request_Configuration" path="/test.asmx" method="POST" doc:name="HTTPS POST" metadata:id="4c78fe88-7b4c-47b9-bb9b-4a627207ae46">
        <http:request-builder>
            <http:header headerName="Content-Type" value="text/xml"/>
        </http:request-builder>
    </http:request>

    <object-to-string-transformer doc:name="Object to String"/>
    <set-variable variableName="acks" value="#[payload]" doc:name="Set Acks Response"/>        
</sub-flow>
Mind Peace
  • 905
  • 8
  • 29
  • 1
    If the server the HTTP request component is hitting sends "Set-Cookie" headers, then you should just enable cookies on the components configuration. Otherwise, you should just send the Cookies as you would any other header, could you post the details (XML) of every option you tried? – afelisatti Aug 15 '19 at 18:59
  • I have enabled component for cookies and also tried to send cookies as header. Unfortunately I can't post xml here due to privacy however I created chat room. May be we can continue on the same. Thanks! – Mind Peace Aug 15 '19 at 19:31
  • 1
    You can just edit out whatever is confidential and used dummy strings. – afelisatti Aug 16 '19 at 13:55
  • I added xml for one of the 6 approaches I tried. Just to clarify - I am using Mule Community Edition 3.9. – Mind Peace Aug 16 '19 at 15:34

0 Answers0