Sending POJOs on Message Queues?

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

Sending POJOs on Message Queues?

Glen Mazza
Hello, I'm new to ActiveMQ messaging queues and unsure if I can place
and subsequently read POJO's from them.  I have no problems getting
Strings to work it's just using POJO's that is creating the problem for me.

Here's how I place a DoubleIt POJO on the queue in Camel:  

      ProducerTemplate template = context.createProducerTemplate();
      context.start();
      DoubleIt doubleIt = new DoubleIt();
      doubleIt.setNumberToDouble(5);
      template.sendBody("jms:queue:numbersToDouble", doubleIt);
      Thread.sleep(24000);
      context.stop();

Here's my route:
from("jms:queue:numbersToDouble").process(new DoubleItReader());

And here's my implementation of DoubleItReader:

public class DoubleItReader implements Processor {

   @Override
   public void process(Exchange e) {
      DoubleIt response = e.getIn().getBody(DoubleIt.class);      
      System.out.println("This was returned - Body: " +
response.getNumberToDouble());
   }

}

The above returns this error when I try to run Camel:
[INFO] [aultMessageListenerContainer-1] DefaultErrorHandler            
ERROR Failed delivery for exchangeId:
ID:gmazza-desktop-54558-1283773608538-2:1:1:1:1. Exhausted after
delivery attempt: 1 caught: java.lang.NullPointerException
[INFO] java.lang.NullPointerException
[INFO]     at camel.SOAPResponseReader.process(SOAPResponseReader.java:12)
[INFO]     at
org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsyncProcessorBridge.process(AsyncProcessorTypeConverter.java:50)
[INFO]     at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70)

If I try this conversion line instead:
DoubleIt response = (DoubleIt) e.getIn().getBody(Object.class);      

I get this error:
[INFO] Caused by: java.lang.ClassCastException:
org.apache.camel.component.jms.JmsMessage cannot be cast to
org.example.schema.doubleit.DoubleIt
[INFO]     at camel.SOAPResponseReader.process(SOAPResponseReader.java:11)
[INFO]     at
org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsyncProcessorBridge.process(AsyncProcessorTypeConverter.java:50)
[INFO]     at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70)
[INFO]     at
org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)

Does this mean I'm basically limited only to Strings (or to what?) for
the second parameter of the
"template.sendBody("jms:queue:numbersToDouble", ???)" command--or am I
doing something else wrong?

Thanks,
Glen

Reply | Threaded
Open this post in threaded view
|

Re: Sending POJOs on Message Queues?

tarjei
Hi,
On 09/06/2010 02:00 PM, Glen Mazza wrote:
> Hello, I'm new to ActiveMQ messaging queues and unsure if I can place
> and subsequently read POJO's from them.  I have no problems getting
> Strings to work it's just using POJO's that is creating the problem
> for me.
You should be able to send Serializable objects through the queues, but
I would like to suggest you look into other serialization methods like
Protobufs or JSON.

Is DoubleIt serializable?

Regards,
Tarjei

>
> Here's how I place a DoubleIt POJO on the queue in Camel:
>      ProducerTemplate template = context.createProducerTemplate();
>      context.start();
>      DoubleIt doubleIt = new DoubleIt();
>      doubleIt.setNumberToDouble(5);
>      template.sendBody("jms:queue:numbersToDouble", doubleIt);
>      Thread.sleep(24000);
>      context.stop();
>
> Here's my route:
> from("jms:queue:numbersToDouble").process(new DoubleItReader());
>
> And here's my implementation of DoubleItReader:
>
> public class DoubleItReader implements Processor {
>
>   @Override
>   public void process(Exchange e) {
>      DoubleIt response = e.getIn().getBody(DoubleIt.class);          
> System.out.println("This was returned - Body: " +
> response.getNumberToDouble());
>   }
>
> }
>
> The above returns this error when I try to run Camel:
> [INFO] [aultMessageListenerContainer-1] DefaultErrorHandler          
> ERROR Failed delivery for exchangeId:
> ID:gmazza-desktop-54558-1283773608538-2:1:1:1:1. Exhausted after
> delivery attempt: 1 caught: java.lang.NullPointerException
> [INFO] java.lang.NullPointerException
> [INFO]     at
> camel.SOAPResponseReader.process(SOAPResponseReader.java:12)
> [INFO]     at
> org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsyncProcessorBridge.process(AsyncProcessorTypeConverter.java:50)
>
> [INFO]     at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70)
>
>
> If I try this conversion line instead:
> DoubleIt response = (DoubleIt) e.getIn().getBody(Object.class);    
> I get this error:
> [INFO] Caused by: java.lang.ClassCastException:
> org.apache.camel.component.jms.JmsMessage cannot be cast to
> org.example.schema.doubleit.DoubleIt
> [INFO]     at
> camel.SOAPResponseReader.process(SOAPResponseReader.java:11)
> [INFO]     at
> org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsyncProcessorBridge.process(AsyncProcessorTypeConverter.java:50)
>
> [INFO]     at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70)
>
> [INFO]     at
> org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)
>
>
> Does this mean I'm basically limited only to Strings (or to what?) for
> the second parameter of the
> "template.sendBody("jms:queue:numbersToDouble", ???)" command--or am I
> doing something else wrong?
>
> Thanks,
> Glen
>


--
Regards / Med vennlig hilsen
Tarjei Huse
Mobil: 920 63 413

Reply | Threaded
Open this post in threaded view
|

Re: Sending POJOs on Message Queues?

Glen Mazza
No, it's not serializable, but I believe with some effort I can make it
so (The class is JAXB-generated  to support a web service call; JAXB has
some extensions to allow for serializability).  Right now I'm trying to
get the JAXB DataFormat to work (after sending the object to the queue I
plan on marshalling it to XML) just for the sake of seeing JAXB working.

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "numberToDouble"
})
@XmlRootElement(name = "DoubleIt")
public class DoubleIt {
    protected int numberToDouble;
    ... setter and getter for above...
}

I can look into JSON and/or Protobuf next -- is it primarily speed, or
ease-of-use (don't have to worry about making the class serializable),
or smaller message size that you recommend those other formats?

Thanks,
Glen

Tarjei Huse wrote:

> Hi,
> On 09/06/2010 02:00 PM, Glen Mazza wrote:
>  
>> Hello, I'm new to ActiveMQ messaging queues and unsure if I can place
>> and subsequently read POJO's from them.  I have no problems getting
>> Strings to work it's just using POJO's that is creating the problem
>> for me.
>>    
> You should be able to send Serializable objects through the queues, but
> I would like to suggest you look into other serialization methods like
> Protobufs or JSON.
>
> Is DoubleIt serializable?
>
> Regards,
> Tarjei
>  

Reply | Threaded
Open this post in threaded view
|

Re: Sending POJOs on Message Queues?

tarjei
On 09/06/2010 02:35 PM, Glen Mazza wrote:

> No, it's not serializable, but I believe with some effort I can make
> it so (The class is JAXB-generated  to support a web service call;
> JAXB has some extensions to allow for serializability).  Right now I'm
> trying to get the JAXB DataFormat to work (after sending the object to
> the queue I plan on marshalling it to XML) just for the sake of seeing
> JAXB working.
>
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "", propOrder = {
>    "numberToDouble"
> })
> @XmlRootElement(name = "DoubleIt")
> public class DoubleIt {
>    protected int numberToDouble;
>    ... setter and getter for above...
> }
>
> I can look into JSON and/or Protobuf next -- is it primarily speed, or
> ease-of-use (don't have to worry about making the class serializable),
> or smaller message size that you recommend those other formats?

In my experience using a format that is not dependent on both the client
and server having the same version of the java object class makes it far
easier to do updates and deployments. If you got an xml format that
works that may fit the bill just fine.

Another bonus is that you can use other languages to process the objects
if needed.

Regards,
Tarjei

>
> Thanks,
> Glen
>
> Tarjei Huse wrote:
>> Hi,
>> On 09/06/2010 02:00 PM, Glen Mazza wrote:
>>  
>>> Hello, I'm new to ActiveMQ messaging queues and unsure if I can place
>>> and subsequently read POJO's from them.  I have no problems getting
>>> Strings to work it's just using POJO's that is creating the problem
>>> for me.
>>>    
>> You should be able to send Serializable objects through the queues, but
>> I would like to suggest you look into other serialization methods like
>> Protobufs or JSON.
>>
>> Is DoubleIt serializable?
>>
>> Regards,
>> Tarjei
>>  
>


--
Regards / Med vennlig hilsen
Tarjei Huse
Mobil: 920 63 413

Reply | Threaded
Open this post in threaded view
|

Re: Sending POJOs on Message Queues?

Glen Mazza
Oh!  I was thinking of sending the POJO to the queue where it would be
subsequently read and marshalled into XML, but I can have the
client-side marshal into XML and send the XML to the queue instead.  
Makes sense...

Thanks again,
Glen

Tarjei Huse wrote:

> On 09/06/2010 02:35 PM, Glen Mazza wrote:
>  
>> No, it's not serializable, but I believe with some effort I can make
>> it so (The class is JAXB-generated  to support a web service call;
>> JAXB has some extensions to allow for serializability).  Right now I'm
>> trying to get the JAXB DataFormat to work (after sending the object to
>> the queue I plan on marshalling it to XML) just for the sake of seeing
>> JAXB working.
>>
>> @XmlAccessorType(XmlAccessType.FIELD)
>> @XmlType(name = "", propOrder = {
>>    "numberToDouble"
>> })
>> @XmlRootElement(name = "DoubleIt")
>> public class DoubleIt {
>>    protected int numberToDouble;
>>    ... setter and getter for above...
>> }
>>
>> I can look into JSON and/or Protobuf next -- is it primarily speed, or
>> ease-of-use (don't have to worry about making the class serializable),
>> or smaller message size that you recommend those other formats?
>>    
>
> In my experience using a format that is not dependent on both the client
> and server having the same version of the java object class makes it far
> easier to do updates and deployments. If you got an xml format that
> works that may fit the bill just fine.
>
> Another bonus is that you can use other languages to process the objects
> if needed.
>
> Regards,
> Tarjei
>
>  
>> Thanks,
>> Glen
>>
>> Tarjei Huse wrote:
>>    
>>> Hi,
>>> On 09/06/2010 02:00 PM, Glen Mazza wrote:
>>>  
>>>      
>>>> Hello, I'm new to ActiveMQ messaging queues and unsure if I can place
>>>> and subsequently read POJO's from them.  I have no problems getting
>>>> Strings to work it's just using POJO's that is creating the problem
>>>> for me.
>>>>    
>>>>        
>>> You should be able to send Serializable objects through the queues, but
>>> I would like to suggest you look into other serialization methods like
>>> Protobufs or JSON.
>>>
>>> Is DoubleIt serializable?
>>>
>>> Regards,
>>> Tarjei
>>>  
>>>      
>
>
>  

Reply | Threaded
Open this post in threaded view
|

Re: Sending POJOs on Message Queues?

Charles Moulliard
Hi Glen,

Using Camel, you can use marshal() or unmarshal() to transform objects -->
XML or XML --> objects

http://camel.apache.org/jaxb.html

Regards,

Charles Moulliard

Senior Enterprise Architect (J2EE, .NET, SOA)
Apache Camel - Karaf - ServiceMix Committer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Blog : http://cmoulliard.blogspot.com |  Twitter :
http://twitter.com/cmoulliard
Linkedin : http://www.linkedin.com/in/charlesmoulliard | Skype: cmoulliard


On Mon, Sep 6, 2010 at 2:51 PM, Glen Mazza <[hidden email]> wrote:

> Oh!  I was thinking of sending the POJO to the queue where it would be
> subsequently read and marshalled into XML, but I can have the client-side
> marshal into XML and send the XML to the queue instead.  Makes sense...
>
> Thanks again,
> Glen
>
>
> Tarjei Huse wrote:
>
>> On 09/06/2010 02:35 PM, Glen Mazza wrote:
>>
>>
>>> No, it's not serializable, but I believe with some effort I can make
>>> it so (The class is JAXB-generated  to support a web service call;
>>> JAXB has some extensions to allow for serializability).  Right now I'm
>>> trying to get the JAXB DataFormat to work (after sending the object to
>>> the queue I plan on marshalling it to XML) just for the sake of seeing
>>> JAXB working.
>>>
>>> @XmlAccessorType(XmlAccessType.FIELD)
>>> @XmlType(name = "", propOrder = {
>>>   "numberToDouble"
>>> })
>>> @XmlRootElement(name = "DoubleIt")
>>> public class DoubleIt {
>>>   protected int numberToDouble;
>>>   ... setter and getter for above...
>>> }
>>>
>>> I can look into JSON and/or Protobuf next -- is it primarily speed, or
>>> ease-of-use (don't have to worry about making the class serializable),
>>> or smaller message size that you recommend those other formats?
>>>
>>>
>>
>> In my experience using a format that is not dependent on both the client
>> and server having the same version of the java object class makes it far
>> easier to do updates and deployments. If you got an xml format that
>> works that may fit the bill just fine.
>>
>> Another bonus is that you can use other languages to process the objects
>> if needed.
>>
>> Regards,
>> Tarjei
>>
>>
>>
>>> Thanks,
>>> Glen
>>>
>>> Tarjei Huse wrote:
>>>
>>>
>>>> Hi,
>>>> On 09/06/2010 02:00 PM, Glen Mazza wrote:
>>>>
>>>>
>>>>> Hello, I'm new to ActiveMQ messaging queues and unsure if I can place
>>>>> and subsequently read POJO's from them.  I have no problems getting
>>>>> Strings to work it's just using POJO's that is creating the problem
>>>>> for me.
>>>>>
>>>>>
>>>> You should be able to send Serializable objects through the queues, but
>>>> I would like to suggest you look into other serialization methods like
>>>> Protobufs or JSON.
>>>>
>>>> Is DoubleIt serializable?
>>>>
>>>> Regards,
>>>> Tarjei
>>>>
>>>>
>>>
>>
>>
>>
>
>
Apache Committer / Sr. Pr. Consultant at FuseSource.com
Email: [hidden email]
Twitter : @cmoulliard, @fusenews
Blog : http://cmoulliard.blogspot.com
Reply | Threaded
Open this post in threaded view
|

Re: Sending POJOs on Message Queues?

Glen Mazza
But, just to confirm, do I need to make the JAXB objects serializable if
I plan on placing them on a queue or reading them from a queue?  If
that's the case (makes sense), I will update the Camel JAXB page to
highlight that--it presently doesn't say anything about serializability.

I'm trying to practice working with JAXB, e.g.,

      from("jms:queue:numbersToDouble")
      .marshal(jaxbFormat)
      .to("xslt://AddSOAPEnvelope.xsl")
      .to(CXF_URI)

One more thing--if I needed to make the JAXB object serializable for it
to work on a queue but didn't (or couldn't) do so, what could I replace
"from("jms:queue:numbersToDouble")" above with to start the route?  The
"direct" component?

Thanks,
Glen


Charles Moulliard wrote:

> Hi Glen,
>
> Using Camel, you can use marshal() or unmarshal() to transform objects -->
> XML or XML --> objects
>
> http://camel.apache.org/jaxb.html
>
> Regards,
>
> Charles Moulliard
>
> Senior Enterprise Architect (J2EE, .NET, SOA)
> Apache Camel - Karaf - ServiceMix Committer
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Blog : http://cmoulliard.blogspot.com |  Twitter :
> http://twitter.com/cmoulliard
> Linkedin : http://www.linkedin.com/in/charlesmoulliard | Skype: cmoulliard
>
>
> On Mon, Sep 6, 2010 at 2:51 PM, Glen Mazza <[hidden email]> wrote:
>
>  
>> Oh!  I was thinking of sending the POJO to the queue where it would be
>> subsequently read and marshalled into XML, but I can have the client-side
>> marshal into XML and send the XML to the queue instead.  Makes sense...
>>
>> Thanks again,
>> Glen
>>
>>
>> Tarjei Huse wrote:
>>
>>    
>>> On 09/06/2010 02:35 PM, Glen Mazza wrote:
>>>
>>>
>>>      
>>>> No, it's not serializable, but I believe with some effort I can make
>>>> it so (The class is JAXB-generated  to support a web service call;
>>>> JAXB has some extensions to allow for serializability).  Right now I'm
>>>> trying to get the JAXB DataFormat to work (after sending the object to
>>>> the queue I plan on marshalling it to XML) just for the sake of seeing
>>>> JAXB working.
>>>>
>>>> @XmlAccessorType(XmlAccessType.FIELD)
>>>> @XmlType(name = "", propOrder = {
>>>>   "numberToDouble"
>>>> })
>>>> @XmlRootElement(name = "DoubleIt")
>>>> public class DoubleIt {
>>>>   protected int numberToDouble;
>>>>   ... setter and getter for above...
>>>> }
>>>>
>>>> I can look into JSON and/or Protobuf next -- is it primarily speed, or
>>>> ease-of-use (don't have to worry about making the class serializable),
>>>> or smaller message size that you recommend those other formats?
>>>>
>>>>
>>>>        
>>> In my experience using a format that is not dependent on both the client
>>> and server having the same version of the java object class makes it far
>>> easier to do updates and deployments. If you got an xml format that
>>> works that may fit the bill just fine.
>>>
>>> Another bonus is that you can use other languages to process the objects
>>> if needed.
>>>
>>> Regards,
>>> Tarjei
>>>
>>>
>>>
>>>      
>>>> Thanks,
>>>> Glen
>>>>
>>>> Tarjei Huse wrote:
>>>>
>>>>
>>>>        
>>>>> Hi,
>>>>> On 09/06/2010 02:00 PM, Glen Mazza wrote:
>>>>>
>>>>>
>>>>>          
>>>>>> Hello, I'm new to ActiveMQ messaging queues and unsure if I can place
>>>>>> and subsequently read POJO's from them.  I have no problems getting
>>>>>> Strings to work it's just using POJO's that is creating the problem
>>>>>> for me.
>>>>>>
>>>>>>
>>>>>>            
>>>>> You should be able to send Serializable objects through the queues, but
>>>>> I would like to suggest you look into other serialization methods like
>>>>> Protobufs or JSON.
>>>>>
>>>>> Is DoubleIt serializable?
>>>>>
>>>>> Regards,
>>>>> Tarjei
>>>>>
>>>>>
>>>>>          
>>>
>>>      
>>    
>
>  

Reply | Threaded
Open this post in threaded view
|

AW: Sending POJOs on Message Queues?

Schneider Christian
Hi Glen,

if you use jaxb then your classes do not have to implement Serializable. Instead they of course need to be serializeable by jaxb.

Btw. if you want to call a webservice with the jaxb object (Seems so as you add the soap by using xslt) then you should take a look at the camel soap dataformat. http://camel.apache.org/soap.html



Greetings

Christian
 




Christian Schneider
Informationsverarbeitung
Business Solutions
Handel und Dispatching

Tel : +49-(0)721-63-15482

EnBW Systeme Infrastruktur Support GmbH
Sitz der Gesellschaft: Karlsruhe
Handelsregister: Amtsgericht Mannheim ­ HRB 108550
Vorsitzender des Aufsichtsrats: Dr. Bernhard Beck
Geschäftsführer: Jochen Adenau, Hans-Günther Meier


-----Ursprüngliche Nachricht-----
Von: Glen Mazza [mailto:[hidden email]]
Gesendet: Montag, 6. September 2010 16:15
An: [hidden email]
Betreff: Re: Sending POJOs on Message Queues?

But, just to confirm, do I need to make the JAXB objects serializable if
I plan on placing them on a queue or reading them from a queue?  If
that's the case (makes sense), I will update the Camel JAXB page to
highlight that--it presently doesn't say anything about serializability.

I'm trying to practice working with JAXB, e.g.,

      from("jms:queue:numbersToDouble")
      .marshal(jaxbFormat)
      .to("xslt://AddSOAPEnvelope.xsl")
      .to(CXF_URI)

One more thing--if I needed to make the JAXB object serializable for it
to work on a queue but didn't (or couldn't) do so, what could I replace
"from("jms:queue:numbersToDouble")" above with to start the route?  The
"direct" component?

Thanks,
Glen


Charles Moulliard wrote:

> Hi Glen,
>
> Using Camel, you can use marshal() or unmarshal() to transform objects -->
> XML or XML --> objects
>
> http://camel.apache.org/jaxb.html
>
> Regards,
>
> Charles Moulliard
>
> Senior Enterprise Architect (J2EE, .NET, SOA)
> Apache Camel - Karaf - ServiceMix Committer
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Blog : http://cmoulliard.blogspot.com |  Twitter :
> http://twitter.com/cmoulliard
> Linkedin : http://www.linkedin.com/in/charlesmoulliard | Skype: cmoulliard
>
>
> On Mon, Sep 6, 2010 at 2:51 PM, Glen Mazza <[hidden email]> wrote:
>
>  
>> Oh!  I was thinking of sending the POJO to the queue where it would be
>> subsequently read and marshalled into XML, but I can have the client-side
>> marshal into XML and send the XML to the queue instead.  Makes sense...
>>
>> Thanks again,
>> Glen
>>
>>
>> Tarjei Huse wrote:
>>
>>    
>>> On 09/06/2010 02:35 PM, Glen Mazza wrote:
>>>
>>>
>>>      
>>>> No, it's not serializable, but I believe with some effort I can make
>>>> it so (The class is JAXB-generated  to support a web service call;
>>>> JAXB has some extensions to allow for serializability).  Right now I'm
>>>> trying to get the JAXB DataFormat to work (after sending the object to
>>>> the queue I plan on marshalling it to XML) just for the sake of seeing
>>>> JAXB working.
>>>>
>>>> @XmlAccessorType(XmlAccessType.FIELD)
>>>> @XmlType(name = "", propOrder = {
>>>>   "numberToDouble"
>>>> })
>>>> @XmlRootElement(name = "DoubleIt")
>>>> public class DoubleIt {
>>>>   protected int numberToDouble;
>>>>   ... setter and getter for above...
>>>> }
>>>>
>>>> I can look into JSON and/or Protobuf next -- is it primarily speed, or
>>>> ease-of-use (don't have to worry about making the class serializable),
>>>> or smaller message size that you recommend those other formats?
>>>>
>>>>
>>>>        
>>> In my experience using a format that is not dependent on both the client
>>> and server having the same version of the java object class makes it far
>>> easier to do updates and deployments. If you got an xml format that
>>> works that may fit the bill just fine.
>>>
>>> Another bonus is that you can use other languages to process the objects
>>> if needed.
>>>
>>> Regards,
>>> Tarjei
>>>
>>>
>>>
>>>      
>>>> Thanks,
>>>> Glen
>>>>
>>>> Tarjei Huse wrote:
>>>>
>>>>
>>>>        
>>>>> Hi,
>>>>> On 09/06/2010 02:00 PM, Glen Mazza wrote:
>>>>>
>>>>>
>>>>>          
>>>>>> Hello, I'm new to ActiveMQ messaging queues and unsure if I can place
>>>>>> and subsequently read POJO's from them.  I have no problems getting
>>>>>> Strings to work it's just using POJO's that is creating the problem
>>>>>> for me.
>>>>>>
>>>>>>
>>>>>>            
>>>>> You should be able to send Serializable objects through the queues, but
>>>>> I would like to suggest you look into other serialization methods like
>>>>> Protobufs or JSON.
>>>>>
>>>>> Is DoubleIt serializable?
>>>>>
>>>>> Regards,
>>>>> Tarjei
>>>>>
>>>>>
>>>>>          
>>>
>>>      
>>    
>
>  

Reply | Threaded
Open this post in threaded view
|

Re: AW: Sending POJOs on Message Queues?

Glen Mazza
Thanks, Christian.  It turned out I do need to have the JAXB objects
implement the Serializable marker interface (like here[1], but I didn't
need toString() as it suggests) if I'm going to be sending them or
reading them from a jms queue.  But I don't need Serializable if I'm
using the "direct" component.

I'll check the soap component next.

Glen

[1]
http://stackoverflow.com/questions/1513972/how-to-generate-a-java-class-which-implements-serializable-interface-from-xsd-usi

Schneider Christian wrote:

> Hi Glen,
>
> if you use jaxb then your classes do not have to implement Serializable. Instead they of course need to be serializeable by jaxb.
>
> Btw. if you want to call a webservice with the jaxb object (Seems so as you add the soap by using xslt) then you should take a look at the camel soap dataformat. http://camel.apache.org/soap.html
>
>
>
> Greetings
>
> Christian
>  
>
>
>
>
> Christian Schneider
> Informationsverarbeitung
> Business Solutions
> Handel und Dispatching
>
> Tel : +49-(0)721-63-15482
>
> EnBW Systeme Infrastruktur Support GmbH
> Sitz der Gesellschaft: Karlsruhe
> Handelsregister: Amtsgericht Mannheim ­ HRB 108550
> Vorsitzender des Aufsichtsrats: Dr. Bernhard Beck
> Geschäftsführer: Jochen Adenau, Hans-Günther Meier
>
>
> -----Ursprüngliche Nachricht-----
> Von: Glen Mazza [mailto:[hidden email]]
> Gesendet: Montag, 6. September 2010 16:15
> An: [hidden email]
> Betreff: Re: Sending POJOs on Message Queues?
>
> But, just to confirm, do I need to make the JAXB objects serializable if
> I plan on placing them on a queue or reading them from a queue?  If
> that's the case (makes sense), I will update the Camel JAXB page to
> highlight that--it presently doesn't say anything about serializability.
>
> I'm trying to practice working with JAXB, e.g.,
>
>       from("jms:queue:numbersToDouble")
>       .marshal(jaxbFormat)
>       .to("xslt://AddSOAPEnvelope.xsl")
>       .to(CXF_URI)
>
> One more thing--if I needed to make the JAXB object serializable for it
> to work on a queue but didn't (or couldn't) do so, what could I replace
> "from("jms:queue:numbersToDouble")" above with to start the route?  The
> "direct" component?
>
> Thanks,
> Glen
>
>
> Charles Moulliard wrote:
>  
>> Hi Glen,
>>
>> Using Camel, you can use marshal() or unmarshal() to transform objects -->
>> XML or XML --> objects
>>
>> http://camel.apache.org/jaxb.html
>>
>> Regards,
>>
>> Charles Moulliard
>>
>> Senior Enterprise Architect (J2EE, .NET, SOA)
>> Apache Camel - Karaf - ServiceMix Committer
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> Blog : http://cmoulliard.blogspot.com |  Twitter :
>> http://twitter.com/cmoulliard
>> Linkedin : http://www.linkedin.com/in/charlesmoulliard | Skype: cmoulliard
>>
>>
>> On Mon, Sep 6, 2010 at 2:51 PM, Glen Mazza <[hidden email]> wrote:
>>
>>  
>>    
>>> Oh!  I was thinking of sending the POJO to the queue where it would be
>>> subsequently read and marshalled into XML, but I can have the client-side
>>> marshal into XML and send the XML to the queue instead.  Makes sense...
>>>
>>> Thanks again,
>>> Glen
>>>
>>>
>>> Tarjei Huse wrote:
>>>
>>>    
>>>      
>>>> On 09/06/2010 02:35 PM, Glen Mazza wrote:
>>>>
>>>>
>>>>      
>>>>        
>>>>> No, it's not serializable, but I believe with some effort I can make
>>>>> it so (The class is JAXB-generated  to support a web service call;
>>>>> JAXB has some extensions to allow for serializability).  Right now I'm
>>>>> trying to get the JAXB DataFormat to work (after sending the object to
>>>>> the queue I plan on marshalling it to XML) just for the sake of seeing
>>>>> JAXB working.
>>>>>
>>>>> @XmlAccessorType(XmlAccessType.FIELD)
>>>>> @XmlType(name = "", propOrder = {
>>>>>   "numberToDouble"
>>>>> })
>>>>> @XmlRootElement(name = "DoubleIt")
>>>>> public class DoubleIt {
>>>>>   protected int numberToDouble;
>>>>>   ... setter and getter for above...
>>>>> }
>>>>>
>>>>> I can look into JSON and/or Protobuf next -- is it primarily speed, or
>>>>> ease-of-use (don't have to worry about making the class serializable),
>>>>> or smaller message size that you recommend those other formats?
>>>>>
>>>>>
>>>>>        
>>>>>          
>>>> In my experience using a format that is not dependent on both the client
>>>> and server having the same version of the java object class makes it far
>>>> easier to do updates and deployments. If you got an xml format that
>>>> works that may fit the bill just fine.
>>>>
>>>> Another bonus is that you can use other languages to process the objects
>>>> if needed.
>>>>
>>>> Regards,
>>>> Tarjei
>>>>
>>>>
>>>>
>>>>      
>>>>        
>>>>> Thanks,
>>>>> Glen
>>>>>
>>>>> Tarjei Huse wrote:
>>>>>
>>>>>
>>>>>        
>>>>>          
>>>>>> Hi,
>>>>>> On 09/06/2010 02:00 PM, Glen Mazza wrote:
>>>>>>
>>>>>>
>>>>>>          
>>>>>>            
>>>>>>> Hello, I'm new to ActiveMQ messaging queues and unsure if I can place
>>>>>>> and subsequently read POJO's from them.  I have no problems getting
>>>>>>> Strings to work it's just using POJO's that is creating the problem
>>>>>>> for me.
>>>>>>>
>>>>>>>
>>>>>>>            
>>>>>>>              
>>>>>> You should be able to send Serializable objects through the queues, but
>>>>>> I would like to suggest you look into other serialization methods like
>>>>>> Protobufs or JSON.
>>>>>>
>>>>>> Is DoubleIt serializable?
>>>>>>
>>>>>> Regards,
>>>>>> Tarjei
>>>>>>
>>>>>>
>>>>>>          
>>>>>>            
>>>>      
>>>>        
>>>    
>>>      
>>  
>>    
>
>
>  

Reply | Threaded
Open this post in threaded view
|

Re: Sending POJOs on Message Queues?

Christian Schneider
  Hi Glen,

it depends on how you want to transmit the objects. If you want to have
them serialized by java serialization then they need to implement
serializeable. If you want to transmit them as xml then you do not have
to add anything as they are already jaxb objects. But you have to
initialize a jaxb dataformat (Like explained here
http://camel.apache.org/jaxb.html).

Greetings
Christian


Am 07.09.2010 02:07, schrieb Glen Mazza:

> Thanks, Christian.  It turned out I do need to have the JAXB objects
> implement the Serializable marker interface (like here[1], but I
> didn't need toString() as it suggests) if I'm going to be sending them
> or reading them from a jms queue.  But I don't need Serializable if
> I'm using the "direct" component.
>
> I'll check the soap component next.
>
> Glen
>
> [1]
> http://stackoverflow.com/questions/1513972/how-to-generate-a-java-class-which-implements-serializable-interface-from-xsd-usi
>
> Schneider Christian wrote:
>> Hi Glen,
>>
>> if you use jaxb then your classes do not have to implement
>> Serializable. Instead they of course need to be serializeable by jaxb.
>>
>> Btw. if you want to call a webservice with the jaxb object (Seems so
>> as you add the soap by using xslt) then you should take a look at the
>> camel soap dataformat. http://camel.apache.org/soap.html
>>
>>
>>
>> Greetings
>>
>> Christian
>>
>>
>>
>>
>>
>> Christian Schneider
>> Informationsverarbeitung Business Solutions
>> Handel und Dispatching
>>
>> Tel : +49-(0)721-63-15482
>>
>> EnBW Systeme Infrastruktur Support GmbH
>> Sitz der Gesellschaft: Karlsruhe
>> Handelsregister: Amtsgericht Mannheim ­ HRB 108550
>> Vorsitzender des Aufsichtsrats: Dr. Bernhard Beck
>> Geschäftsführer: Jochen Adenau, Hans-Günther Meier
>>
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Glen Mazza [mailto:[hidden email]] Gesendet: Montag, 6.
>> September 2010 16:15
>> An: [hidden email]
>> Betreff: Re: Sending POJOs on Message Queues?
>>
>> But, just to confirm, do I need to make the JAXB objects serializable
>> if I plan on placing them on a queue or reading them from a queue?  
>> If that's the case (makes sense), I will update the Camel JAXB page
>> to highlight that--it presently doesn't say anything about
>> serializability.
>>
>> I'm trying to practice working with JAXB, e.g.,
>>
>>       from("jms:queue:numbersToDouble")
>>       .marshal(jaxbFormat)
>>       .to("xslt://AddSOAPEnvelope.xsl")
>>       .to(CXF_URI)
>>
>> One more thing--if I needed to make the JAXB object serializable for
>> it to work on a queue but didn't (or couldn't) do so, what could I
>> replace "from("jms:queue:numbersToDouble")" above with to start the
>> route?  The "direct" component?
>>
>> Thanks,
>> Glen
>>
>>
>> Charles Moulliard wrote:
>>> Hi Glen,
>>>
>>> Using Camel, you can use marshal() or unmarshal() to transform
>>> objects -->
>>> XML or XML --> objects
>>>
>>> http://camel.apache.org/jaxb.html
>>>
>>> Regards,
>>>
>>> Charles Moulliard
>>>
>>> Senior Enterprise Architect (J2EE, .NET, SOA)
>>> Apache Camel - Karaf - ServiceMix Committer
>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> Blog : http://cmoulliard.blogspot.com |  Twitter :
>>> http://twitter.com/cmoulliard
>>> Linkedin : http://www.linkedin.com/in/charlesmoulliard | Skype:
>>> cmoulliard
>>>
>>>
>>> On Mon, Sep 6, 2010 at 2:51 PM, Glen Mazza <[hidden email]>
>>> wrote:
>>>
>>>> Oh!  I was thinking of sending the POJO to the queue where it would be
>>>> subsequently read and marshalled into XML, but I can have the
>>>> client-side
>>>> marshal into XML and send the XML to the queue instead.  Makes
>>>> sense...
>>>>
>>>> Thanks again,
>>>> Glen
>>>>
>>>>
>>>> Tarjei Huse wrote:
>>>>
>>>>> On 09/06/2010 02:35 PM, Glen Mazza wrote:
>>>>>
>>>>>
>>>>>> No, it's not serializable, but I believe with some effort I can make
>>>>>> it so (The class is JAXB-generated  to support a web service call;
>>>>>> JAXB has some extensions to allow for serializability).  Right
>>>>>> now I'm
>>>>>> trying to get the JAXB DataFormat to work (after sending the
>>>>>> object to
>>>>>> the queue I plan on marshalling it to XML) just for the sake of
>>>>>> seeing
>>>>>> JAXB working.
>>>>>>
>>>>>> @XmlAccessorType(XmlAccessType.FIELD)
>>>>>> @XmlType(name = "", propOrder = {
>>>>>>   "numberToDouble"
>>>>>> })
>>>>>> @XmlRootElement(name = "DoubleIt")
>>>>>> public class DoubleIt {
>>>>>>   protected int numberToDouble;
>>>>>>   ... setter and getter for above...
>>>>>> }
>>>>>>
>>>>>> I can look into JSON and/or Protobuf next -- is it primarily
>>>>>> speed, or
>>>>>> ease-of-use (don't have to worry about making the class
>>>>>> serializable),
>>>>>> or smaller message size that you recommend those other formats?
>>>>>>
>>>>>>
>>>>> In my experience using a format that is not dependent on both the
>>>>> client
>>>>> and server having the same version of the java object class makes
>>>>> it far
>>>>> easier to do updates and deployments. If you got an xml format that
>>>>> works that may fit the bill just fine.
>>>>>
>>>>> Another bonus is that you can use other languages to process the
>>>>> objects
>>>>> if needed.
>>>>>
>>>>> Regards,
>>>>> Tarjei
>>>>>
>>>>>
>>>>>
>>>>>> Thanks,
>>>>>> Glen
>>>>>>
>>>>>> Tarjei Huse wrote:
>>>>>>
>>>>>>
>>>>>>> Hi,
>>>>>>> On 09/06/2010 02:00 PM, Glen Mazza wrote:
>>>>>>>
>>>>>>>
>>>>>>>> Hello, I'm new to ActiveMQ messaging queues and unsure if I can
>>>>>>>> place
>>>>>>>> and subsequently read POJO's from them.  I have no problems
>>>>>>>> getting
>>>>>>>> Strings to work it's just using POJO's that is creating the
>>>>>>>> problem
>>>>>>>> for me.
>>>>>>>>
>>>>>>>>
>>>>>>> You should be able to send Serializable objects through the
>>>>>>> queues, but
>>>>>>> I would like to suggest you look into other serialization
>>>>>>> methods like
>>>>>>> Protobufs or JSON.
>>>>>>>
>>>>>>> Is DoubleIt serializable?
>>>>>>>
>>>>>>> Regards,
>>>>>>> Tarjei
>>>>>>>
>>>>>>>
>>
>>
>
>

--
----
http://www.liquid-reality.de