Commit 9ee153ad authored by Roque's avatar Roque

solving http request issue due to frontend ciphers

- see #1
parent 15ea30c8
#! /usr/bin/env bash
DOWN_URL='https://softinst104003.host.vifib.net/erp5/'
ING_URL='https://softinst104003.host.vifib.net/erp5/portal_ingestion_policies/wendelin_embulk'
DOWN_URL='https://softinst104003.lhost.vifib.net/erp5/'
ING_URL='https://softinst104003.lhost.vifib.net/erp5/portal_ingestion_policies/wendelin_embulk'
EBULK_VERSION="0.9.7"
EBULK_DATA_PATH=~/.ebulk
......
......@@ -36,7 +36,7 @@ class WendelinClient
checkReferenceChars(reference)
uri = URI(URI.escape("#{@erp5_url}/ingestionReferenceExists?reference=#{reference}"))
begin
res = open(uri, http_basic_authentication: [@user, @password]).read
response = handleRequest(uri)
rescue Exception => e
@logger.error("An error occurred while checking if reference exists: " + e.to_s)
@logger.error(e.backtrace)
......@@ -45,7 +45,7 @@ class WendelinClient
end
return FALSE
else
return res.to_s == 'TRUE'
return response.to_s == 'TRUE'
end
end
......@@ -78,8 +78,8 @@ class WendelinClient
else
@logger.info("Increasing dataset version")
begin
uri = URI(URI.escape("#{@erp5_url}/ERP5Site_increaseDatasetVersion?reference=#{reference}"))
res = open(uri, http_basic_authentication: [@user, @password]).read
uri = URI(URI.escape("#{@erp5_url}/ERP5Site_increaseDatasetVersion?reference=#{reference}"))
response = handleRequest(uri)
rescue Exception => e
@logger.error("An error occurred while increasing dataset version: " + e.to_s)
@logger.error(e.backtrace)
......@@ -151,7 +151,7 @@ class WendelinClient
n_retry = 0
while ! success && n_retry < 10
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|
chunk = content.read()
if chunk.nil? || chunk.empty?
......@@ -196,54 +196,53 @@ class WendelinClient
private
def handleRequest(uri, reference=nil, data_chunk=nil)
req = Net::HTTP::Post.new(uri)
req.basic_auth @user, @password
if data_chunk != 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
req = Net::HTTP::Post.new(uri)
req.basic_auth @user, @password
if data_chunk != nil
@logger.info("Setting request form data...", print=TRUE) if reference != nil
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
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("HTTP ERROR: " + e.to_s, print=TRUE)
@logger.error(e.backtrace)
return {"success"=>FALSE, "message"=>HTTP_MESSAGE_EXCEPTION}
@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
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
if res.kind_of?(Net::HTTPSuccess) # res.code is 2XX
@logger.info("Done")
return {"success"=>TRUE, "message"=>res.body}
else
@logger.error("HTTP FAIL - code: #{res.code}", print=TRUE)
if res.code == '500' or res.code == '502' or res.code == '503'
@logger.error(HTTP_MESSAGE_5XX, print=TRUE)
elsif res.code == '401'
@logger.error(HTTP_MESSAGE_401, print=TRUE)
@logger.abortExecution()
elsif res.code == '400'
@logger.error(HTTP_MESSAGE_400, print=TRUE)
@logger.abortExecution()
else
@logger.error(HTTP_MESSAGE_OTHER, print=TRUE)
end
return {"success"=>FALSE, "message"=>HTTP_MESSAGE_NOT_2XX}
end
end
@logger.error("HTTP FAIL - code: #{res.code}", print=TRUE)
if res.code == '500' or res.code == '502' or res.code == '503'
@logger.error(HTTP_MESSAGE_5XX, print=TRUE)
elsif res.code == '401'
@logger.error(HTTP_MESSAGE_401, print=TRUE)
@logger.abortExecution()
elsif res.code == '400'
@logger.error(HTTP_MESSAGE_400, print=TRUE)
@logger.abortExecution()
else
@logger.error(HTTP_MESSAGE_OTHER, print=TRUE)
end
return {"success"=>FALSE, "message"=>HTTP_MESSAGE_NOT_2XX}
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