Hi Bing,

simple question, why don't you write e.g. a processor that is configured to 
your route. Your route could look like thos:

/** Processor defined as spring bean, e.g. via @Named tag */
@Inject
MyHeaderExtractor myHeaderExtractor;

public void configure() throws Exceltion {
        from("direct:GetCustomer")
                .setHeader("direct:GetCustomer")
                // ... continue with your setter to the header
        .process(myHeaderExtractor)
        .to(endpoint); 
}

Your header extractor can than implement the processor interface which forces 
you to implement a process(Exchange exchange) method.

You could also decide simply using the bean processing capabilities of camel as 
an alternative approach.

@Named
public class MyHeaderExtractor extends Processor {
        
        public void process(Exchange exchange) {
                exchange.getIn().getHeaders(); // returns the header map on the 
in exchange
                exchange.getIn().getBody(); // returns the body on the in 
exchange
                // Here you can add some specific header extractions for 
whatever you need it
                exchange.getOut().getHeaders(); // Would give you the out header
        }
}

Hope this helps, best regards,

Christoph



On Jul 23, 2012, at 7:06 PM, bitter geek wrote:

> Hi Sergey,
> 
> Thanks for the reply.
> 
> I'm quite new to Camel. I knew you can get it from the out message but
> how do I access the out message from the code snippet I provided?
> 
> I'd like to know what is the best way to access both the status and
> the response message as a string.
> 
> On 7/23/12, Sergey Beryozkin <sberyoz...@gmail.com> wrote:
>> Hi
>> On 23/07/12 16:43, bitter geek wrote:
>>> Hi All,
>>> 
>>> I have a router builder for a rest service with configure override
>>> like the following:
>>> ...
>>> @Override
>>>     public void configure() throws Exception {
>>>             from("direct:GetCustomer")
>>>             .setHeader("Content-Type",
>>> constant("application/x-www-form-urlencoded"))
>>>             .setHeader(Exchange.HTTP_METHOD, constant("GET"))
>>>             .setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API,
>>> constant(Boolean.TRUE))
>>>             .setHeader(Exchange.HTTP_PATH, simple("${header.httpPath}"))
>>>             .setHeader(Exchange.HTTP_QUERY,
>>>                             simple(getURIComponentQuery()))
>>>             .to(endpoint);
>>>     }
>>> ...
>>> 
>>> 
>>> The rest service returns an xml document. I don't have the xsd for it
>>> so would like to set the type of the response to String via
>>> convertBodyTo(String.class).
>>> 
>>> But once I do this, producerTemplate.requestBodyAndHeaders(null,
>>> headers) returns a String object. So I lose the status code.
>>> 
>>> Noting converting it to string will let me access the status code but
>>> then I no longer have the text body available.
>>> 
>>> Any idea how to get both the status code and the text body properly?
>>> 
>>> Thanks a lot for the help!
>> I can see from the code that a status code is set as
>> Exchange.HTTP_RESPONSE_CODE header on the out message, so you should be
>> able to get it from there
>> 
>> Cheers, Sergey
>> 
>>> 
>>> Bing
>> 
>> 

Reply via email to