camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: camel-http how to retrieve response body from HttpOperationFailedException
Date Fri, 21 May 2010 13:03:03 GMT
On Fri, May 21, 2010 at 2:58 PM, attilav <dzs13@freemail.hu> wrote:
>
> Hi,
>
> exchange.getProperty did the trick... thanks.
> However, shouldn't the exchange.getException() also return the exception?
> If not, what is the reasoning here? What is the purpose of the exception
> within the exchange?
>

Because you have caught the exception using onException.
Then you are alternating the routing of the Exchange. So for example
you could continue routing.
The causes exception is then moved from getException -> Property.



> regards,
> attilav
>
>
> willem.jiang wrote:
>>
>> attilav wrote:
>>> Hi,
>>>
>>> I'm trying to use camel-http to post a soap message. The remote server
>>> returns  status code 500, with a body, which causes camel to throw a
>>> HttpOperationFailedException.
>>>
>>> According to the docs (http://camel.apache.org/http.html):
>>> """
>>> This exception contains the following information:
>>>
>>>     * The HTTP status code
>>>     * The HTTP status line (text of the status code)
>>>     * Redirect location, if server returned a redirect
>>>     * Response body as a java.io.InputStream, if server provided a body
>>> as
>>> response
>>> """
>>>
>> I just checked the HttpProducer code, the Response body is turn into
>> String instead of using the inputstream directly.
>> I will update the wiki page for it.
>>
>>> I need to access the response body, but the exchange.getException()
>>> returns
>>> null.
>> You can get the exception by using below code in your processor.
>>
>> Exception c = exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
>> Exception.class);
>>
>>
>> Willem
>>
>>>
>>> Bellow us my setup, am I doing something wrong?
>>>
>>>         from("direct:remotesender")
>>>             .onException(HttpOperationFailedException.class)
>>>                 .maximumRedeliveries(0)
>>>                 .process(new Processor() {
>>>                     public void process(Exchange exchange) throws
>>> Exception
>>> {
>>>                         log1.info("INBODY
>>> ----------------"+exchange.getIn().getBody(String.class));
>>>                         log1.info("INHEAD
>>> ----------------"+exchange.getIn().getHeaders());
>>>                         log1.info("OUTBODY
>>> ---------------"+exchange.getOut().getBody(String.class));
>>>                         log1.info("OUTHEAD
>>> ---------------"+exchange.getOut().getHeaders());
>>>                         log1.info("EXC
>>> -------------------"+exchange.getException());
>>>                         log1.info("FAIL
>>> ------------------"+exchange.isFailed());
>>>                     }
>>>                 })
>>>                 .end()
>>>             .setHeader(Exchange.HTTP_METHOD,
>>> constant(org.apache.camel.component.http.HttpMethods.POST))
>>>             .setHeader("SOAPAction",
>>> constant("http://xxx.com/interfaces/ticket"))
>>>             .to("http://iface.intra:8115/ticket")
>>>
>>>
>>> The output is:
>>>
>>>
>>> org.apache.camel.component.http.HttpOperationFailedException: HTTP
>>> operation
>>> failed invoking http://iface.nrps.telekom.intra:8115/fault_ticket with
>>> statusCode: 500
>>>
>>> 2010-05-20 15:48:32,132 | INFO  | INBODY ----------------<REQUEST ...
>>> 2010-05-20 15:48:32,135 | INFO  | INHEAD ----------------{JMSType=null,
>>> ...
>>> 2010-05-20 15:48:32,138 | INFO  | OUTBODY ---------------null
>>> 2010-05-20 15:48:32,138 | INFO  | OUTHEAD ---------------{}
>>> 2010-05-20 15:48:32,138 | INFO  | EXC -------------------null
>>> 2010-05-20 15:48:32,138 | INFO  | FAIL ------------------false
>>>
>>>
>>> Shouldn't the exchange.isFailed() be also be set?
>>>
>>>
>>> thanks,
>>> attilav
>>
>>
>>
>
> --
> View this message in context: http://old.nabble.com/camel-http-how-to-retrieve-response-body-from-HttpOperationFailedException-tp28621982p28633471.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Mime
View raw message