Thanks for your reply,
As I said in the earlier mail, the If I do not set the DONE status The
message is sent twice to Camel SU.
Based on you recommendation I modified the "inOutExchange" created using the
client to set the DONE status.
Problem of sending the request twice got resolved when I put the condition
on the bean to execute only if exchange status is ACTIVE. Is this the right
approach or is their any drawbacks of it.
Following is the code snippet of bean:
public void onMessageExchange(MessageExchange exchange) throws
MessagingException {
try {
if (exchange.getStatus() != ExchangeStatus.ACTIVE){
return;
}
NormalizedMessage message = exchange.getMessage("in");
//message.setProperty("userPrincipals",message.getSecuritySubject().getPrincipals());
Set<Principal> principals =
message.getSecuritySubject().getPrincipals();
List roles = new ArrayList();
String roleString = "";
Iterator<Principal> principalIterator = principals.iterator();
while (principalIterator.hasNext()) {
Principal element = (Principal)
principalIterator.next();
roles.add(element.getName());
roleString += element.getName();
if(principalIterator.hasNext()) {
roleString += ",";
}
}
ClientFactory factory = (ClientFactory) new
InitialContext().lookup(ClientFactory.DEFAULT_JNDI_NAME);
ServiceMixClient client = factory.createClient();
Destination destination =
client.createDestination("service:http://servicemix.in2m.com/operations/changepassword/validateService");
InOut inOutExchange = destination.createInOutExchange();
inOutExchange.setProperty("org.apache.servicemix.correlationId",
exchange.getProperty("org.apache.servicemix.correlationId"));
NormalizedMessage inMessage = inOutExchange.getInMessage();
inMessage.setProperty("userPrincipals",roles);
inMessage.setContent(message.getContent());
client.sendSync(inOutExchange);
inOutExchange.setStatus(ExchangeStatus.DONE);
channel.send(exchange);
} catch (Exception e) {
logger.error("Error in processing message ",e);
}
}
Also another query, when I was trying to set the out message recieved from
inOutExchange to parent "exchange" it says "out" not supported. Any idea on
why it is so ? Based on your suggestion and bean examples in website this
should be possible.
Thanks,
Sandeep
Gert Vanthienen wrote:
>
> Sandeep Reddy,
>
> In order to send a response from your bean SU, you should set the 'out'
> normalized message content from within your Bean SU and send that. The
> DONE status should be set by the consumer in the case of an InOut
> exchange (have a look at the diagram on
> http://servicemix.apache.org/5-jbi.html#5.JBI-NormalizedMessageRouter --
> Invocation Example).
>
> If you have problems with MEP handling when interacting between Camel
> and JBI, you can always append ?mep=in-only, ?mep=in-out, ... to the
> jbi: endpoints in Camel to make it a little more explicit. Also make
> sure that you have the latest SNAPSHOT of the servicemix-camel component
> -- some bugs with regards to MEP handling were fixed very recently.
>
> Regards,
>
> Gert
>
> sandeep reddy wrote:
>> I have servicemix-camel 3.2.2 snapshot in my ServiceMix 3.2.1 instance.
>>
>> Sample flow:
>> Application 1 --> Http-SU(consumer) --> Bean-SU --> Camel-SU -->
>> Http-SU(provider) --> Application 2
>>
>> My Bean-SU gets message from Http-SU, adds properties to Normalized
>> message
>> and forwards the message to Camel-SU. My property is a collection object
>> which contains string elements. Following is the code of bean:
>>
>> public void onMessageExchange(MessageExchange exchange) throws
>> MessagingException {
>> try {
>> NormalizedMessage message = exchange.getMessage("in");
>> ServiceEndpoint endpoint = exchange.getEndpoint();
>> message.setProperty("userPrincipals",
>> message.getSecuritySubject().getPrincipals());
>> Set<Principal> principals =
>> message.getSecuritySubject().getPrincipals();
>> List roles = new ArrayList();
>> Iterator<Principal> principalIterator = principals.iterator();
>> while (principalIterator.hasNext()) {
>> Principal element = (Principal) principalIterator.next();
>> roles.add(element.getName());
>> }
>>
>> ClientFactory factory = (ClientFactory) new
>> InitialContext().lookup(ClientFactory.DEFAULT_JNDI_NAME);
>> ServiceMixClient client = factory.createClient();
>> Destination destination =
>> client.createDestination("service:http://servicemix.in2m.com/operations/changepassword/validateService");
>> InOut inOutExchange = destination.createInOutExchange();
>> NormalizedMessage inMessage = inOutExchange.getInMessage();
>> inMessage.setProperty("userPrincipals",roles);
>> inMessage.setContent(message.getContent());
>> client.sendSync(inOutExchange);
>>
>> exchange.setStatus(ExchangeStatus.DONE);
>> channel.send(exchange);
>>
>> } catch (Exception e) {
>> logger.debug(e);
>> System.out.println("Exception occured " + e.getMessage());
>> }
>>
>> }
>>
>>
>> I am able to route message to specific service based on the property from
>> Camel using header("userPrincipals").contains("portal"). But the problem
>> is
>> that an exception occurs in the bean. My HTTP-SU Consumer never receives
>> a
>> response and eventually times out.
>>
>> If I do not set the DONE status then the message is sent twice to
>> Camel-SU.
>>
>> Following is the error log:
>> --------------------------------------------------------------------------------------------------------------------------------------------------------
>>
>> DEBUG - JettyContextManager - Dispatching job:
>> [EMAIL PROTECTED],io=0,w=true,b=false|false]
>> DEBUG - JettyContextManager - Dispatching job:
>> [EMAIL PROTECTED],io=1,w=true,b=false|false]
>> DEBUG - JAASAuthenticationService - Authenticating 'smx' with 'smx'
>> DEBUG - HttpComponent - Receiving HTTP request: POST
>> /changepassword/ HTTP/1.1
>> appName: Director
>> Authorization: Basic c214OnNteA==
>> User-Agent: Jakarta Commons-HttpClient/3.1
>> Host: localhost:8192
>> Content-Length: 177
>>
>>
>> DEBUG - HttpComponent - Created correlation id:
>> ID:192.168.2.53-11aa5e1886b-4:29
>> DEBUG - DeliveryChannelImpl - Send
>> ID:192.168.2.53-11aa5e1886b-4:29 in DeliveryChannel{servicemix-http}
>> DEBUG - SedaFlow - Called Flow send
>> DEBUG - SedaQueue -
>> [EMAIL PROTECTED] dequeued
>> exchange: InOut[
>> id: ID:192.168.2.53-11aa5e1886b-4:29
>> status: Active
>> role: provider
>> service:
>> {http://servicemix.in2m.com/operations/changepassword}BeanService
>> endpoint: beanEndpoint
>> in: <?xml version="1.0" encoding="UTF-8"?><request
>> xmlns="http://www.finicity.com">
>> <updatePassword>
>> <userName>sandeep37</userName>
>> <password>mvelopes</password>
>> </updatePassword>
>> </request>
>> ]
>> DEBUG - BeanComponent - Received exchange: status:
>> Active,
>> role: provider
>> DEBUG - BeanComponent - Retrieved correlation id:
>> ID:192.168.2.53-11aa5e1886b-4:29
>> INFO - JBIContainer - Activating component for:
>> [container=ServiceMix,name=ID:192.168.2.53-11aa5e1886b-0:38] with
>> service:
>> null component:
>> [EMAIL PROTECTED]
>> INFO - ComponentMBeanImpl - Initializing component:
>> ID:192.168.2.53-11aa5e1886b-0:38
>> INFO - ComponentMBeanImpl - Starting component:
>> ID:192.168.2.53-11aa5e1886b-0:38
>> DEBUG - HttpComponent - Suspending continuation for
>> exchange: ID:192.168.2.53-11aa5e1886b-4:29
>> DEBUG - DeliveryChannelImpl - SendSync
>> ID:192.168.2.53-11aa5e1886b-118:0 in
>> DeliveryChannel{ID:192.168.2.53-11aa5e1886b-0:38}
>> DEBUG - SedaFlow - Called Flow send
>> DEBUG - SedaQueue -
>> [EMAIL PROTECTED] dequeued
>> exchange: InOut[
>> id: ID:192.168.2.53-11aa5e1886b-118:0
>> status: Active
>> role: provider
>> service:
>> {http://servicemix.in2m.com/operations/changepassword}validateService
>> endpoint: validateEndpoint
>> in: <?xml version="1.0" encoding="UTF-8"?><request
>> xmlns="http://www.finicity.com">
>> <updatePassword>
>> <userName>sandeep37</userName>
>> <password>mvelopes</password>
>> </updatePassword>
>> </request>
>> ]
>> DEBUG - CamelJbiComponent - Received exchange: status:
>> Active,
>> role: provider
>> DEBUG - CamelJbiComponent - Retrieved correlation id: null
>> DEBUG - CamelJbiEndpoint - Received exchange: InOut[
>> id: ID:192.168.2.53-11aa5e1886b-118:0
>> status: Active
>> role: provider
>> service:
>> {http://servicemix.in2m.com/operations/changepassword}validateService
>> endpoint: validateEndpoint
>> in: <?xml version="1.0" encoding="UTF-8"?><request
>> xmlns="http://www.finicity.com">
>> <updatePassword>
>> <userName>sandeep37</userName>
>> <password>mvelopes</password>
>> </updatePassword>
>> </request>
>> ]
>> DEBUG - DeliveryChannelImpl - Waiting for exchange
>> ID:192.168.2.53-11aa5e1886b-118:0 (16e05db) to be answered in
>> DeliveryChannel{ID:192.168.2.53-11aa5e1886b-0:38} from sendSync
>> DEBUG - DeliveryChannelImpl - SendSync
>> ID:192.168.2.53-11aa5e1886b-10:80 in DeliveryChannel{servicemix-camel}
>> DEBUG - SedaFlow - Called Flow send
>> DEBUG - SedaQueue -
>> [EMAIL PROTECTED] dequeued
>> exchange: InOut[
>> id: ID:192.168.2.53-11aa5e1886b-10:80
>> status: Active
>> role: provider
>> service:
>> {http://servicemix.in2m.com/operations/changepassword}routingService
>> endpoint: camel192-168-2-53-11aa5e1886b-20-22
>> in: <?xml version="1.0" encoding="UTF-8"?><request
>> xmlns="http://www.finicity.com">
>> <updatePassword>
>> <userName>sandeep37</userName>
>> <password>mvelopes</password>
>> </updatePassword>
>> </request>
>> ]
>> DEBUG - CamelJbiComponent - Received exchange: status:
>> Active,
>> role: provider
>> DEBUG - CamelJbiComponent - Retrieved correlation id: null
>> DEBUG - CamelJbiEndpoint - Received exchange: InOut[
>> id: ID:192.168.2.53-11aa5e1886b-10:80
>> status: Active
>> role: provider
>> service:
>> {http://servicemix.in2m.com/operations/changepassword}routingService
>> endpoint: camel192-168-2-53-11aa5e1886b-20-22
>> in: <?xml version="1.0" encoding="UTF-8"?><request
>> xmlns="http://www.finicity.com">
>> <updatePassword>
>> <userName>sandeep37</userName>
>> <password>mvelopes</password>
>> </updatePassword>
>> </request>
>> ]
>> DEBUG - DeliveryChannelImpl - SendSync
>> ID:192.168.2.53-11aa5e1886b-10:81 in DeliveryChannel{servicemix-camel}
>> DEBUG - SedaFlow - Called Flow send
>> DEBUG - DeliveryChannelImpl - Waiting for exchange
>> ID:192.168.2.53-11aa5e1886b-10:81 (1346394) to be answered in
>> DeliveryChannel{servicemix-camel} from sendSync
>> DEBUG - SedaQueue -
>> [EMAIL PROTECTED] dequeued
>> exchange: InOut[
>> id: ID:192.168.2.53-11aa5e1886b-10:81
>> status: Active
>> role: provider
>> service:
>> {http://servicemix.in2m.com/operations/changepassword}PortalService
>> endpoint: PortalEndpoint
>> in: <?xml version="1.0" encoding="UTF-8"?><request
>> xmlns="http://www.finicity.com">
>> <updatePassword>
>> <userName>sandeep37</userName>
>> <password>mvelopes</password>
>> </updatePassword>
>> </request>
>> ]
>> DEBUG - HttpComponent - Received exchange: status:
>> Active,
>> role: provider
>> DEBUG - HttpComponent - Retrieved correlation id: null
>> DEBUG - DefaultHttpParams - Set parameter
>> http.method.retry-handler =
>> [EMAIL PROTECTED]
>> DEBUG - MultiThreadedHttpConnectionManager -
>> HttpConnectionManager.getConnection: config =
>> HostConfiguration[host=http://192.168.2.71], timeout = 0
>> DEBUG - MultiThreadedHttpConnectionManager - Getting free connection,
>> hostConfig=HostConfiguration[host=http://192.168.2.71]
>> DEBUG - HttpConnection - Connection is stale, closing...
>> DEBUG - HttpConnection - Open connection to
>> 192.168.2.71:80
>> DEBUG - DeliveryChannelImpl - Waiting for exchange
>> ID:192.168.2.53-11aa5e1886b-10:80 (1aa2cc6) to be answered in
>> DeliveryChannel{servicemix-camel} from sendSync
>> DEBUG - HttpMethodBase - Adding Host request header
>> DEBUG - EntityEnclosingMethod - Request body sent
>> DEBUG - HttpMethodBase - Cookie accepted: "$Version=0;
>> 82de8fdbf7056e00d8556195416f75ba=bcd8c3d291c2ba4634164a892caea611;
>> $Path=/"
>> DEBUG - DeliveryChannelImpl - Send
>> ID:192.168.2.53-11aa5e1886b-10:81 in DeliveryChannel{servicemix-http}
>> DEBUG - SedaFlow - Called Flow send
>> DEBUG - HttpMethodBase - Resorting to protocol version
>> default close connection policy
>> DEBUG - HttpMethodBase - Should NOT close connection,
>> using
>> HTTP/1.1
>> DEBUG - HttpConnection - Releasing connection back to
>> connection manager.
>> DEBUG - MultiThreadedHttpConnectionManager - Freeing connection,
>> hostConfig=HostConfiguration[host=http://192.168.2.71]
>> DEBUG - IdleConnectionHandler - Adding connection at:
>> 1213980410067
>> DEBUG - MultiThreadedHttpConnectionManager - Notifying no-one, there are
>> no
>> waiting threads
>> DEBUG - SedaQueue -
>> [EMAIL PROTECTED] dequeued
>> exchange: InOut[
>> id: ID:192.168.2.53-11aa5e1886b-10:81
>> status: Active
>> role: consumer
>> service:
>> {http://servicemix.in2m.com/operations/changepassword}PortalService
>> endpoint: PortalEndpoint
>> in: <?xml version="1.0" encoding="UTF-8"?><request
>> xmlns="http://www.finicity.com">
>> <updatePassword>
>> <userName>sandeep37</userName>
>> <password>mvelopes</password>
>> </updatePassword>
>> </request>
>> out: <?xml version="1.0"
>> encoding="UTF-8"?><Response><status>error</status><message>Service is
>> not
>> available on portal.</message></Response>
>> ]
>> DEBUG - DeliveryChannelImpl - Notifying exchange
>> ID:192.168.2.53-11aa5e1886b-10:81(1346394) in
>> DeliveryChannel{servicemix-camel} from processInboundSynchronousExchange
>> DEBUG - DeliveryChannelImpl - Notified:
>> ID:192.168.2.53-11aa5e1886b-10:81(1346394) in
>> DeliveryChannel{servicemix-camel} from sendSync
>> DEBUG - DeliveryChannelImpl - Send
>> ID:192.168.2.53-11aa5e1886b-10:81 in DeliveryChannel{servicemix-camel}
>> DEBUG - SedaFlow - Called Flow send
>> DEBUG - DeliveryChannelImpl - Send
>> ID:192.168.2.53-11aa5e1886b-10:80 in DeliveryChannel{servicemix-camel}
>> DEBUG - SedaFlow - Called Flow send
>> DEBUG - SedaQueue -
>> [EMAIL PROTECTED] dequeued
>> exchange: InOut[
>> id: ID:192.168.2.53-11aa5e1886b-10:80
>> status: Active
>> role: consumer
>> service:
>> {http://servicemix.in2m.com/operations/changepassword}routingService
>> endpoint: camel192-168-2-53-11aa5e1886b-20-22
>> in: <?xml version="1.0" encoding="UTF-8"?><request
>> xmlns="http://www.finicity.com">
>> <updatePassword>
>> <userName>sandeep37</userName>
>> <password>mvelopes</password>
>> </updatePassword>
>> </request>
>> out: <?xml version="1.0"
>> encoding="UTF-8"?><Response><status>error</status><message>Service is
>> not
>> available on portal.</message></Response>
>> ]
>> DEBUG - DeliveryChannelImpl - Notifying exchange
>> ID:192.168.2.53-11aa5e1886b-10:80(1aa2cc6) in
>> DeliveryChannel{servicemix-camel} from processInboundSynchronousExchange
>> DEBUG - SedaQueue -
>> [EMAIL PROTECTED] dequeued
>> exchange: InOut[
>> id: ID:192.168.2.53-11aa5e1886b-10:81
>> status: Done
>> role: provider
>> service:
>> {http://servicemix.in2m.com/operations/changepassword}PortalService
>> endpoint: PortalEndpoint
>> in: <?xml version="1.0" encoding="UTF-8"?><request
>> xmlns="http://www.finicity.com">
>> <updatePassword>
>> <userName>sandeep37</userName>
>> <password>mvelopes</password>
>> </updatePassword>
>> </request>
>> out: <?xml version="1.0"
>> encoding="UTF-8"?><Response><status>error</status><message>Service is
>> not
>> available on portal.</message></Response>
>> ]
>> DEBUG - HttpComponent - Received exchange: status: Done,
>> role: provider
>> DEBUG - HttpComponent - Retrieved correlation id: null
>> DEBUG - DeliveryChannelImpl - Notified:
>> ID:192.168.2.53-11aa5e1886b-10:80(1aa2cc6) in
>> DeliveryChannel{servicemix-camel} from sendSync
>> DEBUG - DeliveryChannelImpl - Send
>> ID:192.168.2.53-11aa5e1886b-10:80 in DeliveryChannel{servicemix-camel}
>> DEBUG - SedaFlow - Called Flow send
>> DEBUG - DeliveryChannelImpl - Send
>> ID:192.168.2.53-11aa5e1886b-118:0 in DeliveryChannel{servicemix-camel}
>> DEBUG - SedaFlow - Called Flow send
>> DEBUG - SedaQueue -
>> [EMAIL PROTECTED] dequeued
>> exchange: InOut[
>> id: ID:192.168.2.53-11aa5e1886b-118:0
>> status: Active
>> role: consumer
>> service:
>> {http://servicemix.in2m.com/operations/changepassword}validateService
>> endpoint: validateEndpoint
>> in: <?xml version="1.0" encoding="UTF-8"?><request
>> xmlns="http://www.finicity.com">
>> <updatePassword>
>> <userName>sandeep37</userName>
>> <password>mvelopes</password>
>> </updatePassword>
>> </request>
>> out: <?xml version="1.0"
>> encoding="UTF-8"?><Response><status>error</status><message>Service is
>> not
>> available on portal.</message></Response>
>> ]
>> DEBUG - DeliveryChannelImpl - Notifying exchange
>> ID:192.168.2.53-11aa5e1886b-118:0(16e05db) in
>> DeliveryChannel{ID:192.168.2.53-11aa5e1886b-0:38} from
>> processInboundSynchronousExchange
>> DEBUG - SedaQueue -
>> [EMAIL PROTECTED] dequeued
>> exchange: InOut[
>> id: ID:192.168.2.53-11aa5e1886b-10:80
>> status: Done
>> role: provider
>> service:
>> {http://servicemix.in2m.com/operations/changepassword}routingService
>> endpoint: camel192-168-2-53-11aa5e1886b-20-22
>> in: <?xml version="1.0" encoding="UTF-8"?><request
>> xmlns="http://www.finicity.com">
>> <updatePassword>
>> <userName>sandeep37</userName>
>> <password>mvelopes</password>
>> </updatePassword>
>> </request>
>> out: <?xml version="1.0"
>> encoding="UTF-8"?><Response><status>error</status><message>Service is
>> not
>> available on portal.</message></Response>
>> ]
>> DEBUG - CamelJbiComponent - Received exchange: status: Done,
>> role: provider
>> DEBUG - CamelJbiComponent - Retrieved correlation id: null
>> DEBUG - DeliveryChannelImpl - Notified:
>> ID:192.168.2.53-11aa5e1886b-118:0(16e05db) in
>> DeliveryChannel{ID:192.168.2.53-11aa5e1886b-0:38} from sendSync
>> DEBUG - DeliveryChannelImpl - Send
>> ID:192.168.2.53-11aa5e1886b-4:29 in DeliveryChannel{servicemix-bean}
>> DEBUG - DeliveryChannelImpl - Exception processing:
>> ID:192.168.2.53-11aa5e1886b-4:29 in DeliveryChannel{servicemix-bean}
>> Exception occured illegal exchange status: done
>> DEBUG - JettyContextManager - Dispatching job:
>> [EMAIL PROTECTED],pending,expired
>> DEBUG - HttpComponent - Receiving HTTP request: POST
>> /changepassword/ HTTP/1.1
>> appName: Director
>> Authorization: Basic c214OnNteA==
>> User-Agent: Jakarta Commons-HttpClient/3.1
>> Host: localhost:8192
>> Content-Length: 177
>>
>>
>> DEBUG - JettyContextManager - Dispatching job:
>> [EMAIL PROTECTED],io=1,w=true,b=false|false]
>>
>> --------------------------------------------------------------------------------------------------------------------------------------------------------
>>
>> Please help.
>>
>> Thanks,
>> Sandeep Reddy
>>
>>
>
>
>
> -----
> ---
> Gert Vanthienen
> http://www.anova.be
>
--
View this message in context:
http://www.nabble.com/Problem-regarding-Custom-Bean-tp18033529p18066544.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.