-
1. Re: Mechanism for passing information from Consumer to Producer in and Endp
jstrachan Apr 16, 2008 12:02 PM (in response to eamdwyer)Could you give a more concrete example of what you mean by any chance?
When a producer is sending an Exchange to some endpoint (where it'll get processed typically by a consumer), the consumer can modify the Exchange setting properties, or it can set the OUT message.
So if you are a producer and you wanna see what is returned by the consumer you do something like this in Java....
class Producer implements Processor { ... Exchange exchange = endpoint.createExchange(); consumer.process(exchange); // now lets see if we have any output... Message out = exchange.getOut(false); // lets not create it if its not present if (out != null) { .... /// lets process it } }
-
2. Re: Mechanism for passing information from Consumer to Producer in and Endp
eamdwyer Apr 17, 2008 5:40 AM (in response to eamdwyer)My scenario is a bit different to the one you describe. I am using a modified version of the basic CXF example from the kits where a cxf client invokes on a camel-cxf soap-over-http endpoint and those requests are then forwarded on to a camel-cxf soap-over-jms endpoint.
For this, the cxf client invokes on a camel-cxf soap-over-http endpoint and first hits the camel cxf endpoint consumer (this is as much a statement as well as a place where you can confirm if I have the architecture/terminology correct in my head;) ). I also have cxf interceptors loaded at that point to process in the request from the client. Those interceptors will set up some data based on the message it receives.
Camel then routes this request on to the soap-over-jms endpoint so to get there an invocation goes through the camel exchange and enters the camel-cxf endpoint producer. I would like at this stage, i.e. in the producer, to put the data setup in the consumer onto the outbound request, but I dont know how to get the data from the consumer.
Also it would be nice if the data setup in the consumer could be available in a camel interceptor if I had on in my route.
-
3. Re: Mechanism for passing information from Consumer to Producer in and Endp
wtam Apr 22, 2008 9:44 AM (in response to eamdwyer)I don't see anything wrong with putting the data in the Exchange. Is the data is guaranteed to be there when the producer reads the exchange? I believe so. Have you tried it to see if it works? I am not too familiar with how the Camel interceptor works. Maybe someone could provide information on Camel interceptor but I think Camel interceptor can access the Exchange as well.
-
4. Re: Mechanism for passing information from Consumer to Producer in and Endp
eamdwyer Apr 22, 2008 10:31 AM (in response to eamdwyer)test
Edited by: eamdwyer on Apr 22, 2008 10:31 AM
-
5. Re: Mechanism for passing information from Consumer to Producer in and Endp
eamdwyer Apr 22, 2008 10:30 AM (in response to eamdwyer)Some psuedo code to try illustrate the problem :
if you could imagine that my Camel Cxf Soap over HTTP endpoint has a cxf type MyInInterceptor and a cxf type MyOutInterceptor and they are configured to intercept Soap messages going in and out of this endpoint.
The MyInInterceptor is part of the Camel CXF Consumer invoation chain and intercepts the request from the client. The cxf handleMesage code for this interceptor could look like
public void handleMessage(SoapMessage msg) throws Fault {
String userName = getUserNameFromSoapMessage(msg);
String password = getPasswordFromSoapMessage(msg);
String token = authenticate(userName, password);
//Now how can I make this token available to the outbout MyOutInterceptor??
//Can I do something like
Exchange myExchange = msg.getExchange();
myExchange.setProperty("token", token);
// I know that myExchange above is of type CxfExchange and not a Camel Exchange, but the two objects
//are linked together in code AT THE MOMENT - will they always be?
.... // rest of handleMessage
}
MyOutInterceptor would look like
public void handleMessage(SoapMessage msg) throws Fault {
Exchange myExchange = msg.getExchange();
String token = (String)myExchange.getProperty("token");
//add the token to the out bound message
.... // rest of handleMessage
}
In addition to this a CAMEL InterceptorProcessor could then possible have
void process(Exchange exchange) {
Exchange myExchange = exchange.getExchange();
String token = (String)myExchange.getProperty("token");
// Do some logic in this processor based on the token value
}
Edited by: eamdwyer on Apr 22, 2008 10:28 AM
-
6. Re: Mechanism for passing information from Consumer to Producer in and Endp
willem.jiang Apr 24, 2008 9:13 AM (in response to eamdwyer)If you have a chance to look at the CamelInvoker[1]'s Object invoke(Exchange exchange, Object o) method, you can get the answer
The parameter could be an instance of List class or an Object due to the WSDL operation's parameter definition.
You can also find the code example[2] to should how to set the CXF producer invocation parameter.
https://svn.apache.org/repos/asf/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CamelInvoker.java
https://svn.apache.org/repos/asf/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java