Changeset 616
- Timestamp:
- 05/03/07 10:33:43 (2 years ago)
- Files:
-
- trunk/src/hefeweizen_library_ebMS_message2.rb (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/hefeweizen_library_ebMS_message2.rb
r606 r616 175 175 end 176 176 177 # ebMS ifno 177 # ebMS message info based on the ebMS info (from the CPA). 178 # The infos are service, action, from name, to name, and the cpa id. 178 179 def ebMS_info_summary ebMS_info 179 return"ebXML Message Info: service is '#{ebMS_info['service']}', action is '#{ebMS_info['action']}', sender is '#{ebMS_info['from']}', receiver is '#{ebMS_info['to']}', CPA ID is '#{ebMS_info['info']['cpa_id']}'."180 "ebXML Message Info: service is '#{ebMS_info['service']}', action is '#{ebMS_info['action']}', sender is '#{ebMS_info['from']}', receiver is '#{ebMS_info['to']}', CPA ID is '#{ebMS_info['info']['cpa_id']}'." 180 181 end 181 182 … … 238 239 239 240 public 241 240 242 def set_new_ebXML_message_file ebXML_message_id, temp_file_path 241 243 FileUtils.mv temp_file_path, "#{@message_store_directory}/messages/#{ebXML_message_id}/ebXML_message.ebMS2" … … 288 290 289 291 # This is the ebXML message class. 292 # This class is used for all ebXML Messages version 2.0. This includes user messages and ebMS signals (acks, error, ping, pong etc) 290 293 class EBMessage2 291 294 … … 295 298 attr_reader :references, :payloads 296 299 attr_reader :errors 297 attr_accessor :raw_message_file_path298 300 attr_reader :ack_ref_to_msg_id 299 301 attr_reader :message_data_ref_to_message_id … … 301 303 attr_reader :time_to_live 302 304 attr_reader :soap_only 305 attr_reader :ebXML_message_path 306 attr_accessor :raw_message_file_path 307 303 308 def me 304 309 "EBMessage2" … … 309 314 end 310 315 316 # This method calculates the hash value of this ebXML message. 317 # The values service, action, from name, and to name are used. 311 318 def get_hash_value cpa 312 319 hash = Hash.new … … 318 325 end 319 326 327 # This method returns the current state of the message as a string 328 def get_message_state 329 states = Dir.glob("#{File.dirname @ebXML_message_path}/message_state/*") 330 return "No history for this message." if states.empty? 331 (File.basename states[0]).gsub /_/, " " 332 end 333 334 # This method returns a history summary in the form of a string. 335 # This is typically used in a text user interface 336 def get_history_summary 337 out = "" 338 counter = 1 339 history_events = Dir.glob("#{File.dirname @ebXML_message_path}/message_history/*") 340 return "No history for this message." if history_events.empty? 341 details_size = 10 342 content_size = 12 343 event_size = 55 344 time_date_size = 15 345 out += sprintf "\n %1$*2$s %3$*4$s %5$*6$s %7$*8$s", "Details Key", -details_size, "Has details", -content_size, "Event", -event_size, "Date/Time", -time_date_size 346 history_events.sort.each{ | dir | 347 if dir =~ /.*__(.*)/ then 348 event = $1.gsub /_/, " " 349 time_date = File.ctime(dir).to_s 350 has_content = (FileTest.size? dir) ? "x" : "-" 351 out += sprintf "\n H%1$*2$s %3$*4$s %5$*6$s %7$*8$s", counter, -details_size, has_content, -content_size, event, -event_size, time_date, time_date_size 352 end 353 counter += 1 354 } 355 return out 356 end 357 358 # This is a online line summary of the message. This includes the service, the action, the from name and to to name. 320 359 def summary 321 return "ebXML Message: service is '#{@service}', action is '#{@action}', sender is '#{@from_name}', receiver is '#{@to_name}'." 322 end 323 324 def ack_requested? 325 return @is_ack_requested 326 end 360 "ebXML Message: service is '#{@service}', action is '#{@action}', sender is '#{@from_name}', receiver is '#{@to_name}'." 361 end 362 363 # This method returns a complete summary of an ebXML message. 364 # This is typcially used in a text user interface 365 def long_summary 366 row = 20 367 content_length = 50 368 out = "" 369 out += sprintf "%1$*2$s %3$*4$s\n", "Title", -row, "Content", -content_length 370 out += "-"*(row+content_length) + "\n" 371 out += sprintf "%1$*2$s %3$*4$s\n", "Message Id", -row, message_id, -content_length 372 out += sprintf "%1$*2$s %3$*4$s\n", "Conversation Id", -row, conversation_id, -content_length 373 out += sprintf "%1$*2$s %3$*4$s\n", "CPA ID", -row, cpa_id, -content_length 374 out += sprintf "%1$*2$s %3$*4$s\n", "From", -row, from_name, -content_length 375 out += sprintf "%1$*2$s %3$*4$s\n", "From Role", -row, (from_role rescue "-"), -content_length 376 out += sprintf "%1$*2$s %3$*4$s\n", "To", -row, to_name, -content_length 377 out += sprintf "%1$*2$s %3$*4$s\n", "To Role", -row, (to_role rescue "-"), -content_length 378 out += sprintf "%1$*2$s %3$*4$s\n", "Service ", -row, service, -content_length 379 out += sprintf "%1$*2$s %3$*4$s\n", "Action", -row, action, -content_length 380 out += sprintf "%1$*2$s %3$*4$s\n", "Timestamp", -row, message_timestamp, -content_length 381 out += sprintf "%1$*2$s %3$*4$s\n", "Message State", -row, get_message_state, -content_length 382 if is_user_message? 383 out += sprintf "%1$*2$s %3$*4$s\n", "Type of Message", -row, "User Message", -content_length 384 out += sprintf "%1$*2$s %3$*4$s\n", "Number of payloads: ", -row, references.size.to_s, -content_length 385 else 386 out += sprintf "%1$*2$s %3$*4$s\n", "Type of Message", -row, "ebMS Signal Message", -content_length 387 if is_ack? then 388 out += sprintf "%1$*2$s %3$*4$s\n", "Ref to Messsage ID", -row, ack_ref_to_msg_id, -content_length 389 end 390 end 391 out += sprintf "%1$*2$s %3$s\n", "History" , -row, get_history_summary 392 end 393 327 394 328 395 def is_multipart? … … 330 397 end 331 398 399 # This method returns whether this message is digitally signed. 332 400 def is_signed? 333 401 @has_signature … … 335 403 336 404 # TODO : IMPLEMENT 405 # This method returns whether this message is encrypted. 337 406 def is_encrypted? 338 407 @is_encrypted … … 340 409 341 410 # TODO : IMPLEMENT 411 # This method returns the encryption protocol of this message if there is a encryption protocol. Nil 412 # otherwise 342 413 def encryption_protocol? 343 414 @encryption_protocol || nil 344 415 end 345 416 417 # This method returns the encryption algorithm of this message if there is an encryption algorithm. Nil 418 # otherwise. 346 419 def encryption_algorithm? 347 420 @encryption_algorithm || nil 348 421 end 349 422 423 # This method returns whether the message has an Acknowledgement element. 350 424 def is_ack? 351 425 @is_ack … … 359 433 end 360 434 361 def has_ack_requested? 435 # This method returns whether the ebXML Message has the AckRequested element. 436 def ack_requested? 362 437 @is_ack_requested 363 438 end 364 439 440 # has_ack_requested? is another way to find out whether the message has an AckRequested element. 441 alias has_ack_requested? ack_requested? 442 443 # This method returns whether the AckRequested element has the request to be signed. 365 444 def has_signed_ack_requested? 366 445 @is_ack_signed_requested rescue false 367 446 end 368 369 def has_ack_signature_requested?370 @is_ack_signed_requested rescue false371 end 372 447 448 # has_ack_signature_requested? is another way to find out whether the message has a signed AckRequested element. 449 alias has_ack_signature_requested? has_signed_ack_requested? 450 451 # This method returns whether this message is a non ebMS message service 373 452 def is_user_message? 374 453 @service != "urn:oasis:names:tc:ebxml-msg:service" … … 403 482 end 404 483 484 # This method returns whether the message has the DuplicateElimination element set. 405 485 def has_duplicate_elimination? 406 486 @duplicate_elimination 407 487 end 408 488 489 # This method returns whether the passed in ebMS info (from the CPA) represents an ebXML signal message. 490 def EBMessage2.ebMS_info_includes_ebMS_signal? ebMS_info 491 (ebMS_info['service'] == "urn:oasis:names:tc:ebxml-msg:service" and ["MessageError", "Ping", "Pong", "StatusRequest", "StatusResponse", "Acknowledgment"].include? ebMS_info['action']) ? true : false 492 end 493 494 # This method is used to get the message type. This is required for ebMS protocol logic. 409 495 def get_message_type 410 496 return "User" if is_user_message? … … 418 504 end 419 505 420 # TODO 421 # XML DateTime DataType 506 # This method returns the current time in an XML XSD format. 422 507 def EBMessage2.create_timestamp 423 508 Time.new.strftime('%Y-%m-%dT%H:%M:%SZ') 424 509 end 425 510 511 # This method returns the current time in an XML XSD format. 512 def create_timestamp 513 Time.new.strftime('%Y-%m-%dT%H:%M:%SZ') 514 end 515 516 # This method returns a new ebXML message id 426 517 def EBMessage2.get_good_message_id 427 518 HefeWeizen::HefeWeizenLibrary::Execution.uuid.strip.gsub( /-/, "") 428 519 end 429 520 430 def create_timestamp431 Time.new.strftime('%Y-%m-%dT%H:%M:%SZ')432 end433 434 521 def EBMessage2.create_message_header_id 435 522 "ID#{EBMessage2.get_good_message_id}#{HefeWeizen}" … … 465 552 466 553 # This method creates an ebXML Message based on directives and ebMS message infos. 554 # This includes ebXML user messages and ebMS signals 555 # ############################################################# 556 # TASKER SMELL 557 # TODO A ebXML user message should be constructed in a tasker. 558 # The reason being that there can be multiple payloads 559 # ############################################################# 467 560 def EBMessage2.create_message party_ids, directive, ebMS_message_info, complete_ebXML_message_file_path, 468 561 config, message_id, conversation_id … … 749 842 end 750 843 751 def EBMessage2.ebMS_info_includes_ebMS_signal? ebMS_info752 (ebMS_info['service'] == "urn:oasis:names:tc:ebxml-msg:service" and ["MessageError", "Ping", "Pong", "StatusRequest", "StatusResponse", "Acknowledgment"].include? ebMS_info['action']) ? true : false753 end754 844 755 845 ################################## 756 846 ## EBMessage2 757 847 ################################## 848 # This is the constructor of the ebXML Message Version 2.0 class. 758 849 # currently it is possible to load the ebXML message from a file, string 759 850 # TODO add as load type URI 760 851 def initialize config, ebXML_message_path, load_type = "file" 852 @ebXML_message_path = ebXML_message_path 761 853 @config = config 762 854 @logger = @config['LOGGER'] … … 776 868 end 777 869 870 require @config['LIB_DIR'].strip + "/hefeweizen_library_utils" 778 871 @raw_message_file_path = "#{@config['TEMP_FILE_DIR']}/raw_message_#{EBMessage2.get_good_message_id}" 779 872 … … 799 892 end 800 893 894 # ############################################################# 895 # TASKER SMELL 896 # o seems like this should be done in a takser ... as the size 897 # and number of the payloads are not known. 898 # ############################################################# 801 899 @soap_only = EBMessage2.raw_message_to_soap_only @raw_message_file_path 802 900 @payloads = EBMessage2.raw_message_to_payloads @raw_message_file_path … … 832 930 @has_manifest = false 833 931 end 834 835 932 836 933 =begin … … 854 951 855 952 # This method determines whether there is an action required for this ebXML message. 953 # Typically a pong follows a ping or for a message with an AckRequested element an 954 # Acknowledgement is required. 856 955 def get_required_action 857 956 if self.is_pig? then … … 866 965 create_ack = self.has_ack_requested? 867 966 868 if create_ack then 869 create_signed_ack = self.has_ack_signature_requested? 870 end 967 create_signed_ack = self.has_ack_signature_requested? if create_ack 871 968 872 969 if create_ack == true and create_signed_ack == false then … … 897 994 898 995 899 900 996 # This method returns the signature references as a string. 901 997 def get_signature_references_as_string 902 903 998 if @has_signature then 904 999 doc = REXML::Document.new(@soap_only) … … 911 1006 return "" 912 1007 end 913 914 1008 end 915 1009 … … 1142 1236 # This is very slow and only good for prototyping. 1143 1237 # TODO Fix this for performance. Use low level IO or a tasker 1238 # ############################################################# 1239 # TASKER SMELL 1240 # o seems like this should be done in a takser ... as the size 1241 # and number of the payloads are not known. 1242 # ############################################################# 1144 1243 def EBMessage2.raw_message_to_soap_only raw_message_file_path 1145 1244 soap_only = "" … … 1177 1276 # This method reads the multipart mime message and retrieves the payload mime parts and creates 1178 1277 # a payload object of each. 1278 # ############################################################# 1279 # TASKER SMELL 1280 # o seems like this should be done in a takser ... as the size 1281 # and number of the payloads are not known. 1282 # ############################################################# 1179 1283 def EBMessage2.raw_message_to_payloads raw_message_file_path 1180 1284 payloads = Hash.new
