<commit_before>require 'socket'
require 'timeout'

class ClientSoap
  def initialize(template,namespace,config) 
    @template=template
    @namespace=namespace
    p @namespace
    @config=config 
  end
  def format(request,hparam) 
    buff= @template[:config][request][:req].dup
    @config.each { |k,value| buff.sub!(k,value.to_s) }
    buff.sub!(/<SOAP-ENV:Envelope\s+></,'<SOAP-ENV:Envelope '+@namespace+'><')
    buff.sub!(/<soap:Envelope\s+></,'<soap:Envelope '+@namespace+'><')
    buff.sub!(/(#{@config["HMESSID"]})/,"#{(Time.now.to_f*1000).round}")
    hparam.each { |k,value| buff.gsub!(k,value.to_s) }
    #buff.gsub!(/<wsa5:From>.*?<\/wsa5:From>/,"")    if @config["nonFrom"]
    buff
  end
  def format_http(server,request,hparam)
    data=format(request,hparam)
    action=data[/<.*?Action.*?>([^<]+)<\/.*?Action.*?>/,1]
    "POST #{server} HTTP/1.1\r\nAccept-Encoding: gzip,deflate\r\nContent-Type: application/soap+xml;charset=UTF-8;action=\"#{action}\"\r\n"+
         "Content-Length: #{data.size}\r\nHost: localhost:9999\r\nConnection: close\r\nUser-Agent: ocpp-simulator"+
         "\r\n\r\n#{data}"
         
  end
  def http_post(server,buff)
    ip=server[/http:\/\/([^:]+):(\d+)\/.*/,1]
    port=server[/http:\/\/([^:]+):(\d+)\/.*/,2]
    puts "Connect to #{ip}  => #{port}  #{server}"
    so=TCPSocket.new(ip,port)
    so.sync=true
    so.write(buff)
    buff.showXmlData("Soap Request:")
    reponse=""<commit_msg>trace xml request if $DEBUG<commit_after>require 'socket'
require 'timeout'

class ClientSoap
  def initialize(template,namespace,config) 
    @template=template
    @namespace=namespace
    p @namespace
    @config=config 
  end
  def format(request,hparam) 
    buff= @template[:config][request][:req].dup
    @config.each { |k,value| buff.sub!(k,value.to_s) }
    buff.sub!(/<SOAP-ENV:Envelope\s+></,'<SOAP-ENV:Envelope '+@namespace+'><')
    buff.sub!(/<soap:Envelope\s+></,'<soap:Envelope '+@namespace+'><')
    buff.sub!(/(#{@config["HMESSID"]})/,"#{(Time.now.to_f*1000).round}")
    hparam.each { |k,value| buff.gsub!(k,value.to_s) }
    #buff.gsub!(/<wsa5:From>.*?<\/wsa5:From>/,"")    if @config["nonFrom"]
    puts "\n#{'='*80}\n#{buff.gsub("><",">\n<")}\n#{'='*80}\n" if $DEBUG
    buff
  end
  def format_http(server,request,hparam)
    data=format(request,hparam)
    action=data[/<.*?Action.*?>([^<]+)<\/.*?Action.*?>/,1]
    "POST #{server} HTTP/1.1\r\nAccept-Encoding: gzip,deflate\r\nContent-Type: application/soap+xml;charset=UTF-8;action=\"#{action}\"\r\n"+
         "Content-Length: #{data.size}\r\nHost: localhost:9999\r\nConnection: close\r\nUser-Agent: ocpp-simulator"+
         "\r\n\r\n#{data}"
         
  end
  def http_post(server,buff)
    ip=server[/http:\/\/([^:]+):(\d+)\/.*/,1]
    port=server[/http:\/\/([^:]+):(\d+)\/.*/,2]
    puts "Connect to #{ip}  => #{port}  #{server}"
    so=TCPSocket.new(ip,port)
    so.sync=true
    so.write(buff)
    buff.showXmlData("Soap Request:")
    reponse=""
{'fraction_non_alphanumeric': 0.24991579656449983, 'fraction_numerical': 0.01212529471202425, 'mean_word_length': 3.767255216693419, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4773171', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1180, 'n_words': 139}