Oracle Rest Data service - customise response status code - oracle-apex

By default all successfull request on ORDS respond with status code 200 Ok. it is well.
But on occassion I need respond with on customizable error code, ie. 201 , 202 etc.
Are there any mode to respond a customizable error code on ORDS on PUT request?
regards
Pedro

Yes, absolutely.
Simply add a parameter called X-ORDS-STATUS-CODE, and assign it to a :bind, that you have as an OUT RESPONSE HEADER, of type INTEGER.
Then in your POST or PUT handler code, assign the status code you want.
:status := 201;
So...
Here's the full module export -
-- Generated by Oracle SQL Developer REST Data Services 20.2.0.147.0319
-- Exported REST Definitions from ORDS Schema Version 20.2.0.r1611903
-- Schema: HR Date: Mon Jun 22 16:41:15 EDT 2020
--
BEGIN
ORDS.DEFINE_MODULE(
p_module_name => 'status',
p_base_path => '/status/',
p_items_per_page => 25,
p_status => 'PUBLISHED',
p_comments => NULL);
ORDS.DEFINE_TEMPLATE(
p_module_name => 'status',
p_pattern => '201',
p_priority => 0,
p_etag_type => 'HASH',
p_etag_query => NULL,
p_comments => NULL);
ORDS.DEFINE_HANDLER(
p_module_name => 'status',
p_pattern => '201',
p_method => 'POST',
p_source_type => 'plsql/block',
p_items_per_page => 0,
p_mimes_allowed => '',
p_comments => NULL,
p_source =>
'declare
new_record integer;
begin
insert into demo201 (column2) values (:words) returning column1 into new_record;
commit;
:status := 201;
end;'
);
ORDS.DEFINE_PARAMETER(
p_module_name => 'status',
p_pattern => '201',
p_method => 'POST',
p_name => 'X-ORDS-STATUS-CODE',
p_bind_variable_name => 'status',
p_source_type => 'HEADER',
p_param_type => 'INT',
p_access_method => 'OUT',
p_comments => NULL);
COMMIT;
END;
Here's a somewhat better example where I've caught my exception and set the HTTP Response Status code to '400'

Related

Oracle APEX ORDS Limitation on URL template?

Is there a limitation on the Oracle APEX ords template?
Currently mapping a GET Request to
Works : URI Template: /history/{PLATAFORM}/{CONTEXT}/{APPLICAT}/
Works : URI Template: /history/{PLATAFORM}/{CONTEXT}/{APPLICAT}/test/
405 Method Not Allowed: URI Template: /history/{PLATAFORM}/{CONTEXT}/{APPLICAT}/{test}/
Can't find documentation about this scenario, wonder if it's Oracle APEX limitation/Bug? Or Maybe some configuration somewhere?
Any help would be appreciated,
Regards.
No limitations other than please switch to using : syntax over {}. We changed that a while back.
-- Generated by Oracle SQL Developer REST Data Services 18.1.0.051.1417
-- Exported REST Definitions from ORDS Schema Version 17.4.0.18.13.50
-- Schema: KLRICE Date: Tue Apr 03 15:03:00 EDT 2018
--
BEGIN
ORDS.ENABLE_SCHEMA(
p_enabled => TRUE,
p_schema => 'KLRICE',
p_url_mapping_type => 'BASE_PATH',
p_url_mapping_pattern => 'klrice',
p_auto_rest_auth => FALSE);
ORDS.DEFINE_MODULE(
p_module_name => '/history/',
p_base_path => '/history/',
p_items_per_page => 25,
p_status => 'PUBLISHED',
p_comments => NULL);
ORDS.DEFINE_TEMPLATE(
p_module_name => '/history/',
p_pattern => ':PLATFORM/:CONTEXT/:APPLICAT/test',
p_priority => 0,
p_etag_type => 'HASH',
p_etag_query => NULL,
p_comments => NULL);
ORDS.DEFINE_HANDLER(
p_module_name => '/history/',
p_pattern => ':PLATFORM/:CONTEXT/:APPLICAT/test',
p_method => 'GET',
p_source_type => 'json/collection',
p_items_per_page => 25,
p_mimes_allowed => '',
p_comments => NULL,
p_source =>
'select :PLATFORM,:CONTEXT,:APPLICAT from dual'
);
COMMIT;
END;

Creating Salesorder with Vtiger Webservice missing Tax

I have the Problem when creating an salesorder with Vtiger Webservice,
The sales order is created but somehow the tax is not added.
I thought it has something to do with the parameter : hdnTaxType
Cause even if I add this value 'group' it does not apply the Tax to the Salesorder.
I have to manually add The Taxtype 'group' then the system adds the tax.
thats why i tried to add values like:
'tax1' => '7.00',
and
'group_tax' =>[
'group_tax_percentage1' => '7.0'
],
nothing so far did help...
has anybody an Idea what the problem is?
Thank you
Tobi
$salesOrder =[
'lastname' => $customer['lastname'],
'subject' => 'Order from 01.01.1018',
'sostatus' => '1',
'assigned_user_id' => '',
'bill_street' => 'Rechunngsstrasse 123',
'ship_street' =>'Lieferungsstrasse 123',
'productid' => '14x4325',
'currency_id' => '21x1',
'carrier' => 'DHL',
'txtAdjustment' => '13',
'salescommission' => '12',
'exciseduty' => '15',
'hdnTaxType' => 'group',
'tax1' => '7.00',
'hdnS_H_Amount' => '22.22',
'group_tax' =>[
'group_tax_percentage1' => '7.0'
],
'LineItems' => [
0 => [
"taxid" => "33x1",
'productid'=>'14x6',
'listprice'=>'20.53',
'quantity'=>'3',
'comment' => "Product123"
]
]
Webservices in Vtiger are not complete.
In this case you can register your own webservice that makes your queries, or check the SalesOrder in the after-save event

Passport Authedication Error in laravel 5.5

Error creating resource: [message] fopen(http://127.0.0.1:8000/oauth/token): failed to open stream: HTTP request failed! [file] /var/www/html/local/api-sample-application/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php [line] 324
I'm getting this error when try to implement laravel passport authentication.
This is my code in routes/web.php content:
Route::get('/redirect', function () {
$query = http_build_query([
'client_id' => '3',
'redirect_uri' => 'http://127.0.0.1:8000/oauth/callback',
'response_type' => 'code',
'scope' => '',
]);
return redirect('http://127.0.0.1:8000/oauth/authorize?' . $query);
});
Route::get('/oauth/callback', function () {
$http = new GuzzleHttp\Client;
if (request('code')) {
$response = $http->post('http://127.0.0.1:8000/oauth/token', [
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => '3',
'client_secret' => 'H1UQCKVRARwASEJLR4ugGjBHHvFy34SCzSJFqQLL',
'redirect_uri' => 'http://127.0.0.1:8000/oauth/callback',
'code' => request('code'),
],
]);
return json_decode((string)$response->getBody(), TRUE);
} else {
return response()->json(['error' => request('error')]);
}
});
When i hit this URL, i'm getting this error, not able to generate the token.
Error message screenshot
I had the same problem, and after 1 day I found the reason...
Since the PHP built-in server is single threaded, requesting another url on your server will halt first request and it gets timed out.
So you can't request localhost from localhost in same thread.
You can easy check it, try 'get' come public server host, 'http://www.example-host.com'..
Check this http://stackoverflow.com/a/25651196/916682

Query string in drupal service custom resources

I am trying to use query string structure in drupal services API. it's not working for me.
I have also search most of the solutions, but all failed.
here is m drupal code:
function rapid_services_resources() {
$resources = array(
'get_data' => array(
'operations' => array(
'retrieve' => array(
'help' => t('Gets user email of uid passed.'),
'callback' => 'my_module_get_user_email',
'args' => array(
array(
'name' => 'nid',
'type' => 'int',
'description' => 'The display ID of the view to get.',
'source' => array('param' => 'nid'),
'optional' => TRUE,
'default value' => 'default',
),
),
'access arguments' => '_blog_access_provide_access',
'access callback' => '_blog_access_provide_access',
//~ 'access arguments append' => FALSE,
),
),
),
);
return $resources;
}
function _blog_access_provide_access() {
return TRUE;
}
function my_module_get_user_email($nid){
var_dump($args);die;
}
I want url like this.:
http://localhost/drupaltest/rapidapi/get_data/?nid=111
Please let me know where i did wrong.
thanks in advance.
Hi here are to reference that will be useful
http://pingv.com/blog/an-introduction-drupal-7-restful-services
https://www.drupal.org/node/783460
Also I am not sure about the query string, but for the retrieve operation you can set it as part of the url
ex:
http://localhost/drupaltest/rapidapi/get_data/<nid should be here>
http://localhost/drupaltest/rapidapi/get_data/111
Also using the source path as source
'source' => array('path' => '0'),
I would think that source param only works for an index operation and not retrieve

Cakephp validating if my user checked at least one option

I have a problem validating if my user checked at least one option from a list of checkboxes.
Here is what i tried:
My view looks like this:
echo $this->Form->input('market_segment_targeted', array(
'multiple' => 'checkbox',
'label'=>array('text' => 'Market segment targeted', 'class'=>'w120'),
'options' => array(
'Home users' => 'Home users',
'SOHO' => 'SOHO',
'SMB' => 'SMB',
'Enterprise' => 'Enterprise'
),
));
In my controller i have added this snippet of code:
$validate_on_fly = array(
'market_segment_targeted' => array(
'notEmpty' => array(
'rule' => array('multiple', array('min' => 1)),
'required' => true,
'message' => 'Please select at least one!'
))
)));
$this->Partner->validate = Set::merge(
$this->Partner->validate,
$validate_on_fly
);
Any ideas what am i doing wrong?
Thank you
In CakePHP you can use Model Validation for checkboxes. Here is a quick example.
Your Form can look like:
$this->Form->create('User');
$this->Form->input('User.agree', array('type'=>'checkbox', 'hiddenField'=>false, 'value'=>'0'));
$this->Form->submit('Save'):
$this->Form->end();
Then in your Model under public $validate, use:
'agree'=>array(
'Not empty'=>array(
'rule'=>array('comparison', '!=', 0),
'required'=>true,
'message'=>'You must agree to the ToS'
)
)