-
1. Re: Can't convert HTTP Response with no Content-Type to String
njiang Apr 4, 2012 9:35 PM (in response to jamie3_james.archibald)I went through the camel-http trunk code, the response content-type is optional.
I also did some test with the camel HttpProducer, I can get the response if there is no Content-Type.
So I just want to ask you some question:
What version of camel are you using?
Did you add any custom type converter yourself?
Does your web server use gzip to compress the data?
Willem
-
2. Re: Can't convert HTTP Response with no Content-Type to String
jamie3_james.archibald Apr 5, 2012 8:27 AM (in response to njiang)Here's what I've had to do to be able to perform my conversion.
from("timer://foo")
.to("http://.....")
.process(new Processor() {
// for some reason the cached data output stream has already read the inputstream
// so we need to reset the stream position in order for the converters to grab the data
public void process(Exchange exg) {
InputStream in = exg.getIn().getBody(InputStream.class);
in.reset();
}
})
.convertBodyTo(String.class)
.log("$") // no longer outputs an empty string
-
3. Re: Can't convert HTTP Response with no Content-Type to String
jamie3_james.archibald Apr 5, 2012 8:28 AM (in response to jamie3_james.archibald)im using camel.2.8.0-fuse-01-11
no gzip
-
4. Re: Can't convert HTTP Response with no Content-Type to String
jamie3_james.archibald Apr 5, 2012 9:49 AM (in response to jamie3_james.archibald)I think i found the problem. In my real code I spit out the response from the HTTP GET. The logging EIP seems to read the inputstream which moves the position to the end of the buffer.
// this fails
from("timer://foo")
.log("$") .convertBodyTo(String.class) .log("$") // empty string
If i convert the response to a string first, then the output in the log is valid
// this works
from("timer://foo")
.convertBodyTo(String.class)
.log("$") // non empty string
-
5. Re: Can't convert HTTP Response with no Content-Type to String
njiang Apr 10, 2012 2:43 AM (in response to jamie3_james.archibald)As the message body is a stream, you should enable the stream cache to let camel consume it more than one.
Willem
-
6. Re: Can't convert HTTP Response with no Content-Type to String
jamie3_james.archibald Apr 10, 2012 7:08 AM (in response to njiang)Thanks! I'll keep that in mind.
The HTTP response payloads are very small so converting to String does the trick.