The Precondition on the Request for the Url /upload/file-upload.Cgi Evaluated to False. Apache
In my Oracle REST Services Demos I always show things working exactly as planned.
Only what happens when your user does something your plan doesn't look?
Or what happens when you code does something you don't expect? In the web (HTTP) earth, you get a 500.
ten.five.one 500 Internal Server Error
The server encountered an unexpected status which prevented information technology from fulfilling the request.
Thankfully, PL/SQL provides EXCEPTIONS. We tin say, when this bad thing happens, run this code instead. And really, as developers we should be good enough to expect certain problems to occur and to plan for them.
When something doesn't work in your database lawmaking attached to a RESTful Service, you get a HTTP Condition code of 500.
This isn't friendly.
Permit'due south expect at an un-handled exception in ORDS from the user perspective.
Bad

This looks quite unprofessional. Not the warm and fuzzy feel you lot want when doing business with a partner or vendor. What if that was the response I got when trying to buy the WiFi on my airline with my credit card? (A completely imitation/did not actually happen in real life scenario which happened to me yesterday).
Less Bad

We have a proper status code and a message returned from the server (ORDS).
Now, a perfect scenario would include having some client-side validation of the inputs, preventing me from sending bad values in the first place. But even then, information technology'southward best to plan for the common scenarios. For example, what if your service is available Exterior the intended application where there is no validation of inputs happening?
Anyways, let's see how I made this happen. And it's quite uncomplicated really.
The Exception
When you try to select a string into a number in Oracle, you get a ORA-06502. And if nosotros wait into the ORDS log, we can run into this popular out when I make the bad phone call w/o treatment the exception:
Caused By : Mistake : 6502 , Position : 0 , SQL = DECLARE x INTEGER ; Begin SELECT : i INTO x FROM dual; : 2 := 'You passed in this number: ' || x; End ;, OriginalSql = DECLARE 10 INTEGER ; BEGIN SELECT ? INTO x FROM dual; ? := 'You passed in this number: ' || x; Finish ;, Fault Msg = ORA-06502: PL/ SQL : numeric OR VALUE fault: graphic symbol TO NUMBER conversion error ORA-06512: AT line iv
Then, I need to account for the ORA-06502 in my handler code. Here's how I've done that.
DECLARE x INTEGER ; not_a_number EXCEPTION ; PRAGMA EXCEPTION_INIT(not_a_number, -06502) ; Begin SELECT :num_in INTO x FROM dual; :string_out := 'You passed in this number: ' || x; EXCEPTION WHEN not_a_number THEN :string_out := 'That was Non a number!' ; :status := 400 ; Cease ;
I've set the out going message/response to something a bit more than helpful than a ¯\_(ツ)_/¯ and I've set up the response to a HTTP 400, which means:
'10.4.ane 400 Bad Request – The request could non exist understood by the server due to malformed syntax. The client SHOULD NOT repeat the asking without modifications.'
Note to laissez passer the condition back I had to set a parameter for my handler lawmaking for '10-ORDS-Condition-Lawmaking'

I'thousand Getting 500's merely I Don't Know Why?
You demand to get to the ORDS standard output logs. If yous're running ORDS, hopefully you're logging that somewhere. If information technology's Tomcat (Catalina) or WLS, they take places for that. If it's in standalone mode, you demand to redirect that out to a file yourself.
Or…per the troubleshooting guide (DOCS!), you can do this:

Restart ORDS, run your request once more:

By the fashion, Practice NOT Do THIS IN PROD. You volition be exposing details of your database to people you do not want to. Similar those mysql errors yous meet when you endeavor to striking a website and information technology overloads their system. Oh, that's MySQL, and they take a table named 'XYZ'…ahhh. Aye, that's bad.
The Lawmaking
Here'southward how I called it:
curl --request Get \ --url http://localhost:8080/ords/hour/exceptions/unhandled \ --header 'authorization: Bones Y29sbTpvcmFjbGU=' \ --header 'num_in: how-do-you-do'
My ORDS handler pulls the value out of the header (num_in) and tries to convert it to a number (x) – which works just fine if your string just happens to exist a number already. I then laissez passer dorsum a message maxim, hey, cheers for passing me that number, and hither it is again merely so you know I got it correctly.
Here's the module for my exception, handled and un-handled.
-- Generated by Oracle SQL Developer REST Data Services eighteen.iii.0.276.0148 -- Exported REST Definitions from ORDS Schema Version 18.3.0.r2701456 -- Schema: Hour Date: Friday October 26 11:14:42 EDT 2018 -- Begin ORDS.ENABLE_SCHEMA( p_enabled => TRUE , p_schema => 'HR' , p_url_mapping_type => 'BASE_PATH' , p_url_mapping_pattern => '60 minutes' , p_auto_rest_auth => FALSE ) ; ORDS.DEFINE_MODULE( p_module_name => 'exceptions' , p_base_path => '/exceptions/' , p_items_per_page => 25 , p_status => 'PUBLISHED' , p_comments => NULL ) ; ORDS.DEFINE_TEMPLATE( p_module_name => 'exceptions' , p_pattern => 'handled' , p_priority => 0 , p_etag_type => 'HASH' , p_etag_query => Nothing , p_comments => NULL ) ; ORDS.DEFINE_HANDLER( p_module_name => 'exceptions' , p_pattern => 'handled' , p_method => 'Go' , p_source_type => 'plsql/block' , p_items_per_page => 25 , p_mimes_allowed => '' , p_comments => Nothing , p_source => 'declare x integer; not_a_number EXCEPTION; PRAGMA EXCEPTION_INIT(not_a_number, -06502); begin select :num_in into 10 from dual; :string_out := ' 'You passed in this number: ' ' || ten; EXCEPTION WHEN not_a_number THEN :string_out := ' 'That was Non a number!' '; :status := 400; stop;' ) ; ORDS.DEFINE_PARAMETER( p_module_name => 'exceptions' , p_pattern => 'handled' , p_method => 'GET' , p_name => 'X-ORDS-Condition-Code' , p_bind_variable_name => 'status' , p_source_type => 'HEADER' , p_param_type => 'INT' , p_access_method => 'OUT' , p_comments => Goose egg ) ; ORDS.DEFINE_PARAMETER( p_module_name => 'exceptions' , p_pattern => 'handled' , p_method => 'GET' , p_name => 'num_in' , p_bind_variable_name => 'num_in' , p_source_type => 'HEADER' , p_param_type => 'STRING' , p_access_method => 'IN' , p_comments => Null ) ; ORDS.DEFINE_PARAMETER( p_module_name => 'exceptions' , p_pattern => 'handled' , p_method => 'GET' , p_name => 'string_out' , p_bind_variable_name => 'string_out' , p_source_type => 'RESPONSE' , p_param_type => 'String' , p_access_method => 'OUT' , p_comments => NULL ) ; ORDS.DEFINE_TEMPLATE( p_module_name => 'exceptions' , p_pattern => 'unhandled' , p_priority => 0 , p_etag_type => 'HASH' , p_etag_query => NULL , p_comments => NULL ) ; ORDS.DEFINE_HANDLER( p_module_name => 'exceptions' , p_pattern => 'unhandled' , p_method => 'GET' , p_source_type => 'plsql/cake' , p_items_per_page => 25 , p_mimes_allowed => '' , p_comments => Naught , p_source => 'declare 10 integer; begin select :num_in into x from dual; :string_out := ' 'You passed in this number: ' ' || x; end;' ) ; ORDS.DEFINE_PARAMETER( p_module_name => 'exceptions' , p_pattern => 'unhandled' , p_method => 'GET' , p_name => 'num_in' , p_bind_variable_name => 'num_in' , p_source_type => 'HEADER' , p_param_type => 'String' , p_access_method => 'IN' , p_comments => NULL ) ; ORDS.DEFINE_PARAMETER( p_module_name => 'exceptions' , p_pattern => 'unhandled' , p_method => 'GET' , p_name => 'string_out' , p_bind_variable_name => 'string_out' , p_source_type => 'RESPONSE' , p_param_type => 'String' , p_access_method => 'OUT' , p_comments => NULL ) ; COMMIT ; Cease ;
alexanderyoulthad95.blogspot.com
Source: https://www.thatjeffsmith.com/archive/2018/10/preventing-500-status-codes-with-oracle-rest-data-services/
Enregistrer un commentaire for "The Precondition on the Request for the Url /upload/file-upload.Cgi Evaluated to False. Apache"