Add a Query parameter in Mule - http

Hi I want to add a query parameter Age = 23
I tried adding
message.inboundProperties.'http.query.params'.Age = '23'
In a expression
<expression-component doc:name="Expression"><![CDATA[message.inboundProperties.'http.query.params'.Age= '23';]]></expression-component>
It won't work.

Inbound properties are Immutable hence you must add it in outbound property to add a query param in your outbound http connector you can use the below
<http:request config-ref="HTTP_Request_Configuration" path="outway" method="POST" doc:name="HTTP">
<http:request-builder>
<http:query-param paramName="Age" value="23"/>
</http:request-builder>
</http:request>

To add properties to an outgoing message they need to be in the outbound scope:
message.outboundProperties.'http.query.params'.Age= '23'

You are trying to modify inbound properties but you can´t, they are inmutable
Properties have two main scopes: inbound and outbound.
Inbound properties are immutable, are automatically generated by the message source and cannot be set or manipulated by the user. They contain metadata specific to the message source that prevents scrambling of data formats or other processing mishaps later in the message’s lifecycle. A message retains its inbound properties only for the duration of the flow; when a message passes out of a flow, its inbound properties do not follow it (see image below).
https://docs.mulesoft.com/mule-fundamentals/v/3.7/mule-message-structure
You must add it to outbound as Ryan said.

Related

Implementing a Passthrough MPG in Datapower which dynamic routing

I want to implement a MPG service in Datapower with Request Type and Response type as Passthrough, with static end point its fine. Can I handle the same Dynamically.
Created a Policy with Request rule having a result action and a transform action having the dynamic routing logic, with input and output type as NULL. But not able to route.
Any suggestion?
As bjimba says will the Passthrough mode prevent any processing of the data/meta-data to happen. This is per design and to make sure data passes through "untouched".
Passthrough does not give any performance gain or other benefits (use streaming instead for performance gain).
To be able to dynamically route you have to change the Service variable "routing-url":
XSLT: <dp:set-variable name="var://service/routing-url" value="'protocol://target/URI'" />
(Note the single quotes)
GatewayScript: serviceVars.setVar('var://service/routing-url', 'protocol://target/URI');
or
serviceVars.routingUrl = 'protocol://target/URI';
If you seek performance gain make sure your Stylesheet Action (XSLT or GWS) use Input and Output as NULL and add a Result Action with Input: INPUT and then set your MPGW to Streaming mode.
Passthrough mode won't run request rules. That's why they call it "passthrough". Change it to XML mode.

In Apigee, how can I access callout response in javascript policy

I created a service callout (eg: myCallout) which returns its response in a variable (eg: myCalloutResponse). How can I access the body of the callout in a javascript policy?
I tried context.getVariable("myCallout.myCalloutResponse") and a few others but couldn't get this to work.
Thanks
context.getVariable("myCalloutResponse.content") should give you the payload. Take a look at other variables available on response object - to extract the data you need.

I have a requirement to make calls to two different end points in a sequence on a given call

I am trying to achieve the functionality where i have to call two different backends / target endpoints that have completely different interface in a sequence. Output of one call becomes input to the second one upon an error condition from the first call.
I would like to know how to implement this. I am new to Apigee so details will help me.
It sounds like you need to do a ServiceCallout in the request flow.
Set up your Target as whatever the second server is that you need to talk to in the normal flow. Then create a policy to callout to your first target:
<ServiceCallout name="myPolicy">
<Request clearPayload="false" variable="myRequest"/>
<Response>myResponse</Response>
<HTTPTargetConnection>
<Properties/>
<URL>http://example.com</URL>
</HTTPTargetConnection>
</ServiceCallout>
Note the Response block puts the headers and payload from the response into an object that you can then extract variables from using "myResponse" as the <Source> in the ExtractVariables policy.
Then you can build a new request for your target with the variables you set in the ExtractVariables by using an AssignMessage policy
Service Callout
http://apigee.com/docs/api-services/content/call-services-or-apis-using-servicecallout
ExtractVariables
http://apigee.com/docs/api-services/content/extract-message-content-using-extractvariables
AssignMessage
http://apigee.com/docs/api-services/content/generate-or-modify-messages-using-assignmessage

as for a flex http request, how to set the header attributes when special characters are contained

My task is to call some api in flex, and I use HTTPService to send a request to the server. It must be authenticated if I want to retrieve any data from the server. The authentication information are put in the headers of a request. Now the problem is if the attribute contains some special characters (a colon for instance), then the request won't work, which means the authentication failed. Actually this attribute is then neglected. Is some encoding needed when setting those attributes?
// this attribute will be negelected, for colons are contained in it.
http.headers["X-wsse"] = "Created=\"2013-01-02T11:29:13+01:00\"";
Colon isn't special in HTTP header field values.
You may want to check the documentation of "X-wsse" (whatever that is).

How to add additional data to a mule payload?

I'm trying to add some additional static data to an inbound http message (received as URL parameters) payload before submitting it to an outbound http form based endpoint. My mule config is as follows :
<flow name="login" doc:name="login">
<http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/login" doc:name="Login"/>
<http:body-to-parameter-map-transformer doc:name="Body to Parameter Map"/>
<http:outbound-endpoint address="http://localhost:8090/mayapp/Main/login.do"
method="POST" contentType="application/x-www-form-urlencoded" exchange-pattern="request-response">
</http:outbound-endpoint>
</flow>
The above transforms the URL parameters to a http form POST (name/values pairs) very nicely. What I need now is the ability to add new name-value pairs to the POST(ed) data ? The form I'm posting to expects some static data (posted as hidden HTML fields) that I would like to handle as part of the transformation process.
I've managed to accomplish this using a custom component. I'm wondering if there's an easier way to handle this using Mule's native transformers / message processors !
First I would use a transformer and not a component for this, as it is really a transformation you're doing on the payload data.
Second I can't think of another transformer than the Groovy one to modify the Map payload created by the body-to-parameter-map-transformer. Something like:
<script:transformer>
<script:script engine="groovy">
<script:text>
payload['newKey'] = 'newValue'
</script:text>
</script:script>
</script:transformer>
You can use an expression-component as well:
<expression-component doc:name="change_payload">
<![CDATA[#[ message.payload = 'foo';]]]>
</expression-component>

Resources