You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ychawla <pr...@yahoo.com> on 2012/05/03 22:25:21 UTC
Producer Template to Invoke HTTP Endpoint Request/Reply
Hello All,
I have set up a simple HTTP service using Jetty that acts similar to a REST
endpoint and servers up XML responses. The service works just fine and I am
trying to add some unit tests to it.
I have set up a simple producer template test and tried this:
File inputFile = new File("someFile.xml");
String returnValue = template.requestBody("http://localhost:8081/REST",
inputFile, String.class);
log.debug("value: " + returnValue + "END");
However, I get no return value.
I have also tried to return an object and I get back :
org.apache.camel.converter.stream.CachedOutputStream$WrappedInputStream
If I try to cast this, I get this issue:
org.apache.camel.converter.stream.CachedOutputStream$WrappedInputStream
cannot be cast to org.apache.camel.converter.stream.CachedOutputStream
I also tried setting the stream caching to true:
context.setStreamCaching(true);
but that has no affect.
I know the service is getting invoked and is returning a proper return
value. I just can't get at it with the producer template.
Any idea how I can use the producer template to do a request/reply against
an HTTP endpoint and get the response as a string, file, or other useable
format?
>From what I understand, I need to use template.request.
This would be easy enough to do in a Camel Route with a convertBodyTo
java.lang.String, however I am writing a unit test so I just want to use the
producer template.
Thanks,
Yogesh
--
View this message in context: http://camel.465427.n5.nabble.com/Producer-Template-to-Invoke-HTTP-Endpoint-Request-Reply-tp5684220.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Producer Template to Invoke HTTP Endpoint Request/Reply
Posted by ychawla <pr...@yahoo.com>.
Hello All,
Sorry for the bother. Please ignore this issue. I was setting the body of
my response on my rest service as a buffered reader. This worked fined in
the SMX container but was causing an issue in my unit test. I read a string
from the buffered reader and set that as my service response and all is
fine.
The methods outlined above both work.
Cheers,
Yogesh
--
View this message in context: http://camel.465427.n5.nabble.com/Producer-Template-to-Invoke-HTTP-Endpoint-Request-Reply-tp5684220p5684796.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Producer Template to Invoke HTTP Endpoint Request/Reply
Posted by ychawla <pr...@yahoo.com>.
So I also tried with an exchange/processor and no luck:
Exchange result = template.request("http://localhost:8081/REST", new
Processor() {
public void process(Exchange exchange) {
Message in = exchange.getIn();
in.setBody(inputFile);
exchange.setPattern(ExchangePattern.InOut);
}
});
log.debug("value : " + result.getOut().getBody(String.class) +
"END" + result.getException());
I would expect this to give me the result as a string:
result.getOut().getBody(String.class), but it is null.
Any ideas?
--
View this message in context: http://camel.465427.n5.nabble.com/Producer-Template-to-Invoke-HTTP-Endpoint-Request-Reply-tp5684220p5684682.html
Sent from the Camel - Users mailing list archive at Nabble.com.