We are getting the ORA-29270:too many open HTTP requests when try to execute the Below Procedure. Please let us know where and all we need to close the Request and Response , Please provide one of the Procedure example how we can handle the exception. and all the request should process Properly.
BEGIN
l_http_request := utl_http.begin_request (p_url, 'POST');
BEGIN
-- build the request by using utl_http.set_header() and utl_http.write_text()
-- ...
-- process the request and get the response:
l_http_response := utl_http.get_response (l_http_request);
WHEN OTHERS THEN
--- utl_http.end_response(http_resp);
error_code := '91';
error_desc := SQLERRM || ' Unhandled Exception';
END;
BEGIN
LOOP
-- read the response using utl_http.read_line()
-- ...
END LOOP;
-- Complete the request and response, and close the network connection
utl_http.end_response(l_http_response);
EXCEPTION
when utl_http.end_of_body then
utl_http.end_response(http_resp);
WHEN error_out THEN
NULL;
WHEN OTHERS THEN
--- utl_http.end_response(http_resp);
error_code := '91';
error_desc := SQLERRM || ' Unhandled Exception';
END;
END;
Hello: I happen to be addressing the same error in my own code. I fixed mine by adding utl_http.end_response(l_http_response) - which you already have.
But I notice you use two different arguments in your end_response call. Try changing
utl_http.end_response(http_resp);
to
utl_http.end_response(l_http_response);
in your exception block. I hope this helps. Cheers, Hawk
Related
I have already tried code from StackOverflow, f.e. Download, pause and resume an download using Indy components.
But when I try to use IdHttp1.Disconnect() in order to pause download and then resume it, the download does not resume. The file is downloaded from zero. So, what should I do in order to add resume support to my Delphi app?
BTW: the server allows download resuming, because IDM can resume the download.
You have to check the size of the remote file, and the size of the local file (if exists).
If the size of the remote file is larger than the size of the local file, then you have to set the Ranges property of the Request property of TIdHTTP to the starting point (the local file size).
For example, if the remote file size is 100000 bytes, and the local file size is 80000 bytes, then you have to set http.Request.Ranges to start at 80000.
Here is a fully working code for you to use:
function FileSize(const FileName: string): Int64;
var
AttributeData: TWin32FileAttributeData;
begin
if GetFileAttributesEx(PChar(FileName), GetFileExInfoStandard, #AttributeData) then
begin
Int64Rec(Result).Lo := AttributeData.nFileSizeLow;
Int64Rec(Result).Hi := AttributeData.nFileSizeHigh;
end
else
Result := -1;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
http: TIdHTTP;
FS: TFileStream;
file_url: String;
file_path: String;
web_file_size: Integer;
local_file_size: Integer;
IhaveToDownload: Boolean;
begin
file_url := 'http://212.183.159.230/50MB.zip';
file_path := 'C:\50MB.zip';
IhaveToDownload := False;
FS := nil;
http := TIdHTTP.Create(nil);
try
//I will check if local file exists
if FileExists(file_path) then
begin
//I have to run http.Head() to get the ContentLength of the remote file.
http.Head(file_url);
//web_file_size now has the remote file size in bytes
web_file_size := http.Response.ContentLength;
//local_file_size now has the local file size in bytes
local_file_size := FileSize(file_path);
//check if remote file is bigger than local file (so I have to resume download)
if (web_file_size > local_file_size) and (http.Response.AcceptRanges = 'bytes') then
begin
//remote file is bigger than local file, so I will resume download.
http.Request.Ranges.Add.StartPos := local_file_size;
FS := TFileStream.Create(file_path, fmOpenReadWrite);
FS.Position := local_file_size;
IhaveToDownload := True;
end
else if web_file_size <> local_file_size then
begin
//remote file is not equal with local file, so I will restart download.
FS := TFileStream.Create(file_path, fmCreate);
IhaveToDownload := True;
end;
end
else
begin
//File does not exist locally. I will create a new local file
FS := TFileStream.Create(file_path, fmCreate);
IhaveToDownload := True;
end;
if IhaveToDownload then
http.Get(file_url, FS);
finally
FS.Free;
http.Free;
end;
end;
I'm trying to build up an installer using Inno Setup. I need to setup a prerequisite installation for .NET Core framework. By far I'm able to detect .NET Core existence. But I'm having difficulty with executing the installation.
Here's the code I have by far:
[Files]
Source: "\\shared\path\dotnet-runtime-3.1.10-win-x64.exe"; DestDir: "{tmp}"; \
Flags: deleteafterinstall; BeforeInstall: InstallFramework; \
Check: FrameworkIsNotInstalled
[Code]
var
CancelWithoutPrompt: boolean;
InstallValue: Cardinal;
function InitializeSetup(): Boolean;
begin
CancelWithoutPrompt := false;
result := true;
end;
procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
if CurPageID=wpInstalling then
Confirm := not CancelWithoutPrompt;
end;
function FrameworkIsNotInstalled: Boolean;
begin
Result := not RegQueryDWordValue(HKEY_LOCAL_MACHINE,
'SOFTWARE\WOW6432Node\dotnet\Setup\InstalledVersions\x64\sharedfx\Microsoft.NETCore.App',
'3.1.10', InstallValue) or (InstallValue <> 1)
end;
procedure InstallFramework;
var
StatusText: string;
ResultCode: Integer;
begin
StatusText := WizardForm.StatusLabel.Caption;
WizardForm.StatusLabel.Caption := 'Installing .net core framework...';
WizardForm.ProgressGauge.Style := npbstMarquee;
try
if not Exec(ExpandConstant('{tmp}\dotnet-runtime-3.1.10-win-x64.exe'), '/q /norestart', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
begin
// you can interact with the user that the installation failed
MsgBox('.NET Core installation failed with code: ' + IntToStr(ResultCode) + '.',
mbError, MB_OK);
CancelWithoutPrompt := true;
WizardForm.Close;
end;
finally
WizardForm.StatusLabel.Caption := StatusText;
WizardForm.ProgressGauge.Style := npbstNormal;
end;
end;
I'm getting result code 2 response from the installation, anyone could enlighten me what's code 2 error about? Or is that any way I could extract further detail on the error information? I tried empty argument and tried to search for Code 2 error information on the internet but still no luck.
I had tried with Shellexec and both return the same result
The installation directly using the .net exe are working fine locally
Any help or information would be much appreciate =)
You are trying to run the dotnet-runtime-3.1.10-win-x64.exe before you actually "install" it to the {tmp}:
BeforeInstall: InstallFramework
You have to use the AfterInstall parameter:
AfterInstall: InstallFramework
I am struggling to know how to access the response to an Indy POST request. I post the data either as JSON or paramstring. My code when using JSON is as follows.
params := TStringList.Create;
try
params.Text :=
'{'
+ format ('"client_secret":"%s",', [FilesFrm.ClientSecret])
+ format ('"client_id":"%s",', [FilesFrm.ClientId])
+ '"grant_type":"authorization_code",'
+ '"redirect_uri":"http://localhost:8080",'
+ format ('"code":"%s"', [fCode])
+ '}';
idLogFile1.Active := true;
// Make sure it uses HTTP 1.1, not 1.0
IdHTTP1.HTTPOptions := IdHTTP1.HTTPOptions + [hoKeepOrigProtocol];
IdHTTP1.Request.ContentType := 'application/json';
IdHttp1.Request.Accept := 'application/vnd.hmrc.1.0+json';
try
result := IdHTTP1.Post (
'https://test-api.service.hmrc.gov.uk/oauth/token',
params);
except
on E: Exception do
memo1.lines.add (E.ClassName + ': ' + E.message);
end;
memo1.Lines.add (result);
memo1.Lines.add (idHTTP1.ResponseText);
finally
params.free;
end;
The result of printing out result and RepsonseText is just
EIdHTTPProtocolException: HTTP/1.1 400 Bad Request
HTTP/1.1 400 Bad Request
However, because I have a TidLogFile component attached to the TidHTTP, I can see what actually arrives, which is the following.
Recv 2/1/2019 7:56:07 AM: HTTP/1.1 400 Bad Request<EOL>
Content-Type: application/json<EOL>
Content-Length: 72<EOL>
Cache-Control: no-cache,no-store,etc, etc...
; Secure; HTTPOnly<EOL><EOL>
{"error":"invalid_request","error_description":"grant_type is required"}
Aside from the fact that grant_type appears to be in the original request data, I would like to be able to access the JSON response at the end, since "grant_type_is_required" is much more helpful than "Bad request", but I cannot find where it is.
I have subsequently found Response.ContentLength, which contains the value 72, and Response.ContentStream, which should in theory contain the 72 bytes of data, but produces access violations when I try to extract the data.
len := idHTTP1.Response.ContentLength;
memo1.Lines.Add(format ('Length = %d', [len]));
if assigned (idHTTP1.Response.ContentStream) then
begin
//idHTTP1.Response.ContentStream.Position := 0;
result := ReadStringFromStream (idHTTP1.Response.ContentStream, len);
end;
memo1.lines.add (result);
In addition to mjn42's answer, which is technically correct, TIdHTTP also has optional hoNoProtocolErrorException and hoWantProtocolErrorContent flags in its HTTPOptions property, which you can enable to avoid the EIdHTTPProtocolException being raised and to populate your result variable with error data, respectively:
params := TStringStream.Create(
'{'
+ format ('"client_secret":"%s",', [FilesFrm.ClientSecret])
+ format ('"client_id":"%s",', [FilesFrm.ClientId])
+ '"grant_type":"authorization_code",'
+ '"redirect_uri":"http://localhost:8080",'
+ format ('"code":"%s"', [fCode])
+ '}',
TEncoding.UTF8);
try
IdLogFile1.Active := true;
// Make sure it uses HTTP 1.1, not 1.0,
// and disable EIdHTTPProtocolException on errors
IdHTTP1.ProtocolVersion := pv1_1;
IdHTTP1.HTTPOptions := IdHTTP1.HTTPOptions + [hoKeepOrigProtocol, hoNoProtocolErrorException, hoWantProtocolErrorContent];
IdHTTP1.Request.ContentType := 'application/json';
IdHTTP1.Request.Accept := 'application/vnd.hmrc.1.0+json';
try
result := IdHTTP1.Post('https://test-api.service.hmrc.gov.uk/oauth/token', params);
except
on E: Exception do begin
Memo1.Lines.Add(E.ClassName + ': ' + E.message);
raise;
end;
end;
Memo1.Lines.Add(result);
finally
params.Free;
end;
Here is an example which shows how the HTTP body can be accessed.
The body can be accessed if you catch the EIdHTTPProtocolException exception.
on E: EIdHTTPProtocolException do
begin
WriteLn(E.Message);
WriteLn(E.ErrorMessage);
end;
Full example code:
program JSONPostExample;
{$APPTYPE CONSOLE}
uses
IdHTTP, IdGlobal, SysUtils, Classes;
var
HTTP: TIdHTTP;
RequestBody: TStream;
ResponseBody: string;
begin
HTTP := TIdHTTP.Create;
try
try
RequestBody := TStringStream.Create('{"日本語":42}',
TEncoding.UTF8);
try
HTTP.Request.Accept := 'application/json';
HTTP.Request.ContentType := 'application/json';
ResponseBody := HTTP.Post('https://httpbin.org/post',
RequestBody);
WriteLn(ResponseBody);
WriteLn(HTTP.ResponseText);
finally
RequestBody.Free;
end;
except
on E: EIdHTTPProtocolException do
begin
WriteLn(E.Message);
WriteLn(E.ErrorMessage);
end;
on E: Exception do
begin
WriteLn(E.Message);
end;
end;
finally
HTTP.Free;
end;
ReadLn;
ReportMemoryLeaksOnShutdown := True;
end.
Note that you must not use a TStringList for the POST body. That version of TIdHTTP.Post() formats the data according to the application/x-www-form-urlencoded media type, which is not appropriate for JSON and will corrupt it.
utl_http.end_response(http_resp) ;
-- x_clob response can now be used for extracting text
-- values from specific XML nodes, using XMLExtract
EXCEPTION
WHEN ERROR_OUT THEN
error_code := error_code;
error_desc := error_desc; ---SQLERRM||' Unhandled Exception';
WHEN OTHERS THEN
error_code := '91';
error_desc := SQLERRM || ' Unhandled Exception';
dbms_output.put_line('Error desc:' || error_desc );
end;
/
Getting Below error after the Procedure execution
HTTP Request Failed
ORA-29270: too many open HTTP requests
Many time this procedure will be executed.
let me know how to End some HTTP requests and response and execute all the Request
I have created a web service using ASP.NET.
I tried to access this url from a PL/sql program through UTL_DBWS package. After execution i am receiving below error:
ORA-29532: Java call terminated by uncaught Java exception: port: {http://tempuri.org/}Service1Soap
does not contain operation: Envelope
Can any one of you please tell what steps of configuration I am missing.
I really apprcite your help.
Oracle procedure to call to asp.net service is :
create or replace procedure check_dbws
AS
l_service UTL_DBWS.service;
l_call UTL_DBWS.call;
l_wsdl_url VARCHAR2(32767);
l_namespace VARCHAR2(32767);
l_service_qname UTL_DBWS.qname;
l_port_qname UTL_DBWS.qname;
l_operation_qname UTL_DBWS.qname;
l_xmltype_in SYS.XMLTYPE;
l_xmltype_out SYS.XMLTYPE;
p_fault_node xmltype;
l_return NUMBER;
l_int_type utl_dbws.qname;
l_string_type utl_dbws.QNAME;
BEGIN
l_wsdl_url := 'http://localhost/TestWebService/Service1.asmx?wsdl';
l_namespace := 'http://tempuri.org/';
l_service_qname := UTL_DBWS.to_qname(l_namespace, 'Service1');
l_port_qname := UTL_DBWS.to_qname(l_namespace, 'Service1Soap');
l_operation_qname := UTL_DBWS.to_qname(l_namespace, 'DBConnect');
l_service := UTL_DBWS.create_service (
wsdl_document_location => URIFACTORY.getURI(l_wsdl_url),
service_name => l_service_qname);
l_call := UTL_DBWS.create_call (
service_handle => l_service,
port_name => l_port_qname,
operation_name => l_operation_qname);
utl_dbws.set_property (l_call,'SOAPACTION_USE','TRUE');
utl_dbws.set_property (l_call,'SOAPACTION_URI', 'DBConnect');
utl_dbws.set_property(l_call,'ENCODINGSTYLE_URI', 'http://schemas.xmlsoap.org/soap/encoding/');
utl_dbws.set_property(l_call,'OPERATION_STYLE', 'document');
l_string_type :=utl_dbws.to_qname('http://www.w3.org/2001/xmlschema','String');
utl_dbws.add_parameter(l_call,'Request',l_string_type,'ParameterMode.IN');
utl_dbws.set_return_type(l_call,l_string_type);
l_xmltype_in:=sys.xmltype('<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v002="http://tempuri.org/DBConnect">
<soapenv:Header/>
<soapenv:Body>
<DBConnect>
<Name>Test</Name>
<DBConnect>
</soapenv:Body>
</soapenv:Envelope>');
l_xmltype_out := UTL_DBWS.invoke (call_handle => l_call,,request => l_xmltype_in);
p_fault_node := l_xmltype_out.extract('//soap:Fault', 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/');
if (p_fault_node is not null) then
dbms_output.put_line(p_fault_node.getclobval());
l_return:=2;
elsif l_xmltype_out is not null then
dbms_output.put_line(l_xmltype_out.getclobval());
l_return:=1;
else
dbms_output.put_line('errorin fault'||sqlerrm);
l_return:=0;
end if;
UTL_DBWS.release_call (call_handle => l_call);
UTL_DBWS.release_service (service_handle => l_service);
dbms_output.put_line(l_result.AccessVarchar2);
END;
have a look at my answer here; you may not have all the Java classes required to get UTL_DBWS to work. And, per my answer there, I'll reiterate, I found it much easier to use UTL_HTTP than UTL_DBWS and continue to use UTL_HTTP since I ran into so many limitations and issues with UTL_DBWS.