Specifying the Message Body

This topic describes some of the ways in which you can specify the body of a message sent via the JMS control.

Note: In WebLogic Workshop 7.0, you specified the message body using an XML map. XML maps are no longer supported for specifying the message body on a JMS control. If you have existing JMS controls with the CTRL extension, these controls will continue to work. However, if you choose to upgrade your controls to JCX control files, you'll need to remove the @jws:jms-message tag and any XML maps that it specifies. You can modify these controls to use XMLBeans types instead of XML maps, as described below.

Selecting the Message Type

A JMS control can send and receive text messages (including XML messages), byte array messages, object messages, and javax.jms.Message (JMS Message) objects. These are the types defined by the JMS messaging service specification.

When you create a JMS control, you can specify which type of message it sends and receives in the Message Type drop-down of the Insert Control dialog. The value you choose determines what the default send and receive method signatures will look like; for example, if you specify Text/XMLBean as the message type, the control is created with a sendTextMessage() method and a receiveTextMessage() callback.

You have complete control over the send methods and receiving callback, as long as you are sending a message of a supported type; you can modify the default method signatures as you need to, including adding additional parameters to handle message headers and properties. However, you can only specify one parameter in the method or callback for the message body.

Although you have flexibility over what type of message your code sends and receives, note that the outgoing message and the incoming message must be of the same type; no implicit type conversion is performed on messages.

Sending and Receiving a Simple Text Message

The simplest message body is a text message. The following example shows a simple text message sent to the messaging service via a JMS control:

/**
* @common:operation
*/
public void sendString(String msg) throws Exception
  {
  myJMSControl.sendTextMessage(msg);
  }
  

The receiving callback takes a parameter of type String that the messaging service sends to the control. The following is a simple example of a callback that receives a text message:

public void myJMSControl_onTextMessage(String msg) 
  {
  //this code calls another callback on the client, to return the message to the client
  callback.onMessageReceived("[" + name + "] Your message is: " + msg );
  }	
 

Sending and Receiving an XML Message using XMLBeans

If you need to send a set of values in the message body, you can construct the message body using an XMLBeans object type. WebLogic Workshop's XMLBeans technology generates a set of Java classes from an XML schema (.xsd) file. You can then use these classes to work with XML documents in your code. For more information on XMLBeans, see Getting Started with XMLBeans.

If you don't already have a schema file, you can construct one by hand, or you can generate one from an XML document or fragment using a third-party authoring tool like Altova's XMLSpy. Once you've created your schema file, add it to the Schemas project in your WebLogic Workshop application. When you add a schema to the Schemas project, WebLogic Workshop automatically generates XMLBeans classes for that schema. The XMLBeans classes for all of the schemas in the Schemas project are packaged together in the library Schemas.jar, which appears in the Libraries folder at the root of your application.

In this case, you want to structure your schema so that you can pass a single object as the message body for the JMS message. The object can have any number of properties, but the top-level element of your schema should correspond to the object that you want to send as a message.

Once you've generated the XMLBeans classes from the schema file, you can import those classes into your JMS control class. You can then modify the send method or receiving callback on the JMS control to send or receive a message of the appropriate type.

Note that XMLBeans messages are transmitted as JMS text messages. When you create a JMS control that will use an XMLBeans type for the message body, specify the type in the Message Type drop-down as Text/XMLBean.

For an example that shows how to use an XMLBeans type as the body of a JMS message, see the AccountPublish.jws/AccountSubscribe.jws samples in the jms directory of the WebServices project in the SamplesApp application. These samples use an XMLBean type generated from the JmsSchemas.xsd file, which you can find in the Schemas project in the SamplesApp application.

Related Topics

JMS Control

Overview: Messaging Systems and JMS

Specifying Message Headers and Properties

SimpleJMS.jws Sample

CustomJMSClient.jws Sample

@jc:jms Annotation