Commit 9ee153ad authored by Roque's avatar Roque

solving http request issue due to frontend ciphers

- see #1
parent 15ea30c8
#! /usr/bin/env bash #! /usr/bin/env bash
DOWN_URL='https://softinst104003.host.vifib.net/erp5/' DOWN_URL='https://softinst104003.lhost.vifib.net/erp5/'
ING_URL='https://softinst104003.host.vifib.net/erp5/portal_ingestion_policies/wendelin_embulk' ING_URL='https://softinst104003.lhost.vifib.net/erp5/portal_ingestion_policies/wendelin_embulk'
EBULK_VERSION="0.9.7" EBULK_VERSION="0.9.7"
EBULK_DATA_PATH=~/.ebulk EBULK_DATA_PATH=~/.ebulk
......
...@@ -36,7 +36,7 @@ class WendelinClient ...@@ -36,7 +36,7 @@ class WendelinClient
checkReferenceChars(reference) checkReferenceChars(reference)
uri = URI(URI.escape("#{@erp5_url}/ingestionReferenceExists?reference=#{reference}")) uri = URI(URI.escape("#{@erp5_url}/ingestionReferenceExists?reference=#{reference}"))
begin begin
res = open(uri, http_basic_authentication: [@user, @password]).read response = handleRequest(uri)
rescue Exception => e rescue Exception => e
@logger.error("An error occurred while checking if reference exists: " + e.to_s) @logger.error("An error occurred while checking if reference exists: " + e.to_s)
@logger.error(e.backtrace) @logger.error(e.backtrace)
...@@ -45,7 +45,7 @@ class WendelinClient ...@@ -45,7 +45,7 @@ class WendelinClient
end end
return FALSE return FALSE
else else
return res.to_s == 'TRUE' return response.to_s == 'TRUE'
end end
end end
...@@ -78,8 +78,8 @@ class WendelinClient ...@@ -78,8 +78,8 @@ class WendelinClient
else else
@logger.info("Increasing dataset version") @logger.info("Increasing dataset version")
begin begin
uri = URI(URI.escape("#{@erp5_url}/ERP5Site_increaseDatasetVersion?reference=#{reference}")) uri = URI(URI.escape("#{@erp5_url}/ERP5Site_increaseDatasetVersion?reference=#{reference}"))
res = open(uri, http_basic_authentication: [@user, @password]).read response = handleRequest(uri)
rescue Exception => e rescue Exception => e
@logger.error("An error occurred while increasing dataset version: " + e.to_s) @logger.error("An error occurred while increasing dataset version: " + e.to_s)
@logger.error(e.backtrace) @logger.error(e.backtrace)
...@@ -151,7 +151,7 @@ class WendelinClient ...@@ -151,7 +151,7 @@ class WendelinClient
n_retry = 0 n_retry = 0
while ! success && n_retry < 10 while ! success && n_retry < 10
begin begin
res = open(uri, http_basic_authentication: [@user, @password]) { res = open(uri, http_basic_authentication: [@user, @password], ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE) {
|content| |content|
chunk = content.read() chunk = content.read()
if chunk.nil? || chunk.empty? if chunk.nil? || chunk.empty?
...@@ -196,54 +196,53 @@ class WendelinClient ...@@ -196,54 +196,53 @@ class WendelinClient
private private
def handleRequest(uri, reference=nil, data_chunk=nil) def handleRequest(uri, reference=nil, data_chunk=nil)
req = Net::HTTP::Post.new(uri) req = Net::HTTP::Post.new(uri)
req.basic_auth @user, @password req.basic_auth @user, @password
if data_chunk != nil
if data_chunk != nil @logger.info("Setting request form data...", print=TRUE) if reference != nil
@logger.info("Setting request form data...", print=TRUE) if reference != nil
begin
req.set_form_data('data_chunk' => data_chunk)
rescue java.lang.OutOfMemoryError
@logger.logOutOfMemoryError(reference)
return {"success"=>FALSE, "message"=>HTTP_MEMORY_ERROR}
rescue Exception => e
@logger.error("Error setting form data: " + e.to_s, print=TRUE)
@logger.error(e.backtrace)
return {"success"=>FALSE, "message"=>HTTP_MESSAGE_EXCEPTION}
end
@logger.info("Sending record:'#{reference}'...", print=TRUE) if reference != nil
end
begin begin
res = Net::HTTP.start(uri.hostname, uri.port, req.set_form_data('data_chunk' => data_chunk)
:use_ssl => (uri.scheme == 'https'), rescue java.lang.OutOfMemoryError
:verify_mode => OpenSSL::SSL::VERIFY_NONE, @logger.logOutOfMemoryError(reference)
:ssl_timeout => 300, :open_timeout => 300, :read_timeout => 300, return {"success"=>FALSE, "message"=>HTTP_MEMORY_ERROR}
) do |http|
http.request(req)
end
rescue Exception => e rescue Exception => e
@logger.error("HTTP ERROR: " + e.to_s, print=TRUE) @logger.error("Error setting form data: " + e.to_s, print=TRUE)
@logger.error(e.backtrace) @logger.error(e.backtrace)
return {"success"=>FALSE, "message"=>HTTP_MESSAGE_EXCEPTION} return {"success"=>FALSE, "message"=>HTTP_MESSAGE_EXCEPTION}
end
@logger.info("Sending record:'#{reference}'...", print=TRUE) if reference != nil
end
begin
res = Net::HTTP.start(uri.hostname, uri.port,
:use_ssl => (uri.scheme == 'https'),
:verify_mode => OpenSSL::SSL::VERIFY_NONE,
:ssl_timeout => 300, :open_timeout => 300, :read_timeout => 300,
) do |http|
http.request(req)
end
rescue Exception => e
@logger.error("HTTP ERROR: " + e.to_s, print=TRUE)
@logger.error(e.backtrace)
return {"success"=>FALSE, "message"=>HTTP_MESSAGE_EXCEPTION}
else
if res.kind_of?(Net::HTTPSuccess) # res.code is 2XX
@logger.info("Done")
return {"success"=>TRUE, "message"=>res.body}
else else
if res.kind_of?(Net::HTTPSuccess) # res.code is 2XX @logger.error("HTTP FAIL - code: #{res.code}", print=TRUE)
@logger.info("Done") if res.code == '500' or res.code == '502' or res.code == '503'
return {"success"=>TRUE, "message"=>res.body} @logger.error(HTTP_MESSAGE_5XX, print=TRUE)
else elsif res.code == '401'
@logger.error("HTTP FAIL - code: #{res.code}", print=TRUE) @logger.error(HTTP_MESSAGE_401, print=TRUE)
if res.code == '500' or res.code == '502' or res.code == '503' @logger.abortExecution()
@logger.error(HTTP_MESSAGE_5XX, print=TRUE) elsif res.code == '400'
elsif res.code == '401' @logger.error(HTTP_MESSAGE_400, print=TRUE)
@logger.error(HTTP_MESSAGE_401, print=TRUE) @logger.abortExecution()
@logger.abortExecution() else
elsif res.code == '400' @logger.error(HTTP_MESSAGE_OTHER, print=TRUE)
@logger.error(HTTP_MESSAGE_400, print=TRUE) end
@logger.abortExecution() return {"success"=>FALSE, "message"=>HTTP_MESSAGE_NOT_2XX}
else end
@logger.error(HTTP_MESSAGE_OTHER, print=TRUE) end
end
return {"success"=>FALSE, "message"=>HTTP_MESSAGE_NOT_2XX}
end
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment