You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by hendrila <la...@lancehendrix.com> on 2012/04/15 01:40:44 UTC

Re: Format of stomp MapMessages from PHP? string works, long fails.

neek wrote
> 
> I'm not sure where to ask this question.. here or at fusesource, or at
> xstream.  Quite a few libraries are responsible for marshalling the data
> and I think it's xstream that actually needs the data format I'm talking
> about.
> 
> I've succeeded in sending a MapMessage from PHP to ActiveMQ via the stomp
> protocol, as long as it only contains string datatypes.  e.g.:
> 
> $body = array('map' => array('entry' => array(
>         array('string' => array('orders_id', '1234')),
>         array('string' => array('status', '4'))
> )));
> 
> I do not know where the "map: { entry : [ ... etc" protocol is defined.  I
> believe it's expected in xstream.  They don't appear on the receiving end
> in the resulting MapMessage.
> 
> That map is received as a JMS MapMessage with orders_id => "1234" and
> status => "4".  Great.
> 
> My problem is that as soon as I try to send a non-string value, the
> message parsing fails.  For example the most obvious change to make
> orders_id a long instead of a string:
> 
> $body = array('map' => array('entry' => array(
>         array('long' => array('orders_id', 1234)),
>         array('string' => array('status', '4'))
> )));
> 
> This sends ok from PHP, but barfs in the Java server:
> 
> """""
> Aug 7, 2011 10:18:55 PM
> org.apache.activemq.transport.stomp.ProtocolConverter handleException
> WARNING: Exception occurred processing: 
> SEND
> amq-msg-type:MapMessage
> transformation:jms-map-json
> destination:/queue/integration/order_update
> transformation-error:For input string: "orders_id" : For input string:
> "orders_id"
> ---- Debugging information ----
> message             : For input string: "orders_id"
> cause-exception     : java.lang.NumberFormatException
> cause-message       : For input string: "orders_id"
> class               : java.util.HashMap
> required-type       : java.lang.Long
> path                : /map/entry/long
> line number         : -1
> -------------------------------
> 
> {"map":{"entry":[{"long":["orders_id",1234],"...s","4"]}}]}}:
> org.apache.activemq.transport.stomp.ProtocolException: Unsupported message
> type 'MapMessage'
> """""
> 
> It is taking the string "orders_id" (NOT the value "1234") and trying to
> call Long.parseLong("orders_id") which of course throws
> NumberFormatException.
> 
> It seems that the processing of non-string fields no longer uses the
> "type: [ key, value ]" syntax.
> 
> Can anyone advise how to send non-string fields?
> 
> Just to mention,  I believe I can take the data type identifiers seen in
> com/thoughtworks/xstream/XStream.java .. and the
> http://xstream.codehaus.org/converters.html reference shows a MapMessage
> that looks like this:
> 
> <map>
>   <entry>
>     <string>apple</string>
>     <float>123.553</float>
>   </entry>
>   <entry>
>     <string>orange</string>
>     <float>55.4</float>
>   </entry>
> </map> 
> 
> Yet, simply changing 'string' to 'long' in my example seems to completely
> change the expected format.
> 
> For now I can pass strings and convert them myself in the consumer but
> this is clearly not the right solution in the long term.
> 
> Nick
> 

I don't know if you are still working on this, but I figured out how to do
this.  Basically if both the key and the value are strings, you can do as
you indicate; however, if you want to represent a value that is other than a
string, the format for constructing the data structure varies as such:

    $body = array('map' => array('entry' => array(
        array('string' => array('contentName', 'Partner Resources')),
        array('string' => array('contentHREF', ' "http://somewhere.com/')),
        array('string' =  array('contentId', '10034')),
        array('string' => array('author', 'Lance Hendrix')),
        array('string' => array('authorEmail', 'lance@lancehendrix.com')),
        array('string' => array('content', 'These are the partners we should
be using...')),
        array('string' => array('contentType', 'blog')),
        array(array('string' => 'id', 'int' => 1234))
    )));

The first line, as you know sets up the structure, while the 7 lines that
begin "array('string => array" setup key value pairs where both the key and
the value are strings; however, line 8 is where I have added a key value
pair where the key is a string and the value is an int.  As far as I can
tell, there is no way to have a key that is not a string, but the value can
be of something other than string.  I have verified that this also comes
through ActiveMQ correctly and can be received and decoded in Java.

For a full explanation of this, I have updated my article on using PHP stomp
to talk to Java through ActiveMQ on my site at 
http://www.lancehendrix.com/techdocs/incubation/Talking%20Stomp%20to%20ActiveMQ.html
http://www.lancehendrix.com/techdocs/incubation/Talking%20Stomp%20to%20ActiveMQ.html
.

I hope this helps!

Lance

--
View this message in context: http://activemq.2283324.n4.nabble.com/Format-of-stomp-MapMessages-from-PHP-string-works-long-fails-tp3725070p4558247.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.