Camel recipient List doesnt resolve special characters - apache-camel

I have a camel route which processes xml data and send to http endpoint. below is my http endpoint.
.recipientList(simple("http://${header.httpUri}?xmlData=${body}"))
where the httpUri ill get it from db hence set it header and used. Body contains xml data with special characters of different language. Whenever it tries to resolve endpoint, since the body contains special characters, ResolveEndpointException occurs. The tracer log shows the body with special characters resolved like %20B etc.,
I feel the problem is with simple() SimpleBuilder.
Is there any other way to resolve endpoint dynamically???

Tried POST, HTTP_URI and HTTP_QUERY. It didnt work. Then found it was related to character encoding. My request contained some ISO-8859-9 encoding data. I send request with character encoding ISO-8859-9, and it worked.

Related

http4 not setting HTTP_RESPONSE properties

I have a really simple route that GETs an URL and prints the content using Camel HTTP4 component:
from("timer://foo?fixedRate=true&delay=0&period=10000")
.to("http4://www.google.com")
.process(e -> System.out.println("Out body: " + e.getOut().getBody()));
Note that I'm using out.body because, as stated in Camel documentation:
Camel will store the HTTP response from the external server on the OUT
body. All headers from the IN message will be copied to the OUT
message, so headers are preserved during routing.
But I get null values from OUT (both body and headers). Everything is being filled only in the IN message.
Am I missing anything or is it a bug?
In Camel a route consists of nodes. Each node takes the Exchange. Exchange has an IN and OUT message. So in your case, node with http4 component took the Exchange, called google.com and wrote body and headers to OUT message. Next, node with your proccesor took the Exchange. Now IN message has the response from the previous node(http4), but you are printing OUT which is empty! So IN and OUT message are per node not per route!
You are getting the Out body from the processor without setting it up first. That’s why you get null. To make this work you first need explicitly copy the incoming message, headers and attachments to Out Body and then print it. Or more easily take the In message as you mentioned.
Next part is from “Camel in Action” book which is a great book and I think it is very helpful.
in practice there’s a common pitfall when using getOut: the incoming
message headers and attachments will be lost. This is often not what
you want, so you must copy the headers and attachments from the
incoming message to the outgoing message, which can be tedious.

How to consume a Chunked HTTP Stream with Apache Camel?

I have an issue consuming a Chunked HTTP RSVP Stream using Camel.
The stream is here and you can find more information about it at the end of this page
I have created a simple route such:
from("http4://stream.meetup.com/2/rsvps").log(org.apache.camel.LoggingLevel.INFO, "MeetupElasticSearch.Log", "JSON RSVP ${body}")
But nothing happens no message are consumed. I tried by adding a camel timer before because I am not sure you can use http4 component directly in the from but result is the same.
Can you help me please?
You cannot use the http4 component in a from() directive.
However, there is several ways to call an URL and to retrieve the result:
One is to create a timer and call the http4 component from a to() like this:
from("quartz2://HttpPoll/myTimer?trigger.repeatCount=0")
.to("http4://stream.meetup.com/2/rsvps")
.log("Body is: ${body}")
.to(mockDestination);
Another way is to use the content enricher pattern if you want to for example aggegates results into one another stucture.
Note as well, if your URL is dynamic you must use recipientList() instead to().
UPDATE:
Another way to consume a stream from the Internet is to use another component than http4: the camel-stream.
This one you can declare it in a from()directive:
// Read stream from the given URL... an publish in a queue
from("stream:url?url=http://stream.meetup.com/2/rsvps&scanStream=true&retry=true").
to("seda:processingQueue");
// Read records from the processing queue
// and do something with them.
from("seda:processingQueue").to("log:out")
You can see more sample in this site.

Format=RAW parameter for "Users.threads: get" request

I'd like to get raw messages for a particilar thread via "Users.threads: get" request. Is it possible to use format=raw parameter in this request somehow? I know it is possible for message request but I really need to do that for this one.
It might be useful to specify the format (raw or minimal) when requesting a thread, unfortunately this is not currently possible. The format can only be set for a message request. Requesting a thread in raw format however would not be a good idea since a thread could contain many large messages.
It is possible to set the format, but for some reason google doesn't allow the raw format when getting threads.
See the docs here

How to change the content length in request?

It's regarding content length.
I know its use. It tells the receiver that "this much" data I am sending.
It's available with both request & response. In Java, we have setContentLength() method for response, we can set content length to some value using this method and browser is going to read only up to that point in the body.
In request, we don't have any setContentLength() method - at least not in Java. So I believe browser sets this as per the data request is containing. Now let’s say if I modify this request in between – change a parameter value to some bigger value, how do I change the content length? If I don’t change content length, server doesn’t read the complete body – it only reads up to content length & ignores rest of the body content.
I hope my question is clear.
Thanks.
PS: I am changing request in a C filter in web server before request goes to application server.
I'm not sure if it's a good idea to change content length of request, I don't think you can achieve that simply, the only way i can think of is parse the content of request, the strip unneeded data and the generate the request that simple mimics original request but contains stripped data, it also depends on the whenever you are using POST or GET requests

Determining response length from an ISAPI filter

I am working on an ISAPI Filter to strip certain content out of responses. I need to collect all the body of the response before I do the processing, as the content I'm stripping could overlap send buffers.
To do this I'd like to buffer the response content with each SF_NOTIFY_SEND_RAW_DATA notification until I get to the last one, then send the translated data. I would like to know the best way to determine which SF_NOTIFY_SEND_RAW_DATA is actually the last. If I wait until the SF_NOTIFY_END_OF_REQUESTnotification, then I don't know how to send the data I've buffered.
One approach would be to use the content-length. This would require I detect the end of the headers. It would also require assuming the content-length header is correct (is that guaranteed?). Since HTTP doesn't even require a content-length header, I'm not even sure it will always be there. There seems like there should be an easier way.
I'm assuming the response is not chunked, so I am not handling dechunking before I do the response change. Also, when I do the modifications to the response body, the size of teh response body will not change, so I do not need to go back and update the content-length.
I eventually found some good discussions via google.
This posts answers my questions, as well as raises issues a more complicated filter would have to address: http://groups.google.com/group/microsoft.public.platformsdk.internet.server.isapi-dev/browse_thread/thread/85a5e75f342fad2b/cbb638f9a85c9e03?q=HTTP_FILTER_RAW_DATA&_done=%2Fgroups%3Fq%3DHTTP_FILTER_RAW_DATA%26start%3D20%26&_doneTitle=Back+to+Search&&d&pli=1
The filter I have s buffering the full request into its own buffer then using the SF_NOTIFY_END_OF_REQUEST to send the contents. The modification it does does not change the size, and precludes the possibility that the response is chunked, so in my case the filter is relatively simple.

Resources