Java Reference
In-Depth Information
In the generated code, the @Resource annotation uses its name attribute
to locate the injected resources. This annotation uses the JNDI name of the
injected resources to locate them. In some cases, this JNDI lookup may
fail even if the value of the annotation is correct. This situation can be
corrected by replacing the name attribute with mappedName , and using
the same value we were using for the name attribute.
Initially, the method to create the message does not compile, we are expected to
provide the body for this method.
In our example, the name of the method is createJMSMessageForjmsMyQueue()
(the exact method name will vary depending on the name of our JMS destination).
It returns an instance of a class implementing javax.jms.Message , which all JMS
message types must implement, and takes two parameters: an instance of a class
implementing javax.jms.Session , and an object containing the message data.
The package javax.jms.Message has several sub-interfaces which are part of the
standard Java EE 5 API. In most cases, we use one of the sub-interfaces to send
messages, instead of using a direct implementation of javax.jms.Message . The
following table summarizes all of the standard Java EE 5 subinterfaces:
Subinterface Description
BytesMessage Used to send an array of bytes as a message.
MapMessage Used to send name-value pairs as messages. The names must be String
objects; the values must be either primitive types or Java objects.
ObjectMessage Used to send serializable objects as messages. A serializable object is an
instance of any class that implements java.io.Serializable .
StreamMessage Used to send a stream of Java primitive types as a message.
TextMessage
Used to send a String as a message.
Of the above message types, TextMessage and ObjectMessage are the most
frequently used. We will use TextMessage for our example. Using other message
types is very similar.
Consult the Java EE 5 JavaDoc for details on the APIs for each of the
message types. Java EE 5 JavaDoc can be found at http://java.sun.
com/javaee/5/docs/api/ or directly from NetBeans by going to Help
| Javadoc References | Java EE 5 SDK
 
Search WWH ::




Custom Search