How to create RESTful Service in Oracle Apex? - oracle-apex

I'm trying to create a RESTful service in Oracle Apex 20.2 as follows :
RESTful Service Module : api
Module Base Path : /api/
URI Template : {command}
Full URL : http://localhost:8080/ords/useralias/api/{command}
Method(Value Required) : POST
Source Type : PL/SQL
Source :
htp.p('Hi !');
The service is created. However when calling it via Curl using the command :
curl -X GET http://localhost:8080/ords/useralias/api/something
I'm getting the error :
{
"code": "UserDefinedResourceError",
"title": "User Defined Resource Error",
"message": "The request could not be processed due to an error in a user defined resource",
"o:errorCode": "ORDS-25001",
"cause": "An error occurred when evaluating the SQL statement associated with this resource. SQL Error Code 900, Error Message: ORA-00900: instruction SQL non valide\n",
"action": "Ask the user defined resource author to check the SQL statement is correctly formed and executes without error",
"type": "tag:oracle.com,2020:error/UserDefinedResourceError",
"instance": "tag:oracle.com,2020:ecid/3-WELoSC5oGNk1d3BuOh2A"
}
Using the exact same service with a "GET" handler and the same source (htp.p('Hi !');), the service works properly.
Does anyone know how to make it work please ?
Thanks.

The answer is stupidly simple :
the source should be :
begin
htp.p('hi !');
end;
instead of :
htp.p('hi !');

Related

Wso2 API Manager error - Error while building message. Error while building Passthrough stream, errorcode - 601000

I'm using API Manager to define to connection using oath 2.0. I have done all the configurations and connection is working. But some of the requests comes with the following error
{
"code": "601000",
"type": "Status report",
"message": "Runtime Error",
"description": "Error while building message. Error while building Passthrough stream"
}
and look likes the the response has content type application/fhir+json. I have seen some articles to add the content-type in the axis.xml file. Can someone please advise how I can add this content type in the wso2 api manager so that it recognize this content type.
You can add the following configurations to the repository/conf/deployment.toml.
[[custom_message_builders]]
content_type = "application/fhir+json"
class = "org.apache.synapse.commons.json.JsonStreamBuilder"
[[custom_message_formatters]]
content_type = "application/fhir+json"
class = "org.apache.synapse.commons.json.JsonStreamFormatter"

Upload REST API shows 400 bad request

I have an ESB webservice client which upload document to Alfresco using following RestAPI .
http://:8080/alfresco/service/api/upload
I understand , API to be called as multipart / form data , with file and mandatory fields . When i executed , i got the following error ersponse back .
{
"status": {
"code": 400,
"name": "Bad Request",
"description": "Request sent by the client was syntactically incorrect."
},
"message": "Required parameters are missing",
"exception": "",
"callstack": [],
"server": "Enterprise v5.2.3 (r852994b1-b12) schema 10,065",
"time": "10-Jul-2020 12:26:47"
}
I use WSO2 ESB client , ESB code looks all good . The only place where i can debug is through wirelog .
wirelog shows alll good( please scee screen shot below) . Error message has confilicting information like
"description": "Request sent by the client was syntactically incorrect."
"message": "Required parameters are missing",
Is there a log i can get from Alfresco server side to identify what actually is the issue , which syntax is incorrect ?
what parameter is missing ?
Screen shot for wire log as below
please click this link to see image of wiretap
You can use api-explorer rest api to upload document.
https://api-explorer.alfresco.com/api-explorer/#!/nodes/createNode
Which documentation are you following? By having a quick look here, I'd say you're not sending everything you should be:
https://docs.alfresco.com/5.0/references/RESTful-UploadUploadPost.html
This is the condition you're seeing getting triggered, so I'd look more closely in what you're actually sending. Maybe use Fiddler or some similar software to record your request and inspect it.
// Ensure mandatory file attributes have been located. Need either destination, or site + container or updateNodeRef
if ((filename === null || content === null) || (destination === null && (siteId === null || containerId === null) && updateNodeRef === null))
{
exitUpload(400, "Required parameters are missing");
return;
}
Also, the web script in question can be found here, it's implemented in JS so it would be relatively easy to add additional (temporary) logging.
...alfresco\tomcat\webapps\alfresco\WEB-INF\lib\alfresco-remote-api-5.0.d.jar\alfresco\templates\webscripts\org\alfresco\repository\upload\

Querying Couchbase Bucket from Postman - Unrecognized parameter in request

Using the Postman tool, I'm trying to query a Couchbase bucket. I'm getting an error response 1065 that there is an "unrecognized parameter in request". The query will work fine within the Couchbase workbench, but I need to be able to do this from Postman.
I'm making a POST request with this body:
{
"statement" : "SELECT * from `myBucketName` where id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee""
}
There error message is:
"msg": "Unrecognized parameter in request: {\n\"statement\" : \"SELECT from `myBuckeyName` where _id "
I think this is just an issue with how my request body is formatted, I'm just new to this and not sure how it should be formatted based off the error I'm getting.
Here's how I did it:
Open Postman
Select POST
Use a URL of http://localhost:8093/query/service
Under "Authorization", use Basic Auth (with the username/password you've created for Couchbase)
Under "Body", select "x-www-form-urlencoded"
Add a KEY of statement and a value of your query
Click SEND
I got a 200 OK response with the results of the query. Screenshot:
You should definitely check out the Couchbase REST API documentation. It uses curl instead of Postman, but that's a translation you'll eventually get used to.

Add Status using Facebook API

I am learning Rest web services using Postman extension of Chrome. I'm practicing it using Facebook API. I have a question about posting in FB.
URI used: https://graph.facebook.com/me/feed?
In the Body of the POST Method, I have given the following Json content
{
"message": "hello",
"access_token": "<a valid token>"
}
I am very sure that my access token is correct as when I append the access token and message with the above URI, the status gets posted successfully. Also when I use it as key-value pairs in 'x-wwww-form-urlencoded' section, it works fine.
But when I try to update the status using the Body of the POST method with the JSON content mentioned above, it tells
{ "error": { "message": "An active access token must be used to query information about the current user.", "type": "OAuthException", "code": 2500 } }
Is there any thing wrong in the format of the JSON content
I missed content-type=application/json
in the Header section.
Adding this solved the problem

Why WSO2 IS SAML2SSOAuthenticationService is returning false? (SAML2 SSO)

Scenario: I've deployed a Jaggery App at WSO2 AS 5.2.1 and I have WSO2 IS 5.0.0 (service pack activated) running two Service Providers with SSO config, one pointing to AS and the other to my Jaggery App.
My acs.jag is a copy o Dashboard application running at IS and configuration is similar too:
"saml_config" : {
"SAML.IdPUrl" : "samlsso",
"SAML.IssuerID" : "my.jag.app",
"SAML.LogoutUrl" : "logout",
"SAML.EnableResponseSigning" : "true",
"SAML.EnableAssertionSigning" : "true",
"SAML.EnableRequestSigning" : "true",
"SAML.SSOAgentCredentialImplClass" : "org.wso2.carbon.identity.sso.agent.saml.SSOAgentKeyStoreCredential",
"SAML.KeyStorePassword" : "wso2carbon",
"SAML.IdPCertAlias" : "wso2carbon",
"SAML.PrivateKeyAlias": "wso2carbon",
"SAML.PrivateKeyPassword" : "wso2carbon",
"SAML.KeyStore" : "{carbon.home}/repository/resources/security/wso2carbon.jks"
}
Problem: After IDP response, the payload is submited to SAML2SSOAuthenticationService and it always return false.
<ns:loginResponse xmlns:ns="http://sso.saml2.authenticator.identity.carbon.wso2.org">
<ns:return>false</ns:return>
</ns:loginResponse>
Am I doing something wrong?
[EDIT]
Thanks to #Asela I've noticed this at IS log:
Problem:
ERROR {org.wso2.carbon.identity.authenticator.saml2.sso.SAML2SSOAuthenticator}
Authentication Request is rejected. SAMLResponse AudienceRestriction validation failed.
In SAML2SSOAuthenticator class, the error is set by Assertion object equals null, but Assertion object isn't null before jaggery call SAML2SSOAuthenticationService.
I've found what's missing.
Changed the Claim in the Jaggery App Service Provider to /role && /emailaddress, and now it's working just fine.