I want to add some headers to my incoming rest api requests with kong gateway.
In the kong admin UI, I set these parametes :
config.add.headers: myheader: $(consumer_id)
myheader is a name for new header and I want to set variable of consumer_id value in these header.
but after this configuration , kong gives me a empty value.
I also tried ${consumer_id} and etc ...
but none of these variables worked.!
So the question is: what's the VARIABLE syntaxs of consumer_id or custom_id and ... too call in kong gateway.
thx
BR
finally I found the correct header from network dump, and replace it with My required header.
the right header for my case was : X-Consumer-Custom-ID
Related
I have noticed that rest doc (HttpRequestSnippet.java) is setting APPLICATION_FORM_URLENCODED_VALUE as content type for PUT with request parameter and without request body. This should be corrected, may be introducing a MEDIATYPE as NONE and set content type as NONE or ALL when request body/content empty.
For example, my put request is like below:
/api/v1/config/?mode=unknow
This sounds like a bug in Spring REST Docs' HttpRequestSnippet for which I've opened an issue.
I would like to set some properties before my InvokeHTTP processor in NiFi. In fact, I try to use an API and I would like to give HTTP headers with key API.
I can set all properties with a lot of UpdadeAttribute but there is two problems :
I can't start my work on a UpdadeAttribute
All my properties have to be set one time, no more
These properties are in assembly of two keys.
First, I merge the two keys in merged_keys
${api_key}:${api_secret_key}
Second, I encode merged_keys in encoded64_key.
${merged_key:base64Encode()}
Then, I write my HTTP header Authorization using encoded64_key
'Authorization': 'Basic ${encoded64_key}'
edit : I tried to set this configuration in UpdateAttribute but I know that isn't a good way so I tried to set it directly in my InvokeHTTP and nothing happen.
The part of building HTTP header works perfectly but I don't know how can I do for give this header to my InvokeHTTP one time.
Set a property on the InvokeHTTP processor with name Authorization and value Based ${encoded64_key}. This is the way to attach the header. See the documentatinos.
An HTTP client processor which can interact with a configurable HTTP Endpoint. The destination URL and HTTP Method are configurable. FlowFile attributes are converted to HTTP headers and the FlowFile contents are included as the body of the request (if the HTTP Method is PUT, POST or PATCH).
FYI with the contents, you should give the contents as a flowfile by using replaceText processor.
I am developing a java based web application in spring-boot where I am sending http-header from server to client end.
Server-side I have used Spring-boot in form of REST API, whereas at client end we have simple plain HTML5/Angular framework.
My query is, while I am sending any header from server then at client end I always get it into lowercase vs actual.
For example, I am setting header something like,
header.add("KK-ACTUAL-VALUE", "sfsfjDFFDHTsdfJKKA");
At client end, it gives,
kk-actual-value : "sfsfjDFFDHTsdfJKKA"; (Header name converts into lower case!)
Now, the question is, how to prevent it ?
I want to have the same header name what is actually passed by Server/API.
Looks like tomcat container turns the headers to lowercase. Since spring boot uses an embedded tomcat is been affected by it. More info here: https://github.com/mitre/HTTP-Proxy-Servlet/issues/65
As the Http standard specifies:
Each header field consists of a case-insensitive field name followed
by a colon (":") ...
https://www.rfc-editor.org/rfc/rfc7230#section-3.2
To make the header case-sensitive you can set it to the MultiValueMap, and then pass it as a parameter to the HttpHeaders constructor.
The code snippet can be something like this:
MultiValueMap <String, String> headers = new LinkedMultiValueMap<>();
headers.add("KK-ACTUAL-VALUE", "sfsfjDFFDHTsdfJKKA");
HttpHeaders responseHeaders = new HttpHeaders(headers);
Before posting this question about Apache NiFi InvokeHTTP I have gone through all other questions and their answersbut I am still unsure the best flow I should have. My situation is as below:
1) From Apache Kakfa, I get raw metadata.
2) Using EvaluateJSONPath I get attribute I want.
3) Using RouteOnAttribute I created 3 routes based on the attribute value I got from step-2 above.
4) Now based on the attribute value I want to decide whether I should go for GET or for POST or for Delete.
5) My question is where/how to set POST message? GET message? Delete Message body?
6) I am able to set the URL in configuration part provided by InvokeHTTP. But message body I don't know which is that property? or its in flow file using ReplaceText?
I read somewhere that before you divert your Restful POST HTTP request to InvokeHTTP you must have another processor before which changes the content of flow file.
Ref: Configuring HTTP POST request from Nifi
Please help. Thanks.
regards,
Yeshwant
Adding on to what Bryan had explained, POST will use the FlowFile content as the message body so if you have some other data which you want to wipe/transform into something and then sent as the message body, you can leverage the following processors :
ExtractText to read data from the existing FlowFile content
ReplaceText to erase the existing content of the FlowFile and replace it with different one
To set the headers for the REST calls, InvokeHTTP has the property Attributes to Send property which takes a regex which will scanned against the incoming FlowFiles' attributes and whichever attributes are matched are taken and sent as HTTP header.
To add new attribute to your existing FlowFile, you can use UpdateAttribute
For a POST, the body will be whatever is in the flow file content.
a GET and DELETE typically wouldn't have a body since the information would typically be provided in the URL or query params.
The following flow takes a username/password combination and authenticates against an API via InvokeHTTP:
The result of InvokeHTTP is an authentication token:
I want to use this token in any preceding API calls. What flow do I need to provide the auth token as an authorization header for InvokeHTTP? The header has to look like this:
Authorization: Token ...
You can use an EvaluateJsonPath processor to extract a JSON value using the JsonPath expression $.token and Destination flowfile-attribute, which will place it in an attribute. So using a dynamic property named Authorization with the value $.token will result in InvokeHTTP sending a header with the value Authorization: abcdef..... In order to format the header correctly, you'll want to use an UpdateAttribute processor between EvaluateJsonPath and InvokeHTTP to update the attribute value using the Expression Language expression Token ${Authorization} to prepend the literal string.