I wrote a simple module for web server, but I cann't apply the filter for a specific HTTP status. For example, I would like to add a specific header in the response if the response from the server is 200.
For processing the request I use ap_hook_fixups. As the handler of the hook, can get the status of the answer?
The fixups phase is the wrong place to do this. It occurs before the request handler is called, so the response (and its status) has not been determined yet.
If your module needs to modify the response after it has been generated, it will need to operate as a filter. You may want to refer to the Apache document How filters work in Apache for details.
Related
I understand that Azure standard Stateful Logic app workflow runs Asynchronously but can i use stateful standard logic app for the below scenario:
We want to receive Json data from the third party in a HTTP post request, then process it and store it in Azure data lake. But the problem is since Azure standard stateful workflow runs asynchronously as soon the http trigger is hit it returns Status 202 Accepted. I want to send the caller end status of the request. For example- I want to send 500 Internal server error when the request was valid but still the workflow failed due to an internal error. If the data was processed successfully i want to send the caller HTTP Status 200 Ok. I dont want to send always HTTP status 202 Accepted to the caller. I want the caller to know what exactly happened to their HTTP request. Is it possible through standard logic app? I dont want to use consumption Logic app because of security reasons.
You can achieve this using runafter configuration by enabling this configuration it runs even after the whole workflow is getting failed.
Go to your work flow and select Menu for the action you want to run regardless if the previous one is about to fail, timeout, or skip. It's Condition in my case, and then 'Configure run after'.
For instance here is my logic app
Here is how my code view looks like :
OUTPUT:
UPDATED ANSWER
In that case, too you can use the same runafter concept with the condition having status code is not equal to 200 as a true statement and continue the flow
Here is the logic app
Here is the output
The version of Apache Camel is 2.18.1
In documentation for 2.x, https://camel.apache.org/components/2.x/http4-component.html, getWithBody and deleteWithBody options as query parameters are provided.
deleteWithBody (producer) : Whether the HTTP DELETE should include the message body or not. By default HTTP DELETE do not include any HTTP body. However in some rare cases users may need to be able to include the message body. Default: false
getWithBody (producer) : Whether the HTTP GET should include the message body or not. By default HTTP GET do not include any HTTP body. However in some rare cases users may need to be able to include the message body. Default false
But when I concatenate one of these 2 parameters at the end of the endpoint URI, it's not recognized as an option. Instead, it's passed to the endpoint as an ordinary query parameter, while other query parameter options are treated as component options and not forwarded to the endpoint.
When I inspect the source code, I see that options are recognized by matching with the fields and methods of HttpEndpoint (org.apache.camel.component.http4) and HttpCommonEndpoint (org.apache.camel.http.common) classes. getWithBody and deleteWithBody fields doesn't exist in these classes while other options can be found among the fields of these classes.
Can I assume that the documentation is wrong? If so, how can I achieve to send body with HttpComponent(Http4Component) of Camel while the http method is GET or DELETE?
Option deleteWithBody was introduced in Apache Camel 2.19.0. See CAMEL-10916.
Option getWithBody was introduced in Apache Camel 3.0.0 and backported to 2.25.0. See CAMEL-14118.
For such old version use docs archived on github, it is not published on website - https://github.com/apache/camel/blob/camel-2.18.x/components/camel-http4/src/main/docs/http4-component.adoc
You need to update to newer version or implement custom component overriding some methods from HTTP4 component. There is no option to enable this OOTB in 2.18.1.
i agree with the answer given by #Bedla.
to add something additional this is what we did .
We checked the code and debugged - this allowed us to realize that at a point were camel interacts it drops the body if a GET Call has a one. it will be send as a normal GET Request because Camel version 3.x.x only supports it.
we tried different ways to forcefully add the body. that was also failed because what ever we add will be discarded by camel.
we were using camel v2.22.1 at the time. going to a higher version such as camel 3.x.x will be a big leap since there are multiple changes that will be included , so lucky for us camel team back ported this ability to send the GET Request with the Body (from here on getWithBody) to camel v2.25.0
coding level changes :
Append getWithBody=true to the Request URL
Updated camel Modules
camel-core-2.25.0.jar
camel-cxf-transport-2.25.0.jar
camel-cxf-2.25.0.jar
camel-core-xml-2.25.0.jar
camel-http-common-2.25.0.jar
camel-jaxb-2.25.0.jar
camel-spring-2.25.0.jar
camel-soap-2.25.0.jar
camel-cdi-2.25.0.jar
camel-jdbc-2.25.0.jar
camel-http4-2.25.0.jar
****special note ****
Note that under each folder location, there is a modules.xml file. You need yo open that and change the jar file version number to the one you want to use. in this case 2.25.0
That’s it and Happy Coding !
I have created a route that via a splitter does multiple lookups, aggregates the responses and returns the list of objects.
I use a remote proxy to invoke the route.
Given that there are multiple branches on the route it is possible that some will succeed and some will fail. How can I get all the returned results but also a list of failures, with reasons for failures, from the remote proxy?
I can think of 3 options, but hope there is something cleaner
Use a header structure that is passed in with remote proxy call to collect errors
Wrap the return value of the remote proxy in structure that contains results and errors
Route errors to some error endpoint (not sure how to correlate with my request though)
Are there any other options?
I would go with option 3. Route all the errors to a generic error endpoint where you log the errors and return some default response. That way you can refer to that generic error endpoint from all your branches ensuring they will all react the same way whenever they encounter an error.
You should be able to get exception details in Aggregation strategy class and accordingly take action.
It depends on what you want to achieve from overall design. As a general practice, if you want consumer of your remote practice to fail on errors, it should get the exception details immediately. If your remote proxy is a REST Endpoint, it can return with 500 error. And similar strategy can be followed for other protocols.
I currently have a camel route that exposes a cxf endpoint. When a messages comes through the endpoint I would first enrich that message with some information from another webservice and then do more processing afterwards. However, I want make the first half of this route synchronous so I can send back a response to whomever called my exposed cxf endpoint.
The route looks something like this:
from(cxf:CxfEndpoint)
.process(someProcessing)
.to(cxf:ExternalCxfEndpoint)
.to(activemq:queue:somequeue)
//return a response back to caller here
from(activemq:queue:somequeue)
... //additional processing here
...
The reason for this is because when a message comes via my exposed cxf endpoint I don't know if it's a valid message. I need to first validate it with the message enrichment. Once the message is enriched, I want let whomever sent the message know that their message is accepted but don't want them to wait for the message to make it through the whole route as that could take hours.
Does anyone know how this would work?
Thanks in advance!
I believe all you need to do is set exchangePattern to InOnly a.k.a. make it an Event Message. This should have your route not wait for a reply from ActiveMQ. Camel exchange will default to InOut when it's originating from a web service, as in your case.
A related question with an answer from a Camel dev here.
Also see this one for some details on the behavior when your broker is down.
Yes definitely , 100% possible. A simple example would be this :
From cxf endpoint
Store your request in a camel property or header
To xslt - generate xslt for cxf endpoint - Synchronous flow
Reset your original payload using set body.
Wiretap Endpoint - to any endpoint downstream or even a route , this becomes asynchronous . This won't take part in the above sync response .
Note- step 2 & 4 may not be required, it depends on your use case .
There are whole lots of things you can do, I just gave a very simple example . It doesn't need to be wiretap as well, but wiretap helps us not to write any additional custom exceptional handling.
I am working in a project where i need to change a browser source code to change the way it behaves when receiving a certain http response Status-Code. When these kind of packets are received i need to catch them, analize the message body and do something accordingly.
I am struggling to get access to a HTTP message body. Either request or response. I have tried pretty much everything. I can use/alter headers as i wish, i can insert my messages in the queue(calling libsoup/midori primitives).
Midori uses libsoup session signals for handling the messages. "request-started" and "request-queued". I added the avaiable "request-unqueued" which allows me for further granular control in the http life-cycle.
I know there are Soup_Message specific signals but i have not found how to work with them although i feel like i should.
Please feel free to help me, guide me to any links, documentation, anything that can give me an hint.
TL:DR: Need to access Http response body/content and can only read Headers.