• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

public void onMessage(TextMessage msg){}

 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What will happen when you try to compile the following message driven bean? Assume all packages are correctly imported.

1.public class GatewayBean implements MessageDrivenBean, MessageListener {
2. public GatewayBean(){}
3. public void ejbCreate(){}
4. public void onMessage(TextMessage msg){}
5. public void ejbRemove(){}
6. public void setMessageDrivenContext(MessageDrivenContext ctx){}
7.}

1. Compilation error, incorrect declaration on line 3.

2. Compilation error, incorrect declaration on line 4.

3. The code compiles fine.

4. Compilation error, the GatewayBean class must be declared abstract.

5. Compilation error, the GatewayBean class must be declared final.










Answer 2 is correct.
The message-driven bean class must define one onMessage method whose signature must follow these rules:

The method must be declared as public.
The method must not be declared as final or static.
The return type must be void.
The method must have a single argument of type javax.jms.Message.
The throws clause must not define any application exceptions.




I don't understand why this mthod is declared wrong.
I believe it follows all the above rules....what am I missing?
 
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The method signature in the javax.jms.MessageListener is

public void onMessage(Message m);

That means your MDB should provide the implementation of this method because your MDB implements MessageListener . Thats is why point 2 is correct.

Hope that helps.
 
Kris Reid
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
javax.jms.MessageListener defines:
public void onMessage(javax.jms.Message message)


public interface TextMessage extends javax.jms.Message

so isn't
public void onMessage(javax.jms.TextMessage msg){}
leagal?
 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
########################################################

public void onMessage(javax.jms.Message message)

########################################################

Whenever a class implements an interface it has to provide the implementation of the methods declared in the interface or the class will be abstract. If you provide the implementatiom for onMessage(javax.jms.TextMessage) then you will get a compile time error that the MDB needs to implement the inherited abstract method onMessage(javax.jms.Message).

hope that helps
 
Hey! Wanna see my flashlight? It looks like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic