Hi Dan,
The QName in publish(QName,Element[]) is actually just the topic name of
the notification message.  It shouldn't and isn't being applied to each
Element value.

I have verified that if I send two Elements of different names, they get
sent successfully.  Then on the client side, I can get both objects
using:
        Iterator iter = message.getMessageContentNames().iterator();
        while (iter.hasNext())
        {
            QName name = (QName)iter.next();
            Element value = message.getMessageContent(name);
            System.out.prinltn("value: " + value);
        }


But if the Elements sent have the same names, then only the last one
gets sent.  This is because of the LinkedHashMap being used to collect
the message objects before they are sent out.  I think this should be
fixed to use a list instead.

Awhile back in Muse 2.1.0, there was only a publish(QName, Element)
method.  I opened an enhancement bug to add an additional method to
allow publishing an array of objects because sending only one object at
a time can be a quite an overhead.  This was fixed in Muse 2.2.0, and I
think only I tested the fix back then using different object types (i.e.
Elements with different QNames).  I didn't realize until now that it
doesn't work with objects of the same type.

There's another problem though.  The client side also has to be updated
so that the array of message objects can be extracted properly.
Currently, MessageListener.getMessageContent(QName) only returns one
element.  The following should also be added:

public Element[] getMessageContents();  // returns all message elements
public Element[] getMessageContents(QName);  // returns all message
elements with the given name

The WS-BaseNotification-1_3.xsd defines the <Message> element in a
NotificationMessage to contain a sequence of elements.  There is no
restriction on the element types.  But right now, Muse is restricting it
to only contain unique types.

-Vinh


-----Original Message-----
From: Daniel Jemiolo [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 21, 2007 11:54 AM
To: [email protected]
Subject: RE: Array serialization problem in notifications



> I have solved the issue for the moment by wrapping the Elements that 
> represent the array in another top level element that gets published.

This is the intended behavior and strategy for publishing an array of
elements. Because it can be hard to tell when a group of elements
represents an array vs. a list of independent values, Muse requires
arrays to be wrapped in a parent/"array" element. The publish(QName,
Element[]) method is applying the QName to each value (Element) in the
array and adding a wrapper element. To publish an array of values that
are distinct, you need to wrap them in an element yourself and call
publish(QName, Element).

Dan



Bogdan Solomon <[EMAIL PROTECTED]> wrote on 08/16/2007 03:03:44
PM:

>
> Well I have discovered what the problem is. I am unsure however if 
> this
is
> because of the way I construct the XML or if this is a bug in Muse.
>
> The SimpleNotificationProducer publish array method does the
following:
>
> NotificationMessage message = createNotificationMessage();
>
> for (int n = 0; n < content.length; ++n)
>      message.addMessageContent(content[n]);
>
> and in SimpleNotificationMessage
>
> the addMessageContent does the following:
>
> if (content == null)
>      throw new 
> NullPointerException(_MESSAGES.get("NullMessageContent"));
>
> QName name = XmlUtils.getElementQName(content);
> _messageContent.put(name, content);
>
> but _messageContent is a LinkedHashMap, and from what the Java
specification
> says adding multiple instances with the same key overwrites the
values.
So
> only the last one will be preserved.
>
> I have solved the issue for the moment by wrapping the Elements that 
> represent the array in another top level element that gets published.
>
>
> Vinh Nguyen (vinguye2) wrote:
> >
> > Try explicitly converting your XmlSerializable[] to an Element[], 
> > and then call producer.publish(QName,Element[]).  See if that makes 
> > a difference?
> >
> >
> > -----Original Message-----
> > From: Bogdan Solomon [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, August 16, 2007 7:23 AM
> > To: [email protected]
> > Subject: Array serialization problem in notifications
> >
> >
> > I think the problem is in my serialization code but I just can't
figured
> > out what it is.
> >
> > I am trying to send via notifications an array of custom objects 
> > which implement XmlSerializable. I logged some messages and I see 
> > that all
the
> > objects in the array get serialized (the toXml() method is called 
> > for each of them), but the final notification only contains the last
element
> > in the array.
> >
> > Here is the notification code (the data structure is an ArrayList):
> >
> > QName messageName = new
> > QName("http://autonomic.ibm.com/muse/sensor/execution/Topics";,
> > "MeasuredDataTopic", "topics1");
> > wsn.publish(messageName, data.toArray(new DataInterface[0]));
> >
> > and here is the serialization code:
> >
> > public Element toXML() {
> >       System.out.println("Serializing:"+name);
> >
> >       Element root =
> > XmlUtils.createElement(XmlUtils.EMPTY_DOC,rootQName);
> >
> >       //Element root = XmlUtils.createElement(rootQName);
> >
> >       Element name = XmlUtils.createElement(nameQName, getName());
> >
> >       Element dataValue =
> > XmlUtils.createElement(dataValueQName,getDataValue());
> >
> >       Element desc =
> > XmlUtils.createElement(descQName,getDescription());
> >
> >       Element valueType =
> > XmlUtils.createElement(valueTypeQName,getDataType());
> >
> >       root.appendChild(name);
> >       root.appendChild(dataValue);
> >       root.appendChild(desc);
> >       root.appendChild(valueType);
> >
> >       return root;
> >    }
> >
> > The resulting Notification looks as follows:
> >
> > <soap:Body>
> >         <wsnt:Notify
xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2";>
> >             <wsnt:NotificationMessage
> >
xmlns:muse-wsa="http://ws.apache.org/muse/addressing";
> >
> > xmlns:sensor="http://autonomic.ibm.com/muse/filter/execution";
> >                 xmlns:wsa="http://www.w3.org/2005/08/addressing";
> > xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2";>
> >                 <wsnt:SubscriptionReference>
> >                     <wsa:Address
> >
xmlns:wsa="http://www.w3.org/2005/08/addressing";>http://192.168.32.23:90
> > 81/AutonomicSensor/services/SubscriptionManager</wsa:Address>
> >                     <wsa:ReferenceParameters 
> > xmlns:wsa="http://www.w3.org/2005/08/addressing";>
> >                         <muse-wsa:ResourceId
> >
xmlns:muse-wsa="http://ws.apache.org/muse/addressing";>MuseResource-1</mu
> > se-wsa:ResourceId>
> >                     </wsa:ReferenceParameters>
> >                 </wsnt:SubscriptionReference>
> >                 <wsnt:Topic
> >
> >
Dialect="http://docs.oasis-open.org/wsn/t-1/TopicExpression/Concrete";
> >
xmlns:topics1="http://autonomic.ibm.com/muse/sensor/execution/Topics";>to
> > pics1:MeasuredDataTopic</wsnt:Topic>
> >                 <wsnt:ProducerReference>
> >                     <wsa:Address
> >
xmlns:wsa="http://www.w3.org/2005/08/addressing";>http://192.168.32.23:90
> > 81/AutonomicSensor/services/sensor</wsa:Address>
> >                     <wsa:ReferenceParameters 
> > xmlns:wsa="http://www.w3.org/2005/08/addressing";>
> >                         <muse-wsa:ResourceId
> >
xmlns:muse-wsa="http://ws.apache.org/muse/addressing";>MuseResource-13</m
> > use-wsa:ResourceId>
> >                     </wsa:ReferenceParameters>
> >                 </wsnt:ProducerReference>
> >                 <wsnt:Message>
> >                     <sensor:FilteredData 
> > xmlns:sensor="http://autonomic.ibm.com/muse/filter/execution";>
> >
> >
<sensor:name>TradeScenarioServlet-ServiceTime-TotalTime</sensor:name>
> >                         <sensor:dataValue>0</sensor:dataValue>
> >                         <sensor:description/>
> >                         <sensor:valueType>Long</sensor:valueType>
> >                     </sensor:FilteredData>
> >                 </wsnt:Message>
> >             </wsnt:NotificationMessage>
> >         </wsnt:Notify>
> >     </soap:Body>
> >
> > But my message should contain 7 FilteredData structures as I have 7 
> > DataInterface objects.
> > --
> > View this message in context:
> >
http://www.nabble.com/Array-serialization-problem-in-notifications-tf427
> > 9966.html#a12182356
> > Sent from the Muse User mailing list archive at Nabble.com.
> >
> >
> > --------------------------------------------------------------------
> > - To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> > --------------------------------------------------------------------
> > - To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Array-
> serialization-problem-in-notifications-tf4279966.html#a12187485
> Sent from the Muse User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to