bean method return doesn't work with a single parameter

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

bean method return doesn't work with a single parameter

catshout
Dear all,

I've defined a route as following (snippet) ..

	<bean id="configuration" class="de.ag.cas.sib.configuration.Configuration" />
	<bean id="headerWriter" class="de.ag.cas.sib.eventprocessor.HeaderWriter" />
	<bean id="eventPublisher" class="de.ag.cas.sib.eventprocessor.EventPublisher" />

	<camelContext id="routes" xmlns="http://camel.apache.org/schema/blueprint">

		<route id="File2AMQ">
			<from uri="file:/home/cas/camel/OUT" />
			<bean ref="headerWriter" method="setStartTime" />
			<bean ref="headerWriter" method="setId1('bean:configuration?method=getId()')" />
			<bean ref="headerWriter" method="setId2('', 'bean:configuration?method=getId()')" />

In the bean HeaderWriter are defined two methods like ..

	public void setId1(String value, Exchange exchange) {
		// copy existing message
		exchange.setOut(exchange.getIn());
		log.info("setId1 value: " + value);

		if (exchange.getIn().getHeader(Configuration.ID_STRING) == null) {
			exchange.getOut().setHeader(Configuration.ID_STRING, value);
		}
	}

	public void setId2(String dummy, String value, Exchange exchange) {
		// copy existing message
		exchange.setOut(exchange.getIn());
		log.info("setId2 value: " + value);

		if (exchange.getIn().getHeader(Configuration.ID_STRING) == null) {
			exchange.getOut().setHeader(Configuration.ID_STRING, value);
		}
	}

The Configuration bean is defined as ..

package de.ag.cas.sib.configuration;

public class Configuration {
	// store id
	private static String id;

	public static String getId() {
		return Configuration.id;
	}

	public static void setId(String id) {
		Configuration.id = id;
	}
}

The log says when the route has been executed ..

2015-08-18 12:07:06,718 | INFO  | me/cas/camel/OUT | EventPublisher                   | 251 - SIBEventProcessor - 1.0.0 | setId1 value: bean:configuration?method=getId()
2015-08-18 12:07:06,718 | INFO  | me/cas/camel/OUT | EventPublisher                   | 251 - SIBEventProcessor - 1.0.0 | setId2 value: SIB.0001
2

The getId() returns the value "SIB.0001". The method "setId1" doesn't resolve the "bean:configuration?method=getId()" expression, the method "setId2" does.

Does anyone has an explanation for this behaviour? Did I miss anything?

Thanks in advance for any hints.
- Gerald
Reply | Threaded
Open this post in threaded view
|

Re: bean method return doesn't work with a single parameter

Achim Nierbeck
Hi,

I don't think you intended on using the in-out message pattern, it looks
more like a in-only pattern.
Therefore make sure you only use the exchange.getIn for all your retrieving
and setting of headers.

regards, Achim

2015-08-18 12:20 GMT+02:00 catshout <[hidden email]>:

> Dear all,
>
> I've defined a route as following (snippet) ..
>
>
>
> In the bean HeaderWriter are defined two methods like ..
>
>
>
> The Configuration bean is defined as ..
>
>
>
> The log says when the route has been executed ..
>
> 2015-08-18 12:07:06,718 | INFO  | me/cas/camel/OUT | EventPublisher
> | 251 - SIBEventProcessor - 1.0.0 | setId1 value:
> bean:configuration?method=getId()
> 2015-08-18 12:07:06,718 | INFO  | me/cas/camel/OUT | EventPublisher
> | 251 - SIBEventProcessor - 1.0.0 | setId2 value: SIB.0001
> 2
>
> The getId() returns the value "SIB.0001". The method "setId1" doesn't
> resolve the "bean:configuration?method=getId()" expression, the method
> "setId2" does.
>
> Does anyone has an explanation for this behaviour? Did I miss anything?
>
> Thanks in advance for any hints.
> - Gerald
>
>
>
> --
> View this message in context:
> http://servicemix.396122.n5.nabble.com/bean-method-return-doesn-t-work-with-a-single-parameter-tp5722885.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>



--

Apache Member
Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
Project Lead
blog <http://notizblog.nierbeck.de/>
Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS>

Software Architect / Project Manager / Scrum Master