Our implementation choice for today will be Ruby. To create this message we can use this cool Ruby SIF message API as well as we should have handy the SIF Spec document to make sure that we are creating messages correctly.
A SIF_Register message has five mandatory elements, they are: SIF_Header, SIF_Name, SIF_Version, SIF_MaxBufferSize, SIF_Mode with the rest of the elements being optional or conditional elements. Since the SIF_Header is our first element lets build a simple SIF_Header and then print it out to see it in action.
1. require 'rubygems'
2. require 'openagent'
3.
4. @timenow = Time.now
5. @timestamp = @timenow.strftime("%Y-%m-%d") + "T" + @timenow.strftime("%H:%M:%S")
6. @message_id = UUID.generate(:compact).upcase
7.
8. header = OpenAgent::Messages::SIF_Header.new
9. header.sif_msgid = @message_id
10. header.sif_sourceid = 'AcmeAgent'
11. header.sif_timestamp = @timestamp
12. puts
13. puts header.to_xml
14. puts
Our agent name comes from the SIF Spec examples – I would suggest that you come up with a unique name for this field if you are using your OpenZIS account. Now let continue on with the construct of our Register message.
16. register = OpenAgent::Messages::SIF_Register.new
17. register.sif_header = header
18. register.sif_name= 'Acme Agent for WAP 2.x'
19. register.sif_version = '2.3'
20. register.sif_maxbuffersize = 524288
21. register.sif_mode = 'Pull'
22. puts register.to_xml
23. puts
This section of code puts the Header into the SIF_Regester object as well as sets a few of the other mandatory elements from above.
Now lets put the SIF_Register into its message container.
24. message = OpenAgent::Messages::Register.new
25. message.sif_register = register
26. puts message.to_xml
27. puts
Comments on this entry are closed.