I am calling a HTTP endpoint before my message reaches the apikit:router.
By the time the message reaches the apikit:router, it has lost all the original HTTP headers. Because of that the router is not able to figure out the intended method.
Actually I am able to copy the inbound properties in a session variable, after the HTTP call I am able to revert them as outbound property. Then I have my api router in another flow, so the outbound property gets coverted to inbound property again. This solution works fine, but the flow looks pretty ugly. (as I had to do this copy for about 10 headers)
Is there any better workaround ? Also I am trying to avoid manually dealing with these headers.
Wrap the HTTP call within the enricher, it will preserve the http inbound properties and the payload of the original call. Like this,
<enricher target="#[flowVars.resultOfInnerHTTP] source="#[payload]">
<http:request...../>
</enricher>
<apikit:router.../>
Related
I want to enrich a Camel exchange with content fetched from some external web service. However, when calling that service, I do not want all the headers on my incoming exchange to be mapped onto HTTP headers, just some selected ones should be mapped. Hence, I try to use a HeaderFilteringStrategy as follows:
override fun configure() {
from(direct("webservice-query"))
.setHeader("Accept").constant("application/json")
.setHeader(Exchange.HTTP_PATH)
.simple("/partner:\${header.$PARTNER_ID_HEADER}")
.setHeader(Exchange.HTTP_QUERY).constant("attachments=true")
.enrich(http(partnerDbUrl)
.headerFilterStrategy(myHeaderFilterStrategy)
.httpMethod(HttpMethods.GET), PartnerAggregationStrategy
)
}
where myHeaderFilterStrategy is an instance of a custom HeaderFilteringStrategy. However, the HTTP component does not use this strategy. Instead, a default HttpHeaderFilteringStrategy is used. Why? What is wrong with the above route configuration? How can I set a custom header filtering strategy, or otherwise prevent unwanted headers polluting the HTTP request?
I am working with Apigee edge lately and am having trouble with a specific implementation. Essentially, the client will request an oauth token from their API through apigee. However, to make calls to our proxy they need an oauth token from us as well. So far my flow goes like this.
Client calls token endpoint on apigees side, a service callout is made to get a token from one of our other proxies (returned as a json object). Then the request passes through and gets the token from the clients API.
Here is where I am having trouble. After the response from the clients API, I want to use the assign message policy to modify the response to include the first token that was grabbed from our other proxy. The problem is the variable seems to be falling out of scope between request/response.
Am I missing something obvious here? I have looked into the PopulateCache policy, but I feel like this may be overkill as I only want the variable to remain in scope for the request/response. Thanks for any clarity you guys can provide! Sorry if my explanation is not very good, I am VERY new to Apigee Edge.
You aren't missing anything obvious. Variables should not fall out of scope between request and response flows. You are right that PopulateCache isn't necessary.
One item that catches people sometimes is how you access the response from the service callout. If you configure the service callout response to be stored in a variable called calloutResponse, then when you access the body to extract information, you'd use calloutResponse.content as the source. If you try to access calloutResponse instead, you might think that the variable had disappeared.
Add more details/trace if that is not the problem, and we can figure out what is going wrong.
I am trying to customize the response of a bayeux server response so that i can add some header parameters before sending it back to UI. I am able to add header values in the request using customize method in a LongPollingTransport. Much help needed.
CometD tries to abstract away from the underlying protocol.
When you use WebSocket, for example, the concepts of request headers and response headers simply do not exist anymore.
As such, it is way better that if you have additional information to send to the client, well that additional information should go in the CometD messages rather than in HTTP headers.
Furthermore, when using HTTP as a transport, a single HTTP response may carry multiple messages, so it is not clear to what CometD message the additional information would refer to.
Your question is too generic (does not say why you want to add headers, does not say what specific header, etc.) to get a precise answer, but bottom line is that you typically don't want to use HTTP headers with CometD.
Is it possible to intercept MobileFirst adapter's resource method call? The purpose of such intercepting is adding common logic for all adapter's resource methods into one place (e.g. appending HTTP response with particular headers).
I don't think you can "intercept it", but you can just write your code in a way that all adapter calls first go through some helper function where you add your required headers before "releasing" the call from the client and have it sent to the server.
I'm storing some data as session variables in a mule flow that involves a mid-flow http call to an external service. I need this data for a subsequent branch of the flow logic, hence the session variable. However, I do not want this data to go out with the http call as http headers. Is there a way to limit which session variables mule includes as http headers in a given call?
If you want to decide what session property to propagate you can write a custom session handler and inject it into your http connector something like this:
<http:connector name="httpConnector">
<service-overrides sessionHandler="your_session_handler" />
</http:connector>
An example of a custom session handler can be found here
That said I'd like to echo David Dossot's answer: session variables should seldom be used, especially knowing how Mule leaks them by default. If you want to propagate something, you should set it explicitly as an outbound property and mule will propagate it.
Use flow variables: session variables should seldom be used, especially knowing how Mule leaks them by default.
Flow variables (aka invocation properties) should be unaffected by endpoint interactions, this by design. Any other behaviour would be a bug. If your variables do not need to extend further than a flow, use flow variables, not session variables.
session variables are not sent across http calls, only session ID is sent via cookie (usually)
if you need to pass some data via http call to external domain - include them in GET, for example, as cookie are not shared