sonu131
sonu131

Reputation: 157

How to set payload as constructor-arg value in service-activator

I've started with SI and kind of stuck right now as we want to use SI in one of our existing project avoiding changes where we can.

A bean which we would be using as a service activator accepts an constructor argument of a java object.

that object is in the payload but then I'm unable to set it using inner bean usage of service-activator

<service-activator input-channel="ADMIN_TEST_CONNECTION" method="testConnection">
  <beans:bean class="mypackage.request.AdminRequestProcessor">
                <beans:constructor-arg value="payload"/>
            </beans:bean>
 </service-activator>

it's complaining about Could not convert argument value of type [java.lang.String] to required type.

Please help in how to access payload and set it as an constructor argument.

If I go via non- constructor arg route and change existing java object then it works with this call in the service activator

expression="@bean.testConnection(payload)"/>

but I don't wish you to change the existing java code until there is no other way.

Upvotes: 0

Views: 510

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121177

I think you don't have choice unless change something or add code around existing.

Service-Activator performs its functionality against each incoming message in the input-channel. And that functionality is exactly method invocation where Message is used as a context for method arguments.

Not sure what you are going to do with that payload, but that doesn't look correct to use statefull object like your AdminRequestProcessor. Just don't forget that you may have many incoming message, but service-activator should be consistent.

Plus don't forget that <beans:bean> is singleton, so your AdminRequestProcessor is instantiated only once.

Looking to your sample I'd suggest something like this:

expression="new AdminRequestProcessor(payload).testConnection()"/>

If you really don't want to change anything in your code.

Everything rest you can find in the Reference Manual.

Upvotes: 0

Related Questions