Return-Path: Delivered-To: apmail-camel-users-archive@www.apache.org Received: (qmail 96786 invoked from network); 18 May 2009 13:52:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 May 2009 13:52:28 -0000 Received: (qmail 34288 invoked by uid 500); 18 May 2009 13:52:27 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 34246 invoked by uid 500); 18 May 2009 13:52:27 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 34235 invoked by uid 99); 18 May 2009 13:52:27 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 May 2009 13:52:27 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of claus.ibsen@gmail.com designates 209.85.128.187 as permitted sender) Received: from [209.85.128.187] (HELO fk-out-0910.google.com) (209.85.128.187) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 May 2009 13:52:15 +0000 Received: by fk-out-0910.google.com with SMTP id k31so1619831fkk.4 for ; Mon, 18 May 2009 06:51:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=R+Sz2A3m1oU86E/j9lAeaqB/DimKUEYw7DpOQt2nMSU=; b=CIe0sbugImXGssbkz8Xd8Wiee9ZFkp5FQYs7UF+wufQvADytAxCq60tbIyUatLcp3s yopu+wHNA0PPsFOALWfJmvmDsEUxYd0QtvW6r9wiCos2ynqoNLZV9+nfD86A/OWYm8+k NtzwVpQfsytnfzMj0mYRuLbqSWl5g3Vs3s+mk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=HieqtuwjCHDKyre/e0ZxGwhcfwA2PmbU6EjrUA5Skm+rzUF52mEbGxsD27M8BOqnC9 TxaRxrytyiqxsgLbg5ZClipMNqNaStqrQp4WfPjij2KS0MOjONS6U8F4dXZ4U3d/MuBI KostixbBrALGhc3l/QluqS3ZdIEx+CxQUGd4E= MIME-Version: 1.0 Received: by 10.223.113.132 with SMTP id a4mr4279950faq.75.1242654715338; Mon, 18 May 2009 06:51:55 -0700 (PDT) In-Reply-To: <23595896.post@talk.nabble.com> References: <23588615.post@talk.nabble.com> <5380c69c0905172130j80d69a6i3b07fc27d47e1d65@mail.gmail.com> <23593558.post@talk.nabble.com> <5380c69c0905180208p1fd69e6ev728cd75b6de2ed6c@mail.gmail.com> <23595896.post@talk.nabble.com> From: Claus Ibsen Date: Mon, 18 May 2009 15:51:35 +0200 Message-ID: <5380c69c0905180651r7f4accb8v6a501a44b8055eec@mail.gmail.com> Subject: Re: Why does my JMS message type changes ? To: users@camel.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org On Mon, May 18, 2009 at 3:46 PM, uprooter wrote: > > I'm trying to implement what Willem suggested. > I'm trying to avoid unmarshaling the payload while still processing messa= ges > according to an unmarshalled data. > In order to do so I need to create a copy of the message, unmarshal it. A= nd > transfer it to a processor. > It just don't see how it fits in Java DSL. > Can you please demonstrate that part of creating a copy. unmarshalling an= d > transferring to a processor ? Maybe you can store a copy of the original payload and then route as before and when you are ready restore the body with the original payload. Something like this: from(x) // store the original payload in a exchange property so we can get it later .setPropery("original", body()) // TODO: do the unmarshal and then content based router // now when you are ready to use the original body to send to a topic then you can restore it .setBody(property("original")).to("activemq:topic:foo"); Or am I misunderstanding your use case? BTW: In a Processor you have full power, so you can do the JAXB stuff there= also public void process(Exchange exchange) { JAXBDataFormat df =3D new JAXBDataFormat(.... // and then use df to unmarshal } That gives you another option to try with. > > John. > > > Claus Ibsen-2 wrote: >> >> On Mon, May 18, 2009 at 10:53 AM, uprooter wrote: >>> >>> Many thanks to your both. >>> If I understand correctly, I need to set a header on my message and thi= s >>> header will be attached to my message. >> No you should in fact not. Keep what you got from the JMS topic in the >> body. >> >> What Willem suggested is a "trick" in case you need to store something >> as a kind of 2nd copy / backup you can use headers for that. >> >> >> When you use JMS as the transport then you cannot send any kind of >> data over JMS. In fact one must follow the JMS spec that have a set of >> limitations. >> >> A JMS message can contain >> - properties (is mapped to Camel IN headers) >> - payload (is mapped to Camel IN body) >> >> The JMS properties can only be simple or primitive types such as: >> String, Integer, etc. >> >> The JMS payload can be >> - TextMessage (mapped to String) >> - BytesMessage (mapped to byte[] and other kinds) >> - ObjectMessage (mapped to Serializable) >> etc. >> >> So when you route something to a JMS topic with >> (.to("activemq:topic:topic2") Camel will look at the IN body class >> type and determine the best kinda of JMS message to use. >> >> So if you want to force that to be TextMessage then you IN body class >> type must by java.lang.String. >> >> Using .convertBodyTo(String) before sending to the JMS topic you can >> enfore that. >> >> >> >>> >>> Unfortunately,After trying hard, I couldn't figure out how to add the >>> unmarshaled payload as header, and how to make my bean read that header= . >>> >>> I tried something like : >>> =A0 =A0from("topic1").setHeader("Student").end() >>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .choice() >>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0.when().method("mymethod= ","isstudent") >>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0.to("seda:a"); >>> >>> But I can't find anywhere to put unmarshal() on the header. >> No unmarshal works on BODY only. If you want to do that on a Header >> then you must do than yourself from eg a Processor or regular POJO >> class. >> >> >>> >>> >>> Claus Ibsen-2 wrote: >>>> >>>> On Mon, May 18, 2009 at 12:41 AM, uprooter wrote: >>>>> >>>>> Hello All. >>>>> I have this DSL that routes messages from topic1 to topic2. >>>>> The =A0messages on topic1 are marshaled POJOs and I can happily unmar= shal >>>>> them. >>>>> =A0from("topic1").unmarshal(jaxb).choice() >>>>> >>>>> =A0.when().method("mymethod","isStudent").to("topic2") >>>>> >>>>> The problem is that when I forward them to topic2 the payload is lost >>>>> and >>>>> instead of getting ActiveMQTextMessage I only get ActiveMQMessage >>>>> without >>>>> the text payload and I cannot cast them to TextMessage anymore. >>>>> (like, if I do from("topic1").to("topic2") everything works great but >>>>> unmashalling drops my payload somewhere) >>>>> >>>>> I don't want to marshal the data again. only to route them according = to >>>>> my >>>>> method. >>>>> Can you please help me figure this out? >>>>> Many thanks. >>>> >>>> As Willem pointed out you unmarshal the payload from topic1 to JAXB. >>>> And JAXB is a Java Object (not text). >>>> So when you send a JAXB object to a JMS destination (topic2) the JMS >>>> API will use javax.jms.ObjectMessage as the payload type. >>>> >>>> If you want to store it as text then you must convert the payload back >>>> to text. Either with marshal or convertBodyTo(String.class) etc. >>>> Depending if the JAXB can reverse its operation. >>>> >>>> >>>> Note: In Camel 2.0 we have added options to the JMS producer so you >>>> can enfore a specify JMS type to use, eg. >>>> .to("activemq:topic:topic2? jmsMessageType=3DText"); >>>> >>>> See more here from: Message Mapping between JMS and Camel >>>> http://camel.apache.org/jms.html >>>> >>>> >>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> View this message in context: >>>>> http://www.nabble.com/Why-does-my-JMS-message-type-changes---tp235886= 15p23588615.html >>>>> Sent from the Camel - Users mailing list archive at Nabble.com. >>>>> >>>>> >>>> >>>> >>>> >>>> -- >>>> Claus Ibsen >>>> Apache Camel Committer >>>> >>>> Open Source Integration: http://fusesource.com >>>> Blog: http://davsclaus.blogspot.com/ >>>> Twitter: http://twitter.com/davsclaus >>>> >>>> >>> >>> -- >>> View this message in context: >>> http://www.nabble.com/Why-does-my-JMS-message-type-changes---tp23588615= p23593558.html >>> Sent from the Camel - Users mailing list archive at Nabble.com. >>> >>> >> >> >> >> -- >> Claus Ibsen >> Apache Camel Committer >> >> Open Source Integration: http://fusesource.com >> Blog: http://davsclaus.blogspot.com/ >> Twitter: http://twitter.com/davsclaus >> >> > > -- > View this message in context: http://www.nabble.com/Why-does-my-JMS-messa= ge-type-changes---tp23588615p23595896.html > Sent from the Camel - Users mailing list archive at Nabble.com. > > --=20 Claus Ibsen Apache Camel Committer Open Source Integration: http://fusesource.com Blog: http://davsclaus.blogspot.com/ Twitter: http://twitter.com/davsclaus