Advertisement
Guest User

Untitled

a guest
Jun 12th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. # this file runs a given sparql query on prism endpoint
  2. # run as /usr/bin/time -v ruby prism-query.rb
  3. require 'net/https'
  4.  
  5. f = File.new(ARGV[0])
  6.  
  7. text = f.read
  8. url = URI.encode("https://localhost:8443/prism/rest/sparql?query=#{text}")
  9.  
  10. http = Net::HTTP.new('localhost', '8443')
  11. http.use_ssl = true
  12. http.read_timeout = 1800
  13. http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  14. p12 = OpenSSL::PKCS12.new(File.read("/usr/local/prism-1.0.9/certs/certs/testuser/testuser.p12"), "changeit")
  15. http.cert = p12.certificate
  16. http.key = p12.key
  17. url.gsub!("https://localhost:8443", "")
  18. url.gsub!("=", "%3D")
  19. url.gsub!("?", "%3F")
  20. url.gsub!("!", "%21")
  21. url.gsub!("&", "%26")
  22. url.gsub!("%3Fquery%3D", "?query=")
  23. req = Net::HTTP::Get.new(url)
  24. result = http.start {|http|
  25. result = http.request(req)
  26. #puts result.body
  27. if result.body.include?("<boolean>")
  28. puts "Boolean Result: " + result.body.match(/<boolean>(.+?)<\/boolean>/)[1]
  29. else
  30. puts "Number of Results: " + result.body.scan(/<result>/).length.to_s
  31. end
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement